On 8/19/2015 4:20 AM, Martin Basti wrote:
On 08/16/2015 05:29 PM, Endi Sukma Dewata wrote:
The vault-add and vault-archive commands have been modified to
optionally retrieve a secret from a source vault, then re-archive
the secret into the new/existing target vault.
https://fedorahosted.org/freeipa/ticket/5223
I cannot apply this patch.
Rebased. It depends on patch #371-2.
--
Endi S. Dewata
>From 20ee7fa94d28239b7b0512db53c6b899baf8a62f Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edew...@redhat.com>
Date: Sat, 15 Aug 2015 16:17:47 +0200
Subject: [PATCH] Added mechanism to copy vault secrets.
The vault-add and vault-archive commands have been modified to
optionally retrieve a secret from a source vault, then re-archive
the secret into the new/existing target vault.
https://fedorahosted.org/freeipa/ticket/5223
---
API.txt | 20 +++-
VERSION | 4 +-
ipalib/plugins/vault.py | 193 ++++++++++++++++++++----------
ipatests/test_xmlrpc/test_vault_plugin.py | 143 ++++++++++++++++++++++
4 files changed, 292 insertions(+), 68 deletions(-)
diff --git a/API.txt b/API.txt
index
749aa41d5cab60e4f2acf7486135ad066db7a8a6..3007bf31934d0b71dd104774ddbd1638cd12e8a3
100644
--- a/API.txt
+++ b/API.txt
@@ -5397,7 +5397,7 @@ output: Output('result', <type 'bool'>, None)
output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
output: PrimaryKey('value', None, None)
command: vault_add
-args: 1,14,3
+args: 1,22,3
arg: Str('cn', attribute=True, cli_name='name', maxlength=255,
multivalue=False, pattern='^[a-zA-Z0-9_.-]+$', primary_key=True, query=True,
required=True)
option: Str('addattr*', cli_name='addattr', exclude='webui')
option: Flag('all', autofill=True, cli_name='all', default=False,
exclude='webui')
@@ -5411,6 +5411,14 @@ option: Flag('raw', autofill=True, cli_name='raw',
default=False, exclude='webui
option: Str('service?')
option: Str('setattr*', cli_name='setattr', exclude='webui')
option: Flag('shared?', autofill=True, default=False)
+option: Str('source_password?')
+option: Str('source_password_file?')
+option: Bytes('source_private_key?')
+option: Str('source_private_key_file?')
+option: Str('source_service?')
+option: Flag('source_shared?', autofill=True, default=False)
+option: Str('source_user?')
+option: Str('source_vault?')
option: Str('username?', cli_name='user')
option: Str('version?', exclude='webui')
output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an
LDAP entry', domain='ipa', localedir=None))
@@ -5466,7 +5474,7 @@ output: Output('completed', <type 'int'>, None)
output: Output('failed', <type 'dict'>, None)
output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an
LDAP entry', domain='ipa', localedir=None))
command: vault_archive
-args: 1,11,3
+args: 1,19,3
arg: Str('cn', attribute=True, cli_name='name', maxlength=255,
multivalue=False, pattern='^[a-zA-Z0-9_.-]+$', primary_key=True, query=True,
required=True)
option: Flag('all', autofill=True, cli_name='all', default=False,
exclude='webui')
option: Bytes('data?')
@@ -5477,6 +5485,14 @@ option: Str('password_file?', cli_name='password_file')
option: Flag('raw', autofill=True, cli_name='raw', default=False,
exclude='webui')
option: Str('service?')
option: Flag('shared?', autofill=True, default=False)
+option: Str('source_password?')
+option: Str('source_password_file?')
+option: Bytes('source_private_key?')
+option: Str('source_private_key_file?')
+option: Str('source_service?')
+option: Flag('source_shared?', autofill=True, default=False)
+option: Str('source_user?')
+option: Str('source_vault?')
option: Str('username?', cli_name='user')
option: Str('version?', exclude='webui')
output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an
LDAP entry', domain='ipa', localedir=None))
diff --git a/VERSION b/VERSION
index
941b5356378582d4d620896acdf5c284a4f66b8d..19302efe7a36441b1ffef0d8db609f7be9a26c83
100644
--- a/VERSION
+++ b/VERSION
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
# #
########################################################
IPA_API_VERSION_MAJOR=2
-IPA_API_VERSION_MINOR=152
-# Last change: edewata - Added support for changing vault encryption.
+IPA_API_VERSION_MINOR=153
+# Last change: edewata - Added mechanism to copy vault secrets.
diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py
index
54dbf94b7de53a218df38550daa5e21450d2b9bd..47610fee56069a85296445d4eda3c640f835ebcf
100644
--- a/ipalib/plugins/vault.py
+++ b/ipalib/plugins/vault.py
@@ -254,6 +254,74 @@ vault_options = (
),
)
+source_vault_options = (
+ Str(
+ 'source_vault?',
+ doc=_('Name of the source service vault'),
+ ),
+ Str(
+ 'source_service?',
+ doc=_('Service name of the source service vault'),
+ ),
+ Flag(
+ 'source_shared?',
+ doc=_('Source shared vault'),
+ ),
+ Str(
+ 'source_user?',
+ doc=_('Username of the source user vault'),
+ ),
+ Str(
+ 'source_password?',
+ doc=_('Source vault password'),
+ ),
+ Str( # TODO: use File parameter
+ 'source_password_file?',
+ doc=_('File containing the source vault password'),
+ ),
+ Bytes(
+ 'source_private_key?',
+ doc=_('Source vault private key'),
+ ),
+ Str( # TODO: use File parameter
+ 'source_private_key_file?',
+ doc=_('File containing the source vault private key'),
+ ),
+)
+
+vault_add_options = (
+ Str(
+ 'description?',
+ cli_name='desc',
+ doc=_('Vault description'),
+ ),
+ Str(
+ 'ipavaulttype?',
+ cli_name='type',
+ doc=_('Vault type'),
+ ),
+ Str(
+ 'password?',
+ cli_name='password',
+ doc=_('Vault password'),
+ ),
+ Str( # TODO: use File parameter
+ 'password_file?',
+ cli_name='password_file',
+ doc=_('File containing the vault password'),
+ ),
+ Bytes(
+ 'ipavaultpublickey?',
+ cli_name='public_key',
+ doc=_('Vault public key'),
+ ),
+ Str( # TODO: use File parameter
+ 'public_key_file?',
+ cli_name='public_key_file',
+ doc=_('File containing the vault public key'),
+ ),
+)
+
@register()
class vault(LDAPObject):
@@ -572,56 +640,27 @@ class vault(LDAPObject):
class vault_add(PKQuery, Local):
__doc__ = _('Create a new vault.')
- takes_options = LDAPCreate.takes_options + vault_options + (
- Str(
- 'description?',
- cli_name='desc',
- doc=_('Vault description'),
- ),
- Str(
- 'ipavaulttype?',
- cli_name='type',
- doc=_('Vault type'),
- ),
- Str(
- 'password?',
- cli_name='password',
- doc=_('Vault password'),
- ),
- Str( # TODO: use File parameter
- 'password_file?',
- cli_name='password_file',
- doc=_('File containing the vault password'),
- ),
- Bytes(
- 'ipavaultpublickey?',
- cli_name='public_key',
- doc=_('Vault public key'),
- ),
- Str( # TODO: use File parameter
- 'public_key_file?',
- cli_name='public_key_file',
- doc=_('File containing the vault public key'),
- ),
- )
+ takes_options = LDAPCreate.takes_options + vault_options + \
+ source_vault_options + vault_add_options
has_output = output.standard_entry
def forward(self, *args, **options):
vault_type = options.get('ipavaulttype', u'standard')
- password = options.get('password')
- password_file = options.get('password_file')
+ password = options.pop('password', None)
+ password_file = options.pop('password_file', None)
public_key = options.get('ipavaultpublickey')
- public_key_file = options.get('public_key_file')
+ public_key_file = options.pop('public_key_file', None)
- # don't send these parameters to server
- if 'password' in options:
- del options['password']
- if 'password_file' in options:
- del options['password_file']
- if 'public_key_file' in options:
- del options['public_key_file']
+ source_vault = options.pop('source_vault', None)
+ source_service = options.pop('source_service', None)
+ source_shared = options.pop('source_shared', None)
+ source_user = options.pop('source_user', None)
+ source_password = options.pop('source_password', None)
+ source_password_file = options.pop('source_password_file', None)
+ source_private_key = options.pop('source_private_key', None)
+ source_private_key_file = options.pop('source_private_key_file', None)
if vault_type != u'symmetric' and (password or password_file):
raise errors.MutuallyExclusiveError(
@@ -711,6 +750,7 @@ class vault_add(PKQuery, Local):
opts = options.copy()
if 'description' in opts:
del opts['description']
+
if 'ipavaulttype' in opts:
del opts['ipavaulttype']
@@ -721,7 +761,17 @@ class vault_add(PKQuery, Local):
elif vault_type == u'asymmetric':
del opts['ipavaultpublickey']
- # archive blank data
+ opts['source_vault'] = source_vault
+ opts['source_service'] = source_service
+ opts['source_shared'] = source_shared
+ opts['source_user'] = source_user
+
+ opts['source_password'] = source_password
+ opts['source_password_file'] = source_password_file
+ opts['source_private_key'] = source_private_key
+ opts['source_private_key_file'] = source_private_key_file
+
+ # archive initial data
self.api.Command.vault_archive(*args, **opts)
return response
@@ -1174,7 +1224,7 @@ class vaultconfig_show(Retrieve):
class vault_archive(PKQuery, Local):
__doc__ = _('Archive data into a vault.')
- takes_options = vault_options + (
+ takes_options = vault_options + source_vault_options + (
Bytes(
'data?',
doc=_('Binary data to archive'),
@@ -1205,23 +1255,29 @@ class vault_archive(PKQuery, Local):
name = args[-1]
- data = options.get('data')
- input_file = options.get('in')
+ data = options.pop('data', None)
+ input_file = options.pop('in', None)
- password = options.get('password')
- password_file = options.get('password_file')
+ source_vault = options.pop('source_vault', None)
+ source_service = options.pop('source_service', None)
+ source_shared = options.pop('source_shared', None)
+ source_user = options.pop('source_user', None)
+ source_password = options.pop('source_password', None)
+ source_password_file = options.pop('source_password_file', None)
+ source_private_key = options.pop('source_private_key', None)
+ source_private_key_file = options.pop('source_private_key_file', None)
+
+ password = options.pop('password', None)
+ password_file = options.pop('password_file', None)
override_password = options.pop('override_password', False)
- # don't send these parameters to server
- if 'data' in options:
- del options['data']
- if 'in' in options:
- del options['in']
- if 'password' in options:
- del options['password']
- if 'password_file' in options:
- del options['password_file']
+ if self.api.env.in_server:
+ backend = self.api.Backend.ldap2
+ else:
+ backend = self.api.Backend.rpcclient
+ if not backend.isconnected():
+ backend.connect(ccache=krbV.default_context().default_ccache())
# get data
if data and input_file:
@@ -1231,16 +1287,25 @@ class vault_archive(PKQuery, Local):
elif input_file:
data = validated_read('in', input_file, mode='rb')
+ elif source_vault:
+ opts = {}
+
+ opts['service'] = source_service
+ opts['shared'] = source_shared
+ opts['username'] = source_user
+
+ opts['password'] = source_password
+ opts['password_file'] = source_password_file
+ opts['private_key'] = source_private_key
+ opts['private_key_file'] = source_private_key_file
+
+ # retrieve data from source vault
+ response = self.api.Command.vault_retrieve(source_vault, **opts)
+ data = response['result']['data']
+
elif not data:
data = ''
- if self.api.env.in_server:
- backend = self.api.Backend.ldap2
- else:
- backend = self.api.Backend.rpcclient
- if not backend.isconnected():
- backend.connect(ccache=krbV.default_context().default_ccache())
-
# retrieve vault info
vault = self.api.Command.vault_show(*args, **options)['result']
diff --git a/ipatests/test_xmlrpc/test_vault_plugin.py
b/ipatests/test_xmlrpc/test_vault_plugin.py
index
483a47410c0d49b6a1e8b54047c280c243301d1b..fe0cc6d1e050de2dfb08e064250f5343dbea9c73
100644
--- a/ipatests/test_xmlrpc/test_vault_plugin.py
+++ b/ipatests/test_xmlrpc/test_vault_plugin.py
@@ -33,6 +33,10 @@ standard_vault_name = u'standard_test_vault'
symmetric_vault_name = u'symmetric_test_vault'
asymmetric_vault_name = u'asymmetric_test_vault'
+standard_vault_copy_name = u'standard_test_vault_copy'
+symmetric_vault_copy_name = u'symmetric_test_vault_copy'
+asymmetric_vault_copy_name = u'asymmetric_test_vault_copy'
+
# binary data from \x00 to \xff
secret = ''.join(map(chr, xrange(0, 256)))
@@ -147,6 +151,9 @@ class test_vault_plugin(Declarative):
('vault_del', [standard_vault_name], {'continue': True}),
('vault_del', [symmetric_vault_name], {'continue': True}),
('vault_del', [asymmetric_vault_name], {'continue': True}),
+ ('vault_del', [standard_vault_copy_name], {'continue': True}),
+ ('vault_del', [symmetric_vault_copy_name], {'continue': True}),
+ ('vault_del', [asymmetric_vault_copy_name], {'continue': True}),
]
tests = [
@@ -634,6 +641,52 @@ class test_vault_plugin(Declarative):
},
{
+ 'desc': 'Copy standard vault to symmetric vault',
+ 'command': (
+ 'vault_add',
+ [standard_vault_copy_name],
+ {
+ 'ipavaulttype': u'symmetric',
+ 'password': password,
+ 'source_vault': standard_vault_name,
+ },
+ ),
+ 'expected': {
+ 'value': standard_vault_copy_name,
+ 'summary': u'Added vault "%s"' % standard_vault_copy_name,
+ 'result': {
+ 'dn': u'cn=%s,cn=admin,cn=users,cn=vaults,cn=kra,%s'
+ % (standard_vault_copy_name, api.env.basedn),
+ 'objectclass': [u'top', u'ipaVault'],
+ 'cn': [standard_vault_copy_name],
+ 'ipavaulttype': [u'symmetric'],
+ 'ipavaultsalt': [fuzzy_string],
+ 'owner_user': [u'admin'],
+ },
+ },
+ },
+
+ {
+ 'desc': 'Retrieve secret from standard vault copied to '
+ 'symmetric vault',
+ 'command': (
+ 'vault_retrieve',
+ [standard_vault_copy_name],
+ {
+ 'password': password,
+ },
+ ),
+ 'expected': {
+ 'value': standard_vault_copy_name,
+ 'summary': 'Retrieved data from vault "%s"'
+ % standard_vault_copy_name,
+ 'result': {
+ 'data': secret,
+ },
+ },
+ },
+
+ {
'desc': 'Change standard vault to symmetric vault',
'command': (
'vault_mod',
@@ -738,6 +791,53 @@ class test_vault_plugin(Declarative):
},
{
+ 'desc': 'Copy symmetric vault to asymmetric vault',
+ 'command': (
+ 'vault_add',
+ [symmetric_vault_copy_name],
+ {
+ 'ipavaulttype': u'asymmetric',
+ 'ipavaultpublickey': public_key,
+ 'source_vault': symmetric_vault_name,
+ 'source_password': password,
+ },
+ ),
+ 'expected': {
+ 'value': symmetric_vault_copy_name,
+ 'summary': u'Added vault "%s"' % symmetric_vault_copy_name,
+ 'result': {
+ 'dn': u'cn=%s,cn=admin,cn=users,cn=vaults,cn=kra,%s'
+ % (symmetric_vault_copy_name, api.env.basedn),
+ 'objectclass': [u'top', u'ipaVault'],
+ 'cn': [symmetric_vault_copy_name],
+ 'ipavaulttype': [u'asymmetric'],
+ 'ipavaultpublickey': [public_key],
+ 'owner_user': [u'admin'],
+ },
+ },
+ },
+
+ {
+ 'desc': 'Retrieve secret from symmetric vault copied to '
+ 'asymmetric vault',
+ 'command': (
+ 'vault_retrieve',
+ [symmetric_vault_copy_name],
+ {
+ 'private_key': private_key,
+ },
+ ),
+ 'expected': {
+ 'value': symmetric_vault_copy_name,
+ 'summary': 'Retrieved data from vault "%s"'
+ % symmetric_vault_copy_name,
+ 'result': {
+ 'data': secret,
+ },
+ },
+ },
+
+ {
'desc': 'Change symmetric vault password',
'command': (
'vault_mod',
@@ -883,6 +983,49 @@ class test_vault_plugin(Declarative):
},
{
+ 'desc': 'Copy asymmetric vault to standard vault',
+ 'command': (
+ 'vault_add',
+ [asymmetric_vault_copy_name],
+ {
+ 'ipavaulttype': u'standard',
+ 'source_vault': asymmetric_vault_name,
+ 'source_private_key': private_key,
+ },
+ ),
+ 'expected': {
+ 'value': asymmetric_vault_copy_name,
+ 'summary': u'Added vault "%s"' % asymmetric_vault_copy_name,
+ 'result': {
+ 'dn': u'cn=%s,cn=admin,cn=users,cn=vaults,cn=kra,%s'
+ % (asymmetric_vault_copy_name, api.env.basedn),
+ 'objectclass': [u'top', u'ipaVault'],
+ 'cn': [asymmetric_vault_copy_name],
+ 'ipavaulttype': [u'standard'],
+ 'owner_user': [u'admin'],
+ },
+ },
+ },
+
+ {
+ 'desc': 'Retrieve secret from asymmetric vault copied to '
+ 'standard vault',
+ 'command': (
+ 'vault_retrieve',
+ [asymmetric_vault_copy_name],
+ {},
+ ),
+ 'expected': {
+ 'value': asymmetric_vault_copy_name,
+ 'summary': 'Retrieved data from vault "%s"'
+ % asymmetric_vault_copy_name,
+ 'result': {
+ 'data': secret,
+ },
+ },
+ },
+
+ {
'desc': 'Change asymmetric vault keys',
'command': (
'vault_mod',
--
2.4.3
--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code