2014-10-21 09:57:08 -05:00
|
|
|
# Authors:
|
|
|
|
# Endi S. Dewata <edewata@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
import six
|
|
|
|
|
2016-04-28 02:46:03 -05:00
|
|
|
from ipalib.frontend import Command, Object
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipalib import api, errors
|
2015-08-18 05:50:54 -05:00
|
|
|
from ipalib import Bytes, Flag, Str, StrEnum
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipalib import output
|
2015-12-16 09:06:03 -06:00
|
|
|
from ipalib.crud import PKQuery, Retrieve
|
2016-06-23 11:54:49 -05:00
|
|
|
from ipalib.parameters import Principal
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipalib.plugable import Registry
|
2016-04-20 08:41:34 -05:00
|
|
|
from .baseldap import LDAPObject, LDAPCreate, LDAPDelete,\
|
2014-10-17 11:05:34 -05:00
|
|
|
LDAPSearch, LDAPUpdate, LDAPRetrieve, LDAPAddMember, LDAPRemoveMember,\
|
2015-08-11 01:19:59 -05:00
|
|
|
LDAPModMember, pkey_to_value
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipalib.request import context
|
2016-06-23 11:54:49 -05:00
|
|
|
from .service import normalize_principal, validate_realm
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipalib import _, ngettext
|
2016-06-23 11:54:49 -05:00
|
|
|
from ipapython import kerberos
|
2014-10-21 09:57:08 -05:00
|
|
|
from ipapython.dn import DN
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
if api.env.in_server:
|
|
|
|
import pki.account
|
|
|
|
import pki.key
|
2017-04-26 11:15:40 -05:00
|
|
|
# pylint: disable=no-member
|
|
|
|
try:
|
|
|
|
# pki >= 10.4.0
|
|
|
|
from pki.crypto import DES_EDE3_CBC_OID
|
|
|
|
except ImportError:
|
|
|
|
DES_EDE3_CBC_OID = pki.key.KeyClient.DES_EDE3_CBC_OID
|
|
|
|
# pylint: enable=no-member
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
__doc__ = _("""
|
|
|
|
Vaults
|
|
|
|
""") + _("""
|
|
|
|
Manage vaults.
|
|
|
|
""") + _("""
|
2018-05-20 00:13:00 -05:00
|
|
|
Vault is a secure place to store a secret. One vault can only
|
|
|
|
store one secret. When archiving a secret in a vault, the
|
|
|
|
existing secret (if any) is overwritten.
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Based on the ownership there are three vault categories:
|
|
|
|
* user/private vault
|
|
|
|
* service vault
|
|
|
|
* shared vault
|
|
|
|
""") + _("""
|
|
|
|
User vaults are vaults owned used by a particular user. Private
|
|
|
|
vaults are vaults owned the current user. Service vaults are
|
|
|
|
vaults owned by a service. Shared vaults are owned by the admin
|
|
|
|
but they can be used by other users or services.
|
|
|
|
""") + _("""
|
|
|
|
Based on the security mechanism there are three types of
|
|
|
|
vaults:
|
|
|
|
* standard vault
|
|
|
|
* symmetric vault
|
|
|
|
* asymmetric vault
|
|
|
|
""") + _("""
|
|
|
|
Standard vault uses a secure mechanism to transport and
|
|
|
|
store the secret. The secret can only be retrieved by users
|
|
|
|
that have access to the vault.
|
|
|
|
""") + _("""
|
|
|
|
Symmetric vault is similar to the standard vault, but it
|
|
|
|
pre-encrypts the secret using a password before transport.
|
|
|
|
The secret can only be retrieved using the same password.
|
|
|
|
""") + _("""
|
|
|
|
Asymmetric vault is similar to the standard vault, but it
|
|
|
|
pre-encrypts the secret using a public key before transport.
|
|
|
|
The secret can only be retrieved using the private key.
|
|
|
|
""") + _("""
|
2014-10-21 09:57:08 -05:00
|
|
|
EXAMPLES:
|
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
List vaults:
|
2014-10-21 09:57:08 -05:00
|
|
|
ipa vault-find
|
2015-08-11 01:19:59 -05:00
|
|
|
[--user <user>|--service <service>|--shared]
|
2014-10-21 09:57:08 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Add a standard vault:
|
2014-10-21 09:57:08 -05:00
|
|
|
ipa vault-add <name>
|
2015-08-11 01:19:59 -05:00
|
|
|
[--user <user>|--service <service>|--shared]
|
2015-08-25 11:25:50 -05:00
|
|
|
--type standard
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Add a symmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-add <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--type symmetric --password-file password.txt
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Add an asymmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-add <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--type asymmetric --public-key-file public.pem
|
2014-10-21 09:57:08 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Show a vault:
|
2014-10-21 09:57:08 -05:00
|
|
|
ipa vault-show <name>
|
2015-08-11 01:19:59 -05:00
|
|
|
[--user <user>|--service <service>|--shared]
|
2014-10-21 09:57:08 -05:00
|
|
|
""") + _("""
|
2015-07-31 00:53:15 -05:00
|
|
|
Modify vault description:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--desc <description>
|
2015-07-31 00:53:15 -05:00
|
|
|
""") + _("""
|
|
|
|
Modify vault type:
|
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--type <type>
|
|
|
|
[old password/private key]
|
|
|
|
[new password/public key]
|
|
|
|
""") + _("""
|
|
|
|
Modify symmetric vault password:
|
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--change-password
|
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--old-password <old password>
|
|
|
|
--new-password <new password>
|
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--old-password-file <old password file>
|
|
|
|
--new-password-file <new password file>
|
|
|
|
""") + _("""
|
|
|
|
Modify asymmetric vault keys:
|
|
|
|
ipa vault-mod <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--private-key-file <old private key file>
|
|
|
|
--public-key-file <new public key file>
|
2014-10-21 09:57:08 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Delete a vault:
|
2014-10-21 09:57:08 -05:00
|
|
|
ipa vault-del <name>
|
2015-08-11 01:19:59 -05:00
|
|
|
[--user <user>|--service <service>|--shared]
|
2015-06-05 03:49:39 -05:00
|
|
|
""") + _("""
|
|
|
|
Display vault configuration:
|
2014-10-24 18:53:16 -05:00
|
|
|
ipa vaultconfig-show
|
2015-06-05 03:49:39 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Archive data into standard vault:
|
|
|
|
ipa vault-archive <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--in <input file>
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Archive data into symmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-archive <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--in <input file>
|
|
|
|
--password-file password.txt
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Archive data into asymmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-archive <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--in <input file>
|
2015-06-05 03:49:39 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Retrieve data from standard vault:
|
|
|
|
ipa vault-retrieve <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--out <output file>
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Retrieve data from symmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-retrieve <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--out <output file>
|
|
|
|
--password-file password.txt
|
2014-10-24 18:53:16 -05:00
|
|
|
""") + _("""
|
|
|
|
Retrieve data from asymmetric vault:
|
2015-08-11 01:19:59 -05:00
|
|
|
ipa vault-retrieve <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
--out <output file> --private-key-file private.pem
|
2014-10-17 11:05:34 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Add vault owners:
|
|
|
|
ipa vault-add-owner <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
[--users <users>] [--groups <groups>] [--services <services>]
|
2014-10-17 11:05:34 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Delete vault owners:
|
|
|
|
ipa vault-remove-owner <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
[--users <users>] [--groups <groups>] [--services <services>]
|
2014-10-17 11:05:34 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Add vault members:
|
|
|
|
ipa vault-add-member <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
[--users <users>] [--groups <groups>] [--services <services>]
|
2014-10-17 11:05:34 -05:00
|
|
|
""") + _("""
|
2015-08-11 01:19:59 -05:00
|
|
|
Delete vault members:
|
|
|
|
ipa vault-remove-member <name>
|
|
|
|
[--user <user>|--service <service>|--shared]
|
|
|
|
[--users <users>] [--groups <groups>] [--services <services>]
|
2014-10-21 09:57:08 -05:00
|
|
|
""")
|
|
|
|
|
2015-07-30 08:48:40 -05:00
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
register = Registry()
|
|
|
|
|
|
|
|
vault_options = (
|
2016-06-23 11:54:49 -05:00
|
|
|
Principal(
|
2014-10-21 09:57:08 -05:00
|
|
|
'service?',
|
2016-06-23 11:54:49 -05:00
|
|
|
validate_realm,
|
2014-10-24 18:53:16 -05:00
|
|
|
doc=_('Service name of the service vault'),
|
2015-08-18 05:14:36 -05:00
|
|
|
normalizer=normalize_principal,
|
2014-10-21 09:57:08 -05:00
|
|
|
),
|
|
|
|
Flag(
|
|
|
|
'shared?',
|
|
|
|
doc=_('Shared vault'),
|
|
|
|
),
|
|
|
|
Str(
|
2014-10-17 11:05:34 -05:00
|
|
|
'username?',
|
|
|
|
cli_name='user',
|
2014-10-24 18:53:16 -05:00
|
|
|
doc=_('Username of the user vault'),
|
2014-10-21 09:57:08 -05:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-08-25 12:56:00 -05:00
|
|
|
class VaultModMember(LDAPModMember):
|
|
|
|
def get_options(self):
|
|
|
|
for param in super(VaultModMember, self).get_options():
|
|
|
|
if param.name == 'service' and param not in vault_options:
|
|
|
|
param = param.clone_rename('services')
|
|
|
|
yield param
|
|
|
|
|
|
|
|
def get_member_dns(self, **options):
|
|
|
|
if 'services' in options:
|
|
|
|
options['service'] = options.pop('services')
|
|
|
|
else:
|
|
|
|
options.pop('service', None)
|
|
|
|
return super(VaultModMember, self).get_member_dns(**options)
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
2018-01-24 10:44:39 -06:00
|
|
|
for fail in failed.values():
|
2015-08-25 12:56:00 -05:00
|
|
|
fail['services'] = fail.pop('service', [])
|
|
|
|
self.obj.get_container_attribute(entry_attrs, options)
|
|
|
|
return completed, dn
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultcontainer(LDAPObject):
|
|
|
|
__doc__ = _("""
|
|
|
|
Vault Container object.
|
|
|
|
""")
|
|
|
|
|
|
|
|
container_dn = api.env.container_vault
|
|
|
|
|
|
|
|
object_name = _('vaultcontainer')
|
|
|
|
object_name_plural = _('vaultcontainers')
|
|
|
|
object_class = ['ipaVaultContainer']
|
2015-09-03 02:32:11 -05:00
|
|
|
permission_filter_objectclasses = ['ipaVaultContainer']
|
2015-08-25 12:56:00 -05:00
|
|
|
|
|
|
|
attribute_members = {
|
|
|
|
'owner': ['user', 'group', 'service'],
|
|
|
|
}
|
|
|
|
|
|
|
|
label = _('Vault Containers')
|
|
|
|
label_singular = _('Vault Container')
|
|
|
|
|
2015-09-03 02:32:11 -05:00
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Vault Containers': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'cn', 'description', 'owner',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Add Vault Containers': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'add'},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Delete Vault Containers': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'delete'},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Modify Vault Containers': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'cn', 'description',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Manage Vault Container Ownership': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'owner',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-08-25 12:56:00 -05:00
|
|
|
takes_params = (
|
|
|
|
Str(
|
|
|
|
'owner_user?',
|
|
|
|
label=_('Owner users'),
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'owner_group?',
|
|
|
|
label=_('Owner groups'),
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'owner_service?',
|
|
|
|
label=_('Owner services'),
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'owner?',
|
|
|
|
label=_('Failed owners'),
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'service?',
|
|
|
|
label=_('Vault service'),
|
|
|
|
flags={'virtual_attribute'},
|
|
|
|
),
|
|
|
|
Flag(
|
|
|
|
'shared?',
|
|
|
|
label=_('Shared vault'),
|
|
|
|
flags={'virtual_attribute'},
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'username?',
|
|
|
|
label=_('Vault user'),
|
|
|
|
flags={'virtual_attribute'},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_dn(self, *keys, **options):
|
|
|
|
"""
|
|
|
|
Generates vault DN from parameters.
|
|
|
|
"""
|
|
|
|
service = options.get('service')
|
|
|
|
shared = options.get('shared')
|
|
|
|
user = options.get('username')
|
|
|
|
|
|
|
|
count = (bool(service) + bool(shared) + bool(user))
|
|
|
|
if count > 1:
|
|
|
|
raise errors.MutuallyExclusiveError(
|
|
|
|
reason=_('Service, shared and user options ' +
|
|
|
|
'cannot be specified simultaneously'))
|
|
|
|
|
|
|
|
parent_dn = super(vaultcontainer, self).get_dn(*keys, **options)
|
|
|
|
|
|
|
|
if not count:
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = kerberos.Principal(getattr(context, 'principal'))
|
2015-08-25 12:56:00 -05:00
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
if principal.is_host:
|
2015-08-25 12:56:00 -05:00
|
|
|
raise errors.NotImplementedError(
|
|
|
|
reason=_('Host is not supported'))
|
2016-06-23 11:54:49 -05:00
|
|
|
elif principal.is_service:
|
|
|
|
service = unicode(principal)
|
2015-08-25 12:56:00 -05:00
|
|
|
else:
|
2016-06-23 11:54:49 -05:00
|
|
|
user = principal.username
|
2015-08-25 12:56:00 -05:00
|
|
|
|
|
|
|
if service:
|
|
|
|
dn = DN(('cn', service), ('cn', 'services'), parent_dn)
|
|
|
|
elif shared:
|
|
|
|
dn = DN(('cn', 'shared'), parent_dn)
|
|
|
|
elif user:
|
|
|
|
dn = DN(('cn', user), ('cn', 'users'), parent_dn)
|
|
|
|
else:
|
|
|
|
raise RuntimeError
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def get_container_attribute(self, entry, options):
|
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
container_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
if entry.dn.endswith(DN(('cn', 'services'), container_dn)):
|
|
|
|
entry['service'] = entry.dn[0]['cn']
|
|
|
|
elif entry.dn.endswith(DN(('cn', 'shared'), container_dn)):
|
|
|
|
entry['shared'] = True
|
|
|
|
elif entry.dn.endswith(DN(('cn', 'users'), container_dn)):
|
|
|
|
entry['username'] = entry.dn[0]['cn']
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultcontainer_show(LDAPRetrieve):
|
|
|
|
__doc__ = _('Display information about a vault container.')
|
|
|
|
|
|
|
|
takes_options = LDAPRetrieve.takes_options + vault_options
|
|
|
|
|
|
|
|
has_output_params = LDAPRetrieve.has_output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
self.obj.get_container_attribute(entry_attrs, options)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultcontainer_del(LDAPDelete):
|
|
|
|
__doc__ = _('Delete a vault container.')
|
|
|
|
|
|
|
|
takes_options = LDAPDelete.takes_options + vault_options
|
|
|
|
|
|
|
|
msg_summary = _('Deleted vault container')
|
|
|
|
|
|
|
|
subtree_delete = False
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def execute(self, *keys, **options):
|
|
|
|
keys = keys + (u'',)
|
|
|
|
return super(vaultcontainer_del, self).execute(*keys, **options)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultcontainer_add_owner(VaultModMember, LDAPAddMember):
|
|
|
|
__doc__ = _('Add owners to a vault container.')
|
|
|
|
|
|
|
|
takes_options = LDAPAddMember.takes_options + vault_options
|
|
|
|
|
|
|
|
member_attributes = ['owner']
|
|
|
|
member_param_label = _('owner %s')
|
|
|
|
member_count_out = ('%i owner added.', '%i owners added.')
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
output.Entry('result'),
|
|
|
|
output.Output(
|
|
|
|
'failed',
|
|
|
|
type=dict,
|
|
|
|
doc=_('Owners that could not be added'),
|
|
|
|
),
|
|
|
|
output.Output(
|
|
|
|
'completed',
|
|
|
|
type=int,
|
|
|
|
doc=_('Number of owners added'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultcontainer_remove_owner(VaultModMember, LDAPRemoveMember):
|
|
|
|
__doc__ = _('Remove owners from a vault container.')
|
|
|
|
|
|
|
|
takes_options = LDAPRemoveMember.takes_options + vault_options
|
|
|
|
|
|
|
|
member_attributes = ['owner']
|
|
|
|
member_param_label = _('owner %s')
|
|
|
|
member_count_out = ('%i owner removed.', '%i owners removed.')
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
output.Entry('result'),
|
|
|
|
output.Output(
|
|
|
|
'failed',
|
|
|
|
type=dict,
|
|
|
|
doc=_('Owners that could not be removed'),
|
|
|
|
),
|
|
|
|
output.Output(
|
|
|
|
'completed',
|
|
|
|
type=int,
|
|
|
|
doc=_('Number of owners removed'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
@register()
|
|
|
|
class vault(LDAPObject):
|
|
|
|
__doc__ = _("""
|
|
|
|
Vault object.
|
|
|
|
""")
|
|
|
|
|
|
|
|
container_dn = api.env.container_vault
|
|
|
|
|
|
|
|
object_name = _('vault')
|
|
|
|
object_name_plural = _('vaults')
|
|
|
|
|
|
|
|
object_class = ['ipaVault']
|
2015-09-03 02:32:11 -05:00
|
|
|
permission_filter_objectclasses = ['ipaVault']
|
2014-10-21 09:57:08 -05:00
|
|
|
default_attributes = [
|
|
|
|
'cn',
|
|
|
|
'description',
|
2014-10-24 18:53:16 -05:00
|
|
|
'ipavaulttype',
|
|
|
|
'ipavaultsalt',
|
2015-07-02 14:27:16 -05:00
|
|
|
'ipavaultpublickey',
|
2014-10-17 11:05:34 -05:00
|
|
|
'owner',
|
|
|
|
'member',
|
2014-10-24 18:53:16 -05:00
|
|
|
]
|
|
|
|
search_display_attributes = [
|
|
|
|
'cn',
|
|
|
|
'description',
|
|
|
|
'ipavaulttype',
|
2014-10-21 09:57:08 -05:00
|
|
|
]
|
2014-10-17 11:05:34 -05:00
|
|
|
attribute_members = {
|
2015-08-11 01:19:59 -05:00
|
|
|
'owner': ['user', 'group', 'service'],
|
|
|
|
'member': ['user', 'group', 'service'],
|
2014-10-17 11:05:34 -05:00
|
|
|
}
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
label = _('Vaults')
|
|
|
|
label_singular = _('Vault')
|
|
|
|
|
2015-09-03 02:32:11 -05:00
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Vaults': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'cn', 'description', 'ipavaulttype',
|
|
|
|
'ipavaultsalt', 'ipavaultpublickey', 'owner', 'member',
|
|
|
|
'memberuser', 'memberhost',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Add Vaults': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'add'},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Delete Vaults': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'delete'},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Modify Vaults': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'cn', 'description', 'ipavaulttype',
|
|
|
|
'ipavaultsalt', 'ipavaultpublickey',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Manage Vault Ownership': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'owner',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
'System: Manage Vault Membership': {
|
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN(api.env.container_vault, api.env.basedn),
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'member',
|
|
|
|
},
|
|
|
|
'default_privileges': {'Vault Administrators'},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
takes_params = (
|
|
|
|
Str(
|
|
|
|
'cn',
|
|
|
|
cli_name='name',
|
|
|
|
label=_('Vault name'),
|
|
|
|
primary_key=True,
|
|
|
|
pattern='^[a-zA-Z0-9_.-]+$',
|
|
|
|
pattern_errmsg='may only include letters, numbers, _, ., and -',
|
|
|
|
maxlength=255,
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'description?',
|
|
|
|
cli_name='desc',
|
|
|
|
label=_('Description'),
|
|
|
|
doc=_('Vault description'),
|
|
|
|
),
|
2015-08-18 05:50:54 -05:00
|
|
|
StrEnum(
|
2014-10-24 18:53:16 -05:00
|
|
|
'ipavaulttype?',
|
|
|
|
cli_name='type',
|
|
|
|
label=_('Type'),
|
|
|
|
doc=_('Vault type'),
|
2015-08-18 05:50:54 -05:00
|
|
|
values=(u'standard', u'symmetric', u'asymmetric', ),
|
2015-08-25 11:25:50 -05:00
|
|
|
default=u'symmetric',
|
2014-10-24 18:53:16 -05:00
|
|
|
autofill=True,
|
|
|
|
),
|
|
|
|
Bytes(
|
|
|
|
'ipavaultsalt?',
|
|
|
|
cli_name='salt',
|
|
|
|
label=_('Salt'),
|
|
|
|
doc=_('Vault salt'),
|
|
|
|
flags=['no_search'],
|
|
|
|
),
|
|
|
|
Bytes(
|
2015-07-02 14:27:16 -05:00
|
|
|
'ipavaultpublickey?',
|
2014-10-24 18:53:16 -05:00
|
|
|
cli_name='public_key',
|
|
|
|
label=_('Public key'),
|
|
|
|
doc=_('Vault public key'),
|
|
|
|
flags=['no_search'],
|
|
|
|
),
|
2014-10-17 11:05:34 -05:00
|
|
|
Str(
|
|
|
|
'owner_user?',
|
|
|
|
label=_('Owner users'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'owner_group?',
|
|
|
|
label=_('Owner groups'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
2015-08-11 01:19:59 -05:00
|
|
|
Str(
|
|
|
|
'owner_service?',
|
|
|
|
label=_('Owner services'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
2015-08-17 02:39:48 -05:00
|
|
|
Str(
|
|
|
|
'owner?',
|
|
|
|
label=_('Failed owners'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
2015-08-18 14:44:13 -05:00
|
|
|
Str(
|
|
|
|
'service?',
|
|
|
|
label=_('Vault service'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Flag(
|
|
|
|
'shared?',
|
|
|
|
label=_('Shared vault'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'username?',
|
|
|
|
label=_('Vault user'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2014-10-21 09:57:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_dn(self, *keys, **options):
|
|
|
|
"""
|
|
|
|
Generates vault DN from parameters.
|
|
|
|
"""
|
|
|
|
service = options.get('service')
|
|
|
|
shared = options.get('shared')
|
2014-10-17 11:05:34 -05:00
|
|
|
user = options.get('username')
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2015-08-19 06:32:01 -05:00
|
|
|
count = (bool(service) + bool(shared) + bool(user))
|
2014-10-21 09:57:08 -05:00
|
|
|
if count > 1:
|
|
|
|
raise errors.MutuallyExclusiveError(
|
|
|
|
reason=_('Service, shared, and user options ' +
|
|
|
|
'cannot be specified simultaneously'))
|
|
|
|
|
|
|
|
# TODO: create container_dn after object initialization then reuse it
|
|
|
|
container_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
|
|
|
|
dn = super(vault, self).get_dn(*keys, **options)
|
|
|
|
assert dn.endswith(container_dn)
|
|
|
|
rdns = DN(*dn[:-len(container_dn)])
|
|
|
|
|
|
|
|
if not count:
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = kerberos.Principal(getattr(context, 'principal'))
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
if principal.is_host:
|
2014-10-21 09:57:08 -05:00
|
|
|
raise errors.NotImplementedError(
|
|
|
|
reason=_('Host is not supported'))
|
2016-06-23 11:54:49 -05:00
|
|
|
elif principal.is_service:
|
|
|
|
service = unicode(principal)
|
2014-10-21 09:57:08 -05:00
|
|
|
else:
|
2016-06-23 11:54:49 -05:00
|
|
|
user = principal.username
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
if service:
|
|
|
|
parent_dn = DN(('cn', service), ('cn', 'services'), container_dn)
|
|
|
|
elif shared:
|
|
|
|
parent_dn = DN(('cn', 'shared'), container_dn)
|
2015-08-19 06:32:01 -05:00
|
|
|
elif user:
|
2014-10-21 09:57:08 -05:00
|
|
|
parent_dn = DN(('cn', user), ('cn', 'users'), container_dn)
|
2015-08-19 06:32:01 -05:00
|
|
|
else:
|
|
|
|
raise RuntimeError
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
return DN(rdns, parent_dn)
|
|
|
|
|
2014-10-17 11:05:34 -05:00
|
|
|
def create_container(self, dn, owner_dn):
|
2014-10-21 09:57:08 -05:00
|
|
|
"""
|
|
|
|
Creates vault container and its parents.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: create container_dn after object initialization then reuse it
|
|
|
|
container_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
|
|
|
|
entries = []
|
|
|
|
|
|
|
|
while dn:
|
|
|
|
assert dn.endswith(container_dn)
|
|
|
|
|
|
|
|
rdn = dn[0]
|
|
|
|
entry = self.backend.make_entry(
|
|
|
|
dn,
|
|
|
|
{
|
2014-10-17 11:05:34 -05:00
|
|
|
'objectclass': ['ipaVaultContainer'],
|
2014-10-21 09:57:08 -05:00
|
|
|
'cn': rdn['cn'],
|
2014-10-17 11:05:34 -05:00
|
|
|
'owner': [owner_dn],
|
2014-10-21 09:57:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
# if entry can be added, return
|
|
|
|
try:
|
|
|
|
self.backend.add_entry(entry)
|
|
|
|
break
|
|
|
|
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# otherwise, create parent entry first
|
|
|
|
dn = DN(*dn[1:])
|
|
|
|
entries.insert(0, entry)
|
|
|
|
|
|
|
|
# then create the entries again
|
|
|
|
for entry in entries:
|
|
|
|
self.backend.add_entry(entry)
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def get_key_id(self, dn):
|
|
|
|
"""
|
|
|
|
Generates a client key ID to archive/retrieve data in KRA.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: create container_dn after object initialization then reuse it
|
|
|
|
container_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
|
|
|
|
# make sure the DN is a vault DN
|
|
|
|
if not dn.endswith(container_dn, 1):
|
|
|
|
raise ValueError('Invalid vault DN: %s' % dn)
|
|
|
|
|
|
|
|
# construct the vault ID from the bottom up
|
|
|
|
id = u''
|
|
|
|
for rdn in dn[:-len(container_dn)]:
|
|
|
|
name = rdn['cn']
|
|
|
|
id = u'/' + name + id
|
|
|
|
|
|
|
|
return 'ipa:' + id
|
|
|
|
|
2016-04-27 08:41:12 -05:00
|
|
|
def get_container_attribute(self, entry, options):
|
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
container_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
if entry.dn.endswith(DN(('cn', 'services'), container_dn)):
|
|
|
|
entry['service'] = entry.dn[1]['cn']
|
|
|
|
elif entry.dn.endswith(DN(('cn', 'shared'), container_dn)):
|
|
|
|
entry['shared'] = True
|
|
|
|
elif entry.dn.endswith(DN(('cn', 'users'), container_dn)):
|
|
|
|
entry['username'] = entry.dn[1]['cn']
|
2014-10-24 18:53:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vault_add_internal(LDAPCreate):
|
2018-06-04 05:19:42 -05:00
|
|
|
__doc__ = _('Add a vault.')
|
2014-10-24 18:53:16 -05:00
|
|
|
|
|
|
|
NO_CLI = True
|
|
|
|
|
2016-04-27 08:46:14 -05:00
|
|
|
takes_options = LDAPCreate.takes_options + vault_options
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
msg_summary = _('Added vault "%(value)s"')
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys,
|
|
|
|
**options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = kerberos.Principal(getattr(context, 'principal'))
|
|
|
|
if principal.is_service:
|
|
|
|
owner_dn = self.api.Object.service.get_dn(unicode(principal))
|
2014-10-17 11:05:34 -05:00
|
|
|
else:
|
2016-06-23 11:54:49 -05:00
|
|
|
owner_dn = self.api.Object.user.get_dn(principal.username)
|
2014-10-17 11:05:34 -05:00
|
|
|
|
2015-08-10 13:57:58 -05:00
|
|
|
parent_dn = DN(*dn[1:])
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
try:
|
2015-09-03 01:46:59 -05:00
|
|
|
self.obj.create_container(parent_dn, owner_dn)
|
2016-08-18 03:11:25 -05:00
|
|
|
except (errors.DuplicateEntry, errors.ACIError):
|
2014-10-21 09:57:08 -05:00
|
|
|
pass
|
|
|
|
|
2015-08-10 13:57:58 -05:00
|
|
|
# vault should be owned by the creator
|
2014-10-17 11:05:34 -05:00
|
|
|
entry_attrs['owner'] = owner_dn
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
return dn
|
|
|
|
|
2015-08-18 14:44:13 -05:00
|
|
|
def post_callback(self, ldap, dn, entry, *keys, **options):
|
|
|
|
self.obj.get_container_attribute(entry, options)
|
|
|
|
return dn
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
@register()
|
|
|
|
class vault_del(LDAPDelete):
|
|
|
|
__doc__ = _('Delete a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPDelete.takes_options + vault_options
|
|
|
|
|
|
|
|
msg_summary = _('Deleted vault "%(value)s"')
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def pre_callback(self, ldap, dn, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, *args, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
with self.api.Backend.kra.get_client() as kra_client:
|
|
|
|
kra_account = pki.account.AccountClient(kra_client.connection)
|
|
|
|
kra_account.login()
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
client_key_id = self.obj.get_key_id(dn)
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
# deactivate vault record in KRA
|
|
|
|
response = kra_client.keys.list_keys(
|
|
|
|
client_key_id, pki.key.KeyClient.KEY_STATUS_ACTIVE)
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
for key_info in response.key_infos:
|
|
|
|
kra_client.keys.modify_key_status(
|
|
|
|
key_info.get_key_id(),
|
|
|
|
pki.key.KeyClient.KEY_STATUS_INACTIVE)
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
kra_account.logout()
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
@register()
|
|
|
|
class vault_find(LDAPSearch):
|
|
|
|
__doc__ = _('Search for vaults.')
|
|
|
|
|
2015-08-19 06:32:01 -05:00
|
|
|
takes_options = LDAPSearch.takes_options + vault_options + (
|
|
|
|
Flag(
|
|
|
|
'services?',
|
|
|
|
doc=_('List all service vaults'),
|
|
|
|
),
|
|
|
|
Flag(
|
|
|
|
'users?',
|
|
|
|
doc=_('List all user vaults'),
|
|
|
|
),
|
|
|
|
)
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2014-10-17 11:05:34 -05:00
|
|
|
has_output_params = LDAPSearch.has_output_params
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
msg_summary = ngettext(
|
|
|
|
'%(count)d vault matched',
|
|
|
|
'%(count)d vaults matched',
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args,
|
|
|
|
**options):
|
|
|
|
assert isinstance(base_dn, DN)
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
2015-08-19 06:32:01 -05:00
|
|
|
if options.get('users') or options.get('services'):
|
|
|
|
mutex = ['service', 'services', 'shared', 'username', 'users']
|
|
|
|
count = sum(bool(options.get(option)) for option in mutex)
|
|
|
|
if count > 1:
|
|
|
|
raise errors.MutuallyExclusiveError(
|
|
|
|
reason=_('Service(s), shared, and user(s) options ' +
|
|
|
|
'cannot be specified simultaneously'))
|
|
|
|
|
|
|
|
scope = ldap.SCOPE_SUBTREE
|
|
|
|
container_dn = DN(self.obj.container_dn,
|
|
|
|
self.api.env.basedn)
|
|
|
|
|
|
|
|
if options.get('services'):
|
|
|
|
base_dn = DN(('cn', 'services'), container_dn)
|
|
|
|
else:
|
|
|
|
base_dn = DN(('cn', 'users'), container_dn)
|
|
|
|
else:
|
|
|
|
base_dn = self.obj.get_dn(None, **options)
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2015-08-19 06:32:01 -05:00
|
|
|
return filter, base_dn, scope
|
2014-10-21 09:57:08 -05:00
|
|
|
|
2015-08-18 14:44:13 -05:00
|
|
|
def post_callback(self, ldap, entries, truncated, *args, **options):
|
|
|
|
for entry in entries:
|
|
|
|
self.obj.get_container_attribute(entry, options)
|
|
|
|
return truncated
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
def exc_callback(self, args, options, exc, call_func, *call_args,
|
|
|
|
**call_kwargs):
|
|
|
|
if call_func.__name__ == 'find_entries':
|
|
|
|
if isinstance(exc, errors.NotFound):
|
|
|
|
# ignore missing containers since they will be created
|
|
|
|
# automatically on vault creation.
|
|
|
|
raise errors.EmptyResult(reason=str(exc))
|
|
|
|
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
|
2015-07-31 00:53:15 -05:00
|
|
|
@register()
|
|
|
|
class vault_mod_internal(LDAPUpdate):
|
2018-06-04 05:19:42 -05:00
|
|
|
__doc__ = _('Modify a vault.')
|
2015-07-31 00:53:15 -05:00
|
|
|
|
|
|
|
NO_CLI = True
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
takes_options = LDAPUpdate.takes_options + vault_options
|
|
|
|
|
|
|
|
msg_summary = _('Modified vault "%(value)s"')
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list,
|
|
|
|
*keys, **options):
|
|
|
|
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
2015-08-18 14:44:13 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
self.obj.get_container_attribute(entry_attrs, options)
|
|
|
|
return dn
|
|
|
|
|
2014-10-21 09:57:08 -05:00
|
|
|
|
|
|
|
@register()
|
|
|
|
class vault_show(LDAPRetrieve):
|
|
|
|
__doc__ = _('Display information about a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPRetrieve.takes_options + vault_options
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2014-10-17 11:05:34 -05:00
|
|
|
has_output_params = LDAPRetrieve.has_output_params
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
2015-08-18 14:44:13 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
self.obj.get_container_attribute(entry_attrs, options)
|
|
|
|
return dn
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultconfig(Object):
|
|
|
|
__doc__ = _('Vault configuration')
|
|
|
|
|
|
|
|
takes_params = (
|
|
|
|
Bytes(
|
|
|
|
'transport_cert',
|
|
|
|
label=_('Transport Certificate'),
|
|
|
|
),
|
2016-05-30 11:42:01 -05:00
|
|
|
Str(
|
|
|
|
'kra_server_server*',
|
|
|
|
label=_('IPA KRA servers'),
|
|
|
|
doc=_('IPA servers configured as key recovery agents'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
)
|
2015-06-05 03:49:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class vaultconfig_show(Retrieve):
|
|
|
|
__doc__ = _('Show vault configuration.')
|
|
|
|
|
|
|
|
takes_options = (
|
|
|
|
Str(
|
|
|
|
'transport_out?',
|
|
|
|
doc=_('Output file to store the transport certificate'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def execute(self, *args, **options):
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
with self.api.Backend.kra.get_client() as kra_client:
|
|
|
|
transport_cert = kra_client.system_certs.get_transport_cert()
|
|
|
|
config = {'transport_cert': transport_cert.binary}
|
2017-05-16 10:29:39 -05:00
|
|
|
|
|
|
|
self.api.Object.config.show_servroles_attributes(
|
|
|
|
config, "KRA server", **options)
|
2016-05-30 11:42:01 -05:00
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
return {
|
2016-05-30 11:42:01 -05:00
|
|
|
'result': config,
|
2015-06-05 03:49:39 -05:00
|
|
|
'value': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2014-10-24 18:53:16 -05:00
|
|
|
class vault_archive_internal(PKQuery):
|
2018-06-04 05:19:42 -05:00
|
|
|
__doc__ = _('Archive data into a vault.')
|
2014-10-24 18:53:16 -05:00
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
NO_CLI = True
|
|
|
|
|
|
|
|
takes_options = vault_options + (
|
|
|
|
Bytes(
|
|
|
|
'session_key',
|
|
|
|
doc=_('Session key wrapped with transport certificate'),
|
|
|
|
),
|
|
|
|
Bytes(
|
|
|
|
'vault_data',
|
|
|
|
doc=_('Vault data encrypted with session key'),
|
|
|
|
),
|
|
|
|
Bytes(
|
|
|
|
'nonce',
|
|
|
|
doc=_('Nonce'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2014-10-24 18:53:16 -05:00
|
|
|
has_output = output.standard_entry
|
|
|
|
|
|
|
|
msg_summary = _('Archived data into vault "%(value)s"')
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def execute(self, *args, **options):
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
wrapped_vault_data = options.pop('vault_data')
|
|
|
|
nonce = options.pop('nonce')
|
|
|
|
wrapped_session_key = options.pop('session_key')
|
|
|
|
|
|
|
|
# retrieve vault info
|
2014-10-24 18:53:16 -05:00
|
|
|
vault = self.api.Command.vault_show(*args, **options)['result']
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
# connect to KRA
|
2017-01-13 02:08:42 -06:00
|
|
|
with self.api.Backend.kra.get_client() as kra_client:
|
|
|
|
kra_account = pki.account.AccountClient(kra_client.connection)
|
|
|
|
kra_account.login()
|
|
|
|
|
|
|
|
client_key_id = self.obj.get_key_id(vault['dn'])
|
|
|
|
|
|
|
|
# deactivate existing vault record in KRA
|
|
|
|
response = kra_client.keys.list_keys(
|
|
|
|
client_key_id,
|
|
|
|
pki.key.KeyClient.KEY_STATUS_ACTIVE)
|
|
|
|
|
|
|
|
for key_info in response.key_infos:
|
|
|
|
kra_client.keys.modify_key_status(
|
|
|
|
key_info.get_key_id(),
|
|
|
|
pki.key.KeyClient.KEY_STATUS_INACTIVE)
|
|
|
|
|
|
|
|
# forward wrapped data to KRA
|
|
|
|
kra_client.keys.archive_encrypted_data(
|
|
|
|
client_key_id,
|
|
|
|
pki.key.KeyClient.PASS_PHRASE_TYPE,
|
|
|
|
wrapped_vault_data,
|
|
|
|
wrapped_session_key,
|
2017-04-26 11:15:40 -05:00
|
|
|
algorithm_oid=DES_EDE3_CBC_OID,
|
|
|
|
nonce_iv=nonce,
|
2017-01-13 02:08:42 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
kra_account.logout()
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2014-10-24 18:53:16 -05:00
|
|
|
response = {
|
|
|
|
'value': args[-1],
|
|
|
|
'result': {},
|
|
|
|
}
|
|
|
|
|
|
|
|
response['summary'] = self.msg_summary % response
|
|
|
|
|
|
|
|
return response
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2014-10-24 18:53:16 -05:00
|
|
|
class vault_retrieve_internal(PKQuery):
|
2018-06-04 05:19:42 -05:00
|
|
|
__doc__ = _('Retrieve data from a vault.')
|
2014-10-24 18:53:16 -05:00
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
NO_CLI = True
|
|
|
|
|
|
|
|
takes_options = vault_options + (
|
|
|
|
Bytes(
|
|
|
|
'session_key',
|
|
|
|
doc=_('Session key wrapped with transport certificate'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2014-10-24 18:53:16 -05:00
|
|
|
has_output = output.standard_entry
|
|
|
|
|
|
|
|
msg_summary = _('Retrieved data from vault "%(value)s"')
|
|
|
|
|
2015-06-05 03:49:39 -05:00
|
|
|
def execute(self, *args, **options):
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
if not self.api.Command.kra_is_enabled()['result']:
|
2015-06-05 03:49:39 -05:00
|
|
|
raise errors.InvocationError(
|
|
|
|
format=_('KRA service is not enabled'))
|
|
|
|
|
|
|
|
wrapped_session_key = options.pop('session_key')
|
|
|
|
|
|
|
|
# retrieve vault info
|
2014-10-24 18:53:16 -05:00
|
|
|
vault = self.api.Command.vault_show(*args, **options)['result']
|
2015-06-05 03:49:39 -05:00
|
|
|
|
|
|
|
# connect to KRA
|
2017-01-13 02:08:42 -06:00
|
|
|
with self.api.Backend.kra.get_client() as kra_client:
|
|
|
|
kra_account = pki.account.AccountClient(kra_client.connection)
|
|
|
|
kra_account.login()
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
client_key_id = self.obj.get_key_id(vault['dn'])
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
# find vault record in KRA
|
|
|
|
response = kra_client.keys.list_keys(
|
|
|
|
client_key_id,
|
|
|
|
pki.key.KeyClient.KEY_STATUS_ACTIVE)
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
if not len(response.key_infos):
|
|
|
|
raise errors.NotFound(reason=_('No archived data.'))
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
key_info = response.key_infos[0]
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
# retrieve encrypted data from KRA
|
|
|
|
key = kra_client.keys.retrieve_key(
|
|
|
|
key_info.get_key_id(),
|
|
|
|
wrapped_session_key)
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2017-01-13 02:08:42 -06:00
|
|
|
kra_account.logout()
|
2015-06-05 03:49:39 -05:00
|
|
|
|
2014-10-24 18:53:16 -05:00
|
|
|
response = {
|
|
|
|
'value': args[-1],
|
|
|
|
'result': {
|
|
|
|
'vault_data': key.encrypted_data,
|
|
|
|
'nonce': key.nonce_data,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
response['summary'] = self.msg_summary % response
|
|
|
|
|
|
|
|
return response
|
2015-06-10 03:50:42 -05:00
|
|
|
|
|
|
|
|
2014-10-17 11:05:34 -05:00
|
|
|
@register()
|
2015-08-11 01:19:59 -05:00
|
|
|
class vault_add_owner(VaultModMember, LDAPAddMember):
|
2014-10-17 11:05:34 -05:00
|
|
|
__doc__ = _('Add owners to a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPAddMember.takes_options + vault_options
|
|
|
|
|
|
|
|
member_attributes = ['owner']
|
2015-08-17 02:39:48 -05:00
|
|
|
member_param_label = _('owner %s')
|
2014-10-17 11:05:34 -05:00
|
|
|
member_count_out = ('%i owner added.', '%i owners added.')
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
output.Entry('result'),
|
|
|
|
output.Output(
|
|
|
|
'failed',
|
|
|
|
type=dict,
|
|
|
|
doc=_('Owners that could not be added'),
|
|
|
|
),
|
|
|
|
output.Output(
|
|
|
|
'completed',
|
|
|
|
type=int,
|
|
|
|
doc=_('Number of owners added'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2015-08-11 01:19:59 -05:00
|
|
|
class vault_remove_owner(VaultModMember, LDAPRemoveMember):
|
2014-10-17 11:05:34 -05:00
|
|
|
__doc__ = _('Remove owners from a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPRemoveMember.takes_options + vault_options
|
|
|
|
|
|
|
|
member_attributes = ['owner']
|
2015-08-17 02:39:48 -05:00
|
|
|
member_param_label = _('owner %s')
|
2014-10-17 11:05:34 -05:00
|
|
|
member_count_out = ('%i owner removed.', '%i owners removed.')
|
|
|
|
|
|
|
|
has_output = (
|
|
|
|
output.Entry('result'),
|
|
|
|
output.Output(
|
|
|
|
'failed',
|
|
|
|
type=dict,
|
|
|
|
doc=_('Owners that could not be removed'),
|
|
|
|
),
|
|
|
|
output.Output(
|
|
|
|
'completed',
|
|
|
|
type=int,
|
|
|
|
doc=_('Number of owners removed'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2015-08-11 01:19:59 -05:00
|
|
|
class vault_add_member(VaultModMember, LDAPAddMember):
|
2014-10-17 11:05:34 -05:00
|
|
|
__doc__ = _('Add members to a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPAddMember.takes_options + vault_options
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2015-08-11 01:19:59 -05:00
|
|
|
class vault_remove_member(VaultModMember, LDAPRemoveMember):
|
2014-10-17 11:05:34 -05:00
|
|
|
__doc__ = _('Remove members from a vault.')
|
|
|
|
|
|
|
|
takes_options = LDAPRemoveMember.takes_options + vault_options
|
|
|
|
|
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
@register()
|
|
|
|
class kra_is_enabled(Command):
|
2018-06-04 05:19:42 -05:00
|
|
|
__doc__ = _('Checks if any of the servers has the KRA service enabled')
|
2015-06-10 03:50:42 -05:00
|
|
|
NO_CLI = True
|
|
|
|
|
|
|
|
has_output = output.standard_value
|
|
|
|
|
|
|
|
def execute(self, *args, **options):
|
|
|
|
base_dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
|
|
|
self.api.env.basedn)
|
|
|
|
filter = '(&(objectClass=ipaConfigObject)(cn=KRA))'
|
|
|
|
try:
|
|
|
|
self.api.Backend.ldap2.find_entries(
|
|
|
|
base_dn=base_dn, filter=filter, attrs_list=[])
|
|
|
|
except errors.NotFound:
|
|
|
|
result = False
|
|
|
|
else:
|
|
|
|
result = True
|
|
|
|
return dict(result=result, value=pkey_to_value(None, options))
|