2009-05-27 08:55:26 -05:00
|
|
|
# Authors:
|
|
|
|
# Jason Gerard DeRose <jderose@redhat.com>
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# 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.
|
2009-05-27 08:55:26 -05:00
|
|
|
#
|
|
|
|
# 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
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
import logging
|
|
|
|
|
2016-10-13 02:12:31 -05:00
|
|
|
from cryptography.hazmat.primitives import hashes
|
2015-09-11 06:43:28 -05:00
|
|
|
import six
|
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-08-11 06:51:14 -05:00
|
|
|
|
2016-06-09 06:13:24 -05:00
|
|
|
from ipalib import api, errors, messages
|
2017-07-03 10:10:34 -05:00
|
|
|
from ipalib import StrEnum, Bool, Str, Flag
|
|
|
|
from ipalib.parameters import Principal, Certificate
|
2014-06-10 10:27:51 -05:00
|
|
|
from ipalib.plugable import Registry
|
2016-04-20 08:41:34 -05:00
|
|
|
from .baseldap import (
|
2015-12-16 12:04:20 -06:00
|
|
|
host_is_master,
|
|
|
|
add_missing_object_class,
|
|
|
|
pkey_to_value,
|
|
|
|
LDAPObject,
|
|
|
|
LDAPCreate,
|
|
|
|
LDAPDelete,
|
|
|
|
LDAPUpdate,
|
|
|
|
LDAPSearch,
|
|
|
|
LDAPRetrieve,
|
|
|
|
LDAPAddMember,
|
|
|
|
LDAPRemoveMember,
|
|
|
|
LDAPQuery,
|
|
|
|
LDAPAddAttribute,
|
2016-06-23 12:14:53 -05:00
|
|
|
LDAPRemoveAttribute,
|
|
|
|
LDAPAddAttributeViaOption,
|
|
|
|
LDAPRemoveAttributeViaOption)
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib import x509
|
|
|
|
from ipalib import _, ngettext
|
|
|
|
from ipalib import util
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipalib import output
|
2016-06-23 11:54:49 -05:00
|
|
|
from ipapython import kerberos
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipapython.dn import DN
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Services
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
A IPA service represents a service that runs on a host. The IPA service
|
|
|
|
record can store a Kerberos principal, an SSL certificate, or both.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
An IPA service can be managed directly from a machine, provided that
|
|
|
|
machine has been given the correct permission. This is true even for
|
|
|
|
machines other than the one the service is associated with. For example,
|
|
|
|
requesting an SSL certificate using the host service principal credentials
|
2011-03-04 10:08:54 -06:00
|
|
|
of the host. To manage a service using host credentials you need to
|
2010-08-24 22:40:32 -05:00
|
|
|
kinit as the host:
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
# kinit -kt /etc/krb5.keytab host/ipa.example.com@EXAMPLE.COM
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Adding an IPA service allows the associated service to request an SSL
|
|
|
|
certificate or keytab, but this is performed as a separate step; they
|
|
|
|
are not produced as a result of adding the service.
|
|
|
|
|
|
|
|
Only the public aspect of a certificate is stored in a service record;
|
|
|
|
the private key is not stored.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new IPA service:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa service-add HTTP/web.example.com
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Allow a host to manage an IPA service certificate:
|
2012-10-02 10:06:10 -05:00
|
|
|
ipa service-add-host --hosts=web.example.com HTTP/web.example.com
|
|
|
|
ipa role-add-member --hosts=web.example.com certadmin
|
|
|
|
|
|
|
|
Override a default list of supported PAC types for the service:
|
|
|
|
ipa service-mod HTTP/web.example.com --pac-type=MS-PAC
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2013-02-27 03:32:40 -06:00
|
|
|
A typical use case where overriding the PAC type is needed is NFS.
|
|
|
|
Currently the related code in the Linux kernel can only handle Kerberos
|
|
|
|
tickets up to a maximal size. Since the PAC data can become quite large it
|
|
|
|
is recommended to set --pac-type=NONE for NFS services.
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Delete an IPA service:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa service-del HTTP/web.example.com
|
|
|
|
|
2011-01-13 13:37:10 -06:00
|
|
|
Find all IPA services associated with a host:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa service-find web.example.com
|
|
|
|
|
|
|
|
Find all HTTP services:
|
|
|
|
ipa service-find HTTP
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2011-02-16 03:35:49 -06:00
|
|
|
Disable the service Kerberos key and SSL certificate:
|
2010-07-12 16:45:06 -05:00
|
|
|
ipa service-disable HTTP/web.example.com
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
Request a certificate for an IPA service:
|
|
|
|
ipa cert-request --principal=HTTP/web.example.com example.csr
|
2014-10-02 09:57:08 -05:00
|
|
|
""") + _("""
|
|
|
|
Allow user to create a keytab:
|
|
|
|
ipa service-allow-create-keytab HTTP/web.example.com --users=tuser1
|
|
|
|
""") + _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Generate and retrieve a keytab for an IPA service:
|
|
|
|
ipa-getkeytab -s ipa.example.com -p HTTP/web.example.com -k /etc/httpd/httpd.keytab
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
register = Registry()
|
|
|
|
|
2010-08-05 21:41:32 -05:00
|
|
|
output_params = (
|
2011-11-10 06:46:16 -06:00
|
|
|
Flag('has_keytab',
|
|
|
|
label=_('Keytab'),
|
|
|
|
),
|
2010-08-05 21:41:32 -05:00
|
|
|
Str('managedby_host',
|
|
|
|
label='Managed by',
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_read_keys_user',
|
|
|
|
label=_('Users allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_read_keys_group',
|
|
|
|
label=_('Groups allowed to retrieve keytab'),
|
|
|
|
),
|
2014-12-01 03:15:21 -06:00
|
|
|
Str('ipaallowedtoperform_read_keys_host',
|
|
|
|
label=_('Hosts allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_read_keys_hostgroup',
|
|
|
|
label=_('Host Groups allowed to retrieve keytab'),
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_write_keys_user',
|
|
|
|
label=_('Users allowed to create keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys_group',
|
|
|
|
label=_('Groups allowed to create keytab'),
|
|
|
|
),
|
2014-12-01 03:15:21 -06:00
|
|
|
Str('ipaallowedtoperform_write_keys_host',
|
|
|
|
label=_('Hosts allowed to create keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys_hostgroup',
|
|
|
|
label=_('Host Groups allowed to create keytab'),
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_read_keys',
|
|
|
|
label=_('Failed allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys',
|
|
|
|
label=_('Failed allowed to create keytab'),
|
|
|
|
),
|
2010-08-05 21:41:32 -05:00
|
|
|
)
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
ticket_flags_params = (
|
|
|
|
Bool('ipakrbrequirespreauth?',
|
|
|
|
cli_name='requires_pre_auth',
|
|
|
|
label=_('Requires pre-authentication'),
|
|
|
|
doc=_('Pre-authentication is required for the service'),
|
|
|
|
flags=['virtual_attribute', 'no_search'],
|
|
|
|
),
|
|
|
|
Bool('ipakrbokasdelegate?',
|
|
|
|
cli_name='ok_as_delegate',
|
|
|
|
label=_('Trusted for delegation'),
|
|
|
|
doc=_('Client credentials may be delegated to the service'),
|
|
|
|
flags=['virtual_attribute', 'no_search'],
|
|
|
|
),
|
2016-08-11 03:52:05 -05:00
|
|
|
Bool('ipakrboktoauthasdelegate?',
|
|
|
|
cli_name='ok_to_auth_as_delegate',
|
|
|
|
label=_('Trusted to authenticate as user'),
|
|
|
|
doc=_('The service is allowed to authenticate on behalf of a client'),
|
|
|
|
flags=['virtual_attribute', 'no_search'],
|
|
|
|
),
|
2013-03-18 06:31:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
_ticket_flags_map = {
|
|
|
|
'ipakrbrequirespreauth': 0x00000080,
|
|
|
|
'ipakrbokasdelegate': 0x00100000,
|
2016-08-11 03:52:05 -05:00
|
|
|
'ipakrboktoauthasdelegate': 0x00200000,
|
2013-03-18 06:31:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_ticket_flags_default = _ticket_flags_map['ipakrbrequirespreauth']
|
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
|
|
|
|
def validate_realm(ugettext, principal):
|
|
|
|
"""
|
|
|
|
Check that the principal's realm matches IPA realm if present
|
|
|
|
"""
|
|
|
|
realm = principal.realm
|
|
|
|
if realm is not None and realm != api.env.realm:
|
|
|
|
raise errors.RealmMismatch()
|
|
|
|
|
|
|
|
|
|
|
|
def normalize_principal(value):
|
|
|
|
"""
|
|
|
|
Ensure that the name in the principal is lower-case. The realm is
|
|
|
|
upper-case by convention but it isn't required.
|
|
|
|
|
|
|
|
The principal is validated at this point.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
principal = kerberos.Principal(value, realm=api.env.realm)
|
|
|
|
except ValueError:
|
|
|
|
raise errors.ValidationError(
|
|
|
|
name='principal', reason=_("Malformed principal"))
|
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
return unicode(principal)
|
|
|
|
|
2015-06-23 06:40:30 -05:00
|
|
|
|
2016-08-26 00:31:13 -05:00
|
|
|
def revoke_certs(certs):
|
2015-06-23 06:40:30 -05:00
|
|
|
"""
|
|
|
|
revoke the certificates removed from host/service entry
|
|
|
|
|
2016-08-26 00:31:13 -05:00
|
|
|
:param certs: Output of a 'cert_find' command.
|
2015-06-23 06:40:30 -05:00
|
|
|
|
2016-08-26 00:31:13 -05:00
|
|
|
"""
|
|
|
|
for cert in certs:
|
|
|
|
if 'cacn' not in cert:
|
|
|
|
# Cert is known to IPA, but has no associated CA.
|
|
|
|
# If it was issued by 3rd-party CA, we can't revoke it.
|
|
|
|
# If it was issued by a Dogtag lightweight CA that was
|
|
|
|
# subsequently deleted, we can't revoke it via IPA.
|
|
|
|
# We could go directly to Dogtag to revoke it, but the
|
|
|
|
# issuer's cert should have been revoked so never mind.
|
2015-06-23 06:40:30 -05:00
|
|
|
continue
|
2016-08-26 00:31:13 -05:00
|
|
|
|
|
|
|
if cert['revoked']:
|
|
|
|
# cert is already revoked
|
2015-06-23 06:40:30 -05:00
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
2016-08-26 00:31:13 -05:00
|
|
|
api.Command['cert_revoke'](
|
|
|
|
cert['serial_number'],
|
|
|
|
cacn=cert['cacn'],
|
|
|
|
revocation_reason=4,
|
|
|
|
)
|
2015-06-23 06:40:30 -05:00
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
def set_certificate_attrs(entry_attrs):
|
|
|
|
"""
|
|
|
|
Set individual attributes from some values from a certificate.
|
|
|
|
|
|
|
|
entry_attrs is a dict of an entry
|
|
|
|
|
|
|
|
returns nothing
|
|
|
|
"""
|
|
|
|
if not 'usercertificate' in entry_attrs:
|
|
|
|
return
|
|
|
|
if type(entry_attrs['usercertificate']) in (list, tuple):
|
|
|
|
cert = entry_attrs['usercertificate'][0]
|
|
|
|
else:
|
|
|
|
cert = entry_attrs['usercertificate']
|
2016-10-13 02:12:31 -05:00
|
|
|
entry_attrs['subject'] = unicode(DN(cert.subject))
|
2017-02-10 07:20:22 -06:00
|
|
|
entry_attrs['serial_number'] = unicode(cert.serial_number)
|
|
|
|
entry_attrs['serial_number_hex'] = u'0x%X' % cert.serial_number
|
2016-10-13 02:12:31 -05:00
|
|
|
entry_attrs['issuer'] = unicode(DN(cert.issuer))
|
|
|
|
entry_attrs['valid_not_before'] = x509.format_datetime(
|
|
|
|
cert.not_valid_before)
|
|
|
|
entry_attrs['valid_not_after'] = x509.format_datetime(cert.not_valid_after)
|
2016-10-10 21:43:22 -05:00
|
|
|
entry_attrs['sha1_fingerprint'] = x509.to_hex_with_colons(
|
2016-10-13 02:12:31 -05:00
|
|
|
cert.fingerprint(hashes.SHA1()))
|
2017-02-23 10:03:01 -06:00
|
|
|
entry_attrs['sha256_fingerprint'] = x509.to_hex_with_colons(
|
|
|
|
cert.fingerprint(hashes.SHA256()))
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
def check_required_principal(ldap, principal):
|
2012-03-19 09:16:49 -05:00
|
|
|
"""
|
|
|
|
Raise an error if the host of this prinicipal is an IPA master and one
|
|
|
|
of the principals required for proper execution.
|
|
|
|
"""
|
|
|
|
try:
|
2016-06-23 11:54:49 -05:00
|
|
|
host_is_master(ldap, principal.hostname)
|
2016-09-26 07:08:17 -05:00
|
|
|
except errors.ValidationError:
|
2012-04-05 10:28:43 -05:00
|
|
|
service_types = ['HTTP', 'ldap', 'DNS', 'dogtagldap']
|
2016-06-23 11:54:49 -05:00
|
|
|
if principal.service_name in service_types:
|
2012-03-19 09:16:49 -05:00
|
|
|
raise errors.ValidationError(name='principal', error=_('This principal is required by the IPA master'))
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
def update_krbticketflags(ldap, entry_attrs, attrs_list, options, existing):
|
|
|
|
add = remove = 0
|
|
|
|
|
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-08-11 06:51:14 -05:00
|
|
|
for (name, value) in _ticket_flags_map.items():
|
2013-03-18 06:31:23 -05:00
|
|
|
if name not in options:
|
|
|
|
continue
|
|
|
|
if options[name]:
|
|
|
|
add |= value
|
|
|
|
else:
|
|
|
|
remove |= value
|
|
|
|
|
|
|
|
if not add and not remove:
|
|
|
|
return
|
|
|
|
|
|
|
|
if 'krbticketflags' not in entry_attrs and existing:
|
|
|
|
old_entry_attrs = ldap.get_entry(entry_attrs.dn, ['krbticketflags'])
|
|
|
|
else:
|
|
|
|
old_entry_attrs = entry_attrs
|
|
|
|
|
|
|
|
try:
|
2013-09-10 05:20:24 -05:00
|
|
|
ticket_flags = old_entry_attrs.single_value['krbticketflags']
|
2013-03-18 06:31:23 -05:00
|
|
|
ticket_flags = int(ticket_flags)
|
|
|
|
except (KeyError, ValueError):
|
|
|
|
ticket_flags = _ticket_flags_default
|
|
|
|
|
|
|
|
ticket_flags |= add
|
|
|
|
ticket_flags &= ~remove
|
|
|
|
|
|
|
|
entry_attrs['krbticketflags'] = [ticket_flags]
|
|
|
|
attrs_list.append('krbticketflags')
|
|
|
|
|
|
|
|
def set_kerberos_attrs(entry_attrs, options):
|
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2013-09-10 05:20:24 -05:00
|
|
|
ticket_flags = entry_attrs.single_value.get('krbticketflags',
|
|
|
|
_ticket_flags_default)
|
2013-03-18 06:31:23 -05:00
|
|
|
ticket_flags = int(ticket_flags)
|
|
|
|
except ValueError:
|
|
|
|
return
|
|
|
|
|
|
|
|
all_opt = options.get('all', False)
|
|
|
|
|
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-08-11 06:51:14 -05:00
|
|
|
for (name, value) in _ticket_flags_map.items():
|
2013-03-18 06:31:23 -05:00
|
|
|
if name in options or all_opt:
|
|
|
|
entry_attrs[name] = bool(ticket_flags & value)
|
|
|
|
|
2014-10-02 09:57:08 -05:00
|
|
|
def rename_ipaallowedtoperform_from_ldap(entry_attrs, options):
|
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
|
|
|
|
for subtype in ('read_keys', 'write_keys'):
|
|
|
|
name = 'ipaallowedtoperform;%s' % subtype
|
|
|
|
if name in entry_attrs:
|
|
|
|
new_name = 'ipaallowedtoperform_%s' % subtype
|
|
|
|
entry_attrs[new_name] = entry_attrs.pop(name)
|
|
|
|
|
|
|
|
def rename_ipaallowedtoperform_to_ldap(entry_attrs):
|
|
|
|
for subtype in ('read_keys', 'write_keys'):
|
|
|
|
name = 'ipaallowedtoperform_%s' % subtype
|
|
|
|
if name in entry_attrs:
|
|
|
|
new_name = 'ipaallowedtoperform;%s' % subtype
|
|
|
|
entry_attrs[new_name] = entry_attrs.pop(name)
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service(LDAPObject):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
|
|
|
Service object.
|
|
|
|
"""
|
2009-09-15 06:04:09 -05:00
|
|
|
container_dn = api.env.container_service
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('service')
|
|
|
|
object_name_plural = _('services')
|
2009-09-15 06:04:09 -05:00
|
|
|
object_class = [
|
|
|
|
'krbprincipal', 'krbprincipalaux', 'krbticketpolicyaux', 'ipaobject',
|
2012-10-01 09:49:34 -05:00
|
|
|
'ipaservice', 'pkiuser'
|
2009-09-15 06:04:09 -05:00
|
|
|
]
|
2014-10-02 09:57:08 -05:00
|
|
|
possible_objectclasses = ['ipakrbprincipal', 'ipaallowedoperations']
|
2014-01-09 07:43:37 -06:00
|
|
|
permission_filter_objectclasses = ['ipaservice']
|
2015-08-12 03:35:38 -05:00
|
|
|
search_attributes = ['krbprincipalname', 'managedby', 'ipakrbauthzdata']
|
2016-06-29 07:54:54 -05:00
|
|
|
default_attributes = [
|
|
|
|
'krbprincipalname', 'krbcanonicalname', 'usercertificate', 'managedby',
|
|
|
|
'ipakrbauthzdata', 'memberof', 'ipaallowedtoperform',
|
|
|
|
'krbprincipalauthind']
|
2009-09-15 06:04:09 -05:00
|
|
|
uuid_attribute = 'ipauniqueid'
|
2009-11-03 08:35:19 -06:00
|
|
|
attribute_members = {
|
|
|
|
'managedby': ['host'],
|
2014-08-18 09:49:40 -05:00
|
|
|
'memberof': ['role'],
|
2014-12-01 03:15:21 -06:00
|
|
|
'ipaallowedtoperform_read_keys': ['user', 'group', 'host', 'hostgroup'],
|
|
|
|
'ipaallowedtoperform_write_keys': ['user', 'group', 'host', 'hostgroup'],
|
2009-09-15 06:04:09 -05:00
|
|
|
}
|
2010-12-02 10:05:54 -06:00
|
|
|
bindable = True
|
2011-02-11 18:04:04 -06:00
|
|
|
relationships = {
|
|
|
|
'managedby': ('Managed by', 'man_by_', 'not_man_by_'),
|
2014-10-02 09:57:08 -05:00
|
|
|
'ipaallowedtoperform_read_keys': ('Allow to retrieve keytab by', 'retrieve_keytab_by_', 'not_retrieve_keytab_by_'),
|
|
|
|
'ipaallowedtoperform_write_keys': ('Allow to create keytab by', 'write_keytab_by_', 'not_write_keytab_by'),
|
2011-02-11 18:04:04 -06:00
|
|
|
}
|
2011-08-22 15:24:07 -05:00
|
|
|
password_attributes = [('krbprincipalkey', 'has_keytab')]
|
2014-03-26 11:11:23 -05:00
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Services': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'all',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass',
|
|
|
|
'ipauniqueid', 'managedby', 'memberof', 'usercertificate',
|
|
|
|
'krbprincipalname', 'krbcanonicalname', 'krbprincipalaliases',
|
|
|
|
'krbprincipalexpiration', 'krbpasswordexpiration',
|
|
|
|
'krblastpwdchange', 'ipakrbauthzdata', 'ipakrbprincipalalias',
|
2016-06-29 08:58:07 -05:00
|
|
|
'krbobjectreferences', 'krbprincipalauthind',
|
2014-03-26 11:11:23 -05:00
|
|
|
},
|
|
|
|
},
|
2014-06-04 10:39:10 -05:00
|
|
|
'System: Add Services': {
|
|
|
|
'ipapermright': {'add'},
|
|
|
|
'replaces': [
|
|
|
|
'(target = "ldap:///krbprincipalname=*,cn=services,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Add Services";allow (add) groupdn = "ldap:///cn=Add Services,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Service Administrators'},
|
|
|
|
},
|
|
|
|
'System: Manage Service Keytab': {
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'krblastpwdchange', 'krbprincipalkey'},
|
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "krbprincipalkey || krblastpwdchange")(target = "ldap:///krbprincipalname=*,cn=services,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Manage service keytab";allow (write) groupdn = "ldap:///cn=Manage service keytab,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
2014-06-27 09:14:56 -05:00
|
|
|
'default_privileges': {'Service Administrators', 'Host Administrators'},
|
2014-06-04 10:39:10 -05:00
|
|
|
},
|
2014-10-02 09:57:08 -05:00
|
|
|
'System: Manage Service Keytab Permissions': {
|
|
|
|
'ipapermright': {'read', 'search', 'compare', 'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'ipaallowedtoperform;write_keys',
|
|
|
|
'ipaallowedtoperform;read_keys', 'objectclass'
|
|
|
|
},
|
|
|
|
'default_privileges': {'Service Administrators', 'Host Administrators'},
|
|
|
|
},
|
2014-06-04 10:39:10 -05:00
|
|
|
'System: Modify Services': {
|
|
|
|
'ipapermright': {'write'},
|
2016-06-29 08:58:07 -05:00
|
|
|
'ipapermdefaultattr': {'usercertificate', 'krbprincipalauthind'},
|
2014-06-04 10:39:10 -05:00
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "usercertificate")(target = "ldap:///krbprincipalname=*,cn=services,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Modify Services";allow (write) groupdn = "ldap:///cn=Modify Services,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Service Administrators'},
|
|
|
|
},
|
2016-06-23 13:06:42 -05:00
|
|
|
'System: Manage Service Principals': {
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'krbprincipalname', 'krbcanonicalname'},
|
|
|
|
'default_privileges': {
|
|
|
|
'Service Administrators',
|
|
|
|
},
|
|
|
|
},
|
2014-06-04 10:39:10 -05:00
|
|
|
'System: Remove Services': {
|
|
|
|
'ipapermright': {'delete'},
|
|
|
|
'replaces': [
|
|
|
|
'(target = "ldap:///krbprincipalname=*,cn=services,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Remove Services";allow (delete) groupdn = "ldap:///cn=Remove Services,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Service Administrators'},
|
|
|
|
},
|
2014-03-26 11:11:23 -05:00
|
|
|
}
|
2009-09-15 06:04:09 -05:00
|
|
|
|
2010-02-08 06:03:28 -06:00
|
|
|
label = _('Services')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('Service')
|
2010-02-08 06:03:28 -06:00
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
takes_params = (
|
2016-06-23 11:54:49 -05:00
|
|
|
Principal(
|
2016-06-23 13:01:34 -05:00
|
|
|
'krbcanonicalname',
|
2016-06-23 11:54:49 -05:00
|
|
|
validate_realm,
|
2016-06-23 13:01:34 -05:00
|
|
|
cli_name='canonical_principal',
|
2016-06-23 13:06:42 -05:00
|
|
|
label=_('Principal name'),
|
2010-02-19 10:08:16 -06:00
|
|
|
doc=_('Service principal'),
|
2009-05-27 08:55:26 -05:00
|
|
|
primary_key=True,
|
2016-06-23 11:54:49 -05:00
|
|
|
normalizer=normalize_principal,
|
|
|
|
require_service=True
|
2009-05-27 08:55:26 -05:00
|
|
|
),
|
2016-06-23 13:06:42 -05:00
|
|
|
Principal(
|
|
|
|
'krbprincipalname*',
|
|
|
|
validate_realm,
|
|
|
|
cli_name='principal',
|
|
|
|
label=_('Principal alias'),
|
|
|
|
doc=_('Service principal alias'),
|
|
|
|
normalizer=normalize_principal,
|
|
|
|
require_service=True,
|
|
|
|
flags={'no_create'}
|
|
|
|
),
|
2017-07-03 10:10:34 -05:00
|
|
|
Certificate('usercertificate*',
|
Certificate management for services.
This is an initial implementation of certificate management for
services. It addresses the mechanism required to view and update
certificates. The complete UI implementation will be addressed in
subsequent patches.
On the server side, the service.py has been modified to define
usercertificate in the service object's takes_params. This is
needed to generate the proper JSON metadata which is needed by
the UI. It also has been modified to accept null certificate for
deletion.
On the client side, the service details page has been modified to
display the base64-encoded certificate in a text area. When the
page is saved, the action handler will store the base64-encoded
certificate in the proper JSON structure. Also the service name
and service hostname are now displayed in separate fields.
The details configuration has been modified to support displaying
and updating certificates. The structure is changed to use maps
to define sections and fields. A section contains name, label,
and an array of fields. A field contains name, label, setup
function, load function, and save function. This is used to
implement custom interface and behavior for certificates.
All other entities, test cases, and test data have been updated
accordingly. Some functions and variables have been renamed to
improve clarity and consistency.
2010-10-07 14:02:44 -05:00
|
|
|
cli_name='certificate',
|
|
|
|
label=_('Certificate'),
|
2016-03-04 05:45:39 -06:00
|
|
|
doc=_('Base-64 encoded service certificate'),
|
2011-02-09 12:24:47 -06:00
|
|
|
flags=['no_search',],
|
2012-08-01 09:14:11 -05:00
|
|
|
),
|
2016-06-29 23:37:16 -05:00
|
|
|
Str('subject',
|
|
|
|
label=_('Subject'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('serial_number',
|
|
|
|
label=_('Serial Number'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('serial_number_hex',
|
|
|
|
label=_('Serial Number (hex)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('issuer',
|
|
|
|
label=_('Issuer'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('valid_not_before',
|
|
|
|
label=_('Not Before'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('valid_not_after',
|
|
|
|
label=_('Not After'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('sha1_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA1)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2017-02-23 10:03:01 -06:00
|
|
|
Str('sha256_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA256)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2016-06-29 23:37:16 -05:00
|
|
|
Str('revocation_reason?',
|
|
|
|
label=_('Revocation reason'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2012-08-01 09:14:11 -05:00
|
|
|
StrEnum('ipakrbauthzdata*',
|
|
|
|
cli_name='pac_type',
|
|
|
|
label=_('PAC type'),
|
2012-10-02 10:06:10 -05:00
|
|
|
doc=_("Override default list of supported PAC types."
|
2013-02-27 03:32:40 -06:00
|
|
|
" Use 'NONE' to disable PAC support for this service,"
|
|
|
|
" e.g. this might be necessary for NFS services."),
|
2012-10-02 10:06:10 -05:00
|
|
|
values=(u'MS-PAC', u'PAD', u'NONE'),
|
2012-08-01 09:14:11 -05:00
|
|
|
),
|
2016-05-04 16:08:45 -05:00
|
|
|
Str('krbprincipalauthind*',
|
|
|
|
cli_name='auth_ind',
|
|
|
|
label=_('Authentication Indicators'),
|
|
|
|
doc=_("Defines a whitelist for Authentication Indicators."
|
|
|
|
" Use 'otp' to allow OTP-based 2FA authentications."
|
|
|
|
" Use 'radius' to allow RADIUS-based 2FA authentications."
|
|
|
|
" Other values may be used for custom configurations."),
|
|
|
|
),
|
2013-03-18 06:31:23 -05:00
|
|
|
) + ticket_flags_params
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2012-10-02 10:06:10 -05:00
|
|
|
def validate_ipakrbauthzdata(self, entry):
|
|
|
|
new_value = entry.get('ipakrbauthzdata', [])
|
|
|
|
|
|
|
|
if not new_value:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not isinstance(new_value, (list, tuple)):
|
|
|
|
new_value = set([new_value])
|
|
|
|
else:
|
|
|
|
new_value = set(new_value)
|
|
|
|
|
|
|
|
if u'NONE' in new_value and len(new_value) > 1:
|
|
|
|
raise errors.ValidationError(name='ipakrbauthzdata',
|
|
|
|
error=_('NONE value cannot be combined with other PAC types'))
|
|
|
|
|
2014-08-20 08:34:34 -05:00
|
|
|
def get_dn(self, *keys, **kwargs):
|
2016-06-23 13:01:34 -05:00
|
|
|
key = keys[0]
|
2018-09-26 05:39:56 -05:00
|
|
|
if isinstance(key, str):
|
2016-06-23 13:01:34 -05:00
|
|
|
key = kerberos.Principal(key)
|
|
|
|
|
|
|
|
key = unicode(normalize_principal(key))
|
|
|
|
|
|
|
|
parent_dn = DN(self.container_dn, self.api.env.basedn)
|
|
|
|
true_rdn = 'krbprincipalname'
|
|
|
|
|
|
|
|
return self.backend.make_dn_from_attr(
|
|
|
|
true_rdn, key, parent_dn
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_primary_key_from_dn(self, dn):
|
|
|
|
"""
|
|
|
|
If the entry has krbcanonicalname set return the value of the
|
|
|
|
attribute. If the attribute is not found, assume old-style entry which
|
|
|
|
should have only single value of krbprincipalname and return it.
|
|
|
|
|
|
|
|
Otherwise return input DN.
|
|
|
|
"""
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
|
|
|
try:
|
|
|
|
entry_attrs = self.backend.get_entry(
|
|
|
|
dn, [self.primary_key.name]
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
return entry_attrs[self.primary_key.name][0]
|
|
|
|
except (KeyError, IndexError):
|
|
|
|
return ''
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
2016-08-09 07:09:24 -05:00
|
|
|
return dn['krbprincipalname']
|
2016-06-23 13:01:34 -05:00
|
|
|
except KeyError:
|
|
|
|
return unicode(dn)
|
|
|
|
|
|
|
|
def populate_krbcanonicalname(self, entry_attrs, options):
|
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
|
|
|
|
entry_attrs.setdefault(
|
|
|
|
'krbcanonicalname', entry_attrs['krbprincipalname'])
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_add(LDAPCreate):
|
2016-02-01 06:23:23 -06:00
|
|
|
__doc__ = _('Add a new IPA service.')
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2010-02-12 15:34:21 -06:00
|
|
|
msg_summary = _('Added service "%(value)s"')
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPCreate.has_output_params + output_params
|
2012-08-03 02:04:58 -05:00
|
|
|
takes_options = LDAPCreate.takes_options + (
|
2009-05-27 08:55:26 -05:00
|
|
|
Flag('force',
|
2018-04-26 03:08:33 -05:00
|
|
|
label=_('Force'),
|
|
|
|
doc=_('force principal name even if host not in DNS'),
|
2009-05-27 08:55:26 -05:00
|
|
|
),
|
2018-04-26 03:08:33 -05:00
|
|
|
Flag('skip_host_check',
|
|
|
|
label=_('Skip host check'),
|
|
|
|
doc=_('force service to be created even when host '
|
|
|
|
'object does not exist to manage it'),
|
|
|
|
),
|
2009-05-27 08:55:26 -05:00
|
|
|
)
|
2013-03-18 06:31:23 -05:00
|
|
|
|
2009-12-10 09:39:24 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = keys[-1]
|
|
|
|
hostname = principal.hostname
|
|
|
|
|
|
|
|
if principal.is_host and not options['force']:
|
2009-05-27 08:55:26 -05:00
|
|
|
raise errors.HostService()
|
|
|
|
|
2018-04-26 03:08:33 -05:00
|
|
|
if not options['skip_host_check']:
|
|
|
|
try:
|
|
|
|
hostresult = self.api.Command['host_show'](hostname)['result']
|
|
|
|
except errors.NotFound:
|
|
|
|
raise errors.NotFound(reason=_(
|
|
|
|
"The host '%s' does not exist to add a service to.") %
|
2018-04-26 03:32:19 -05:00
|
|
|
hostname)
|
2009-10-20 21:23:15 -05:00
|
|
|
|
2012-10-02 10:06:10 -05:00
|
|
|
self.obj.validate_ipakrbauthzdata(entry_attrs)
|
|
|
|
|
2010-07-22 13:16:22 -05:00
|
|
|
if not options.get('force', False):
|
2016-05-17 10:20:25 -05:00
|
|
|
# We know the host exists if we've gotten this far but we
|
|
|
|
# really want to discourage creating services for hosts that
|
|
|
|
# don't exist in DNS.
|
|
|
|
util.verify_host_resolvable(hostname)
|
2018-04-26 03:08:33 -05:00
|
|
|
if not (options['skip_host_check'] or 'managedby' in entry_attrs):
|
2012-08-01 09:14:11 -05:00
|
|
|
entry_attrs['managedby'] = hostresult['dn']
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2016-06-27 01:48:29 -05:00
|
|
|
# Enforce ipaKrbPrincipalAlias to aid case-insensitive searches
|
|
|
|
# as krbPrincipalName/krbCanonicalName are case-sensitive in Kerberos
|
|
|
|
# schema
|
|
|
|
entry_attrs['ipakrbprincipalalias'] = keys[-1]
|
|
|
|
|
|
|
|
# Objectclass ipakrbprincipal providing ipakrbprincipalalias is not in
|
|
|
|
# in a list of default objectclasses, add it manually
|
|
|
|
entry_attrs['objectclass'].append('ipakrbprincipal')
|
|
|
|
|
2015-09-08 10:43:30 -05:00
|
|
|
# set krbcanonicalname attribute to enable principal canonicalization
|
|
|
|
util.set_krbcanonicalname(entry_attrs)
|
2012-10-01 09:49:34 -05:00
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
update_krbticketflags(ldap, entry_attrs, attrs_list, options, False)
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2009-09-15 06:04:09 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_del(LDAPDelete):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Delete an IPA service.')
|
|
|
|
|
2010-02-12 15:34:21 -06:00
|
|
|
msg_summary = _('Deleted service "%(value)s"')
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2009-09-15 06:04:09 -05:00
|
|
|
def pre_callback(self, ldap, dn, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2012-02-22 16:42:38 -06:00
|
|
|
# In the case of services we don't want IPA master services to be
|
|
|
|
# deleted. This is a limited few though. If the user has their own
|
|
|
|
# custom services allow them to manage them.
|
2016-06-23 11:54:49 -05:00
|
|
|
check_required_principal(ldap, keys[-1])
|
2014-10-13 07:30:15 -05:00
|
|
|
if self.api.Command.ca_is_enabled()['result']:
|
2016-08-26 00:31:13 -05:00
|
|
|
certs = self.api.Command.cert_find(service=keys)['result']
|
|
|
|
revoke_certs(certs)
|
2015-06-23 06:40:30 -05:00
|
|
|
|
2009-09-15 06:04:09 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_mod(LDAPUpdate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify an existing IPA service.')
|
|
|
|
|
2010-08-05 21:41:32 -05:00
|
|
|
msg_summary = _('Modified service "%(value)s"')
|
Certificate management for services.
This is an initial implementation of certificate management for
services. It addresses the mechanism required to view and update
certificates. The complete UI implementation will be addressed in
subsequent patches.
On the server side, the service.py has been modified to define
usercertificate in the service object's takes_params. This is
needed to generate the proper JSON metadata which is needed by
the UI. It also has been modified to accept null certificate for
deletion.
On the client side, the service details page has been modified to
display the base64-encoded certificate in a text area. When the
page is saved, the action handler will store the base64-encoded
certificate in the proper JSON structure. Also the service name
and service hostname are now displayed in separate fields.
The details configuration has been modified to support displaying
and updating certificates. The structure is changed to use maps
to define sections and fields. A section contains name, label,
and an array of fields. A field contains name, label, setup
function, load function, and save function. This is used to
implement custom interface and behavior for certificates.
All other entities, test cases, and test data have been updated
accordingly. Some functions and variables have been renamed to
improve clarity and consistency.
2010-10-07 14:02:44 -05:00
|
|
|
takes_options = LDAPUpdate.takes_options
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPUpdate.has_output_params + output_params
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2012-10-02 10:06:10 -05:00
|
|
|
|
|
|
|
self.obj.validate_ipakrbauthzdata(entry_attrs)
|
|
|
|
|
2015-05-27 07:02:08 -05:00
|
|
|
# verify certificates
|
2015-06-03 01:49:28 -05:00
|
|
|
certs = entry_attrs.get('usercertificate') or []
|
2015-05-27 07:02:08 -05:00
|
|
|
# revoke removed certificates
|
2016-09-07 04:00:18 -05:00
|
|
|
ca_is_enabled = self.api.Command.ca_is_enabled()['result']
|
|
|
|
if 'usercertificate' in options and ca_is_enabled:
|
2015-06-03 06:11:58 -05:00
|
|
|
try:
|
|
|
|
entry_attrs_old = ldap.get_entry(dn, ['usercertificate'])
|
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(*keys)
|
2015-05-27 07:02:08 -05:00
|
|
|
old_certs = entry_attrs_old.get('usercertificate', [])
|
2017-07-03 10:10:34 -05:00
|
|
|
removed_certs = set(old_certs) - set(certs)
|
|
|
|
for cert in removed_certs:
|
|
|
|
rm_certs = api.Command.cert_find(
|
|
|
|
certificate=cert.public_bytes(x509.Encoding.DER))['result']
|
2016-08-26 00:31:13 -05:00
|
|
|
revoke_certs(rm_certs)
|
2015-06-23 06:40:30 -05:00
|
|
|
|
2015-06-03 06:11:58 -05:00
|
|
|
if certs:
|
2017-07-03 10:10:34 -05:00
|
|
|
entry_attrs['usercertificate'] = certs
|
2013-03-18 06:31:23 -05:00
|
|
|
|
|
|
|
update_krbticketflags(ldap, entry_attrs, attrs_list, options, True)
|
|
|
|
|
2009-09-15 06:04:09 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-11-05 14:16:53 -05:00
|
|
|
set_certificate_attrs(entry_attrs)
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
return dn
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_find(LDAPSearch):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Search for IPA services.')
|
|
|
|
|
2010-08-05 21:41:32 -05:00
|
|
|
msg_summary = ngettext(
|
2011-02-23 15:47:49 -06:00
|
|
|
'%(count)d service matched', '%(count)d services matched', 0
|
2010-08-05 21:41:32 -05:00
|
|
|
)
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2016-06-23 13:01:34 -05:00
|
|
|
sort_result_entries = False
|
|
|
|
|
Certificate management for services.
This is an initial implementation of certificate management for
services. It addresses the mechanism required to view and update
certificates. The complete UI implementation will be addressed in
subsequent patches.
On the server side, the service.py has been modified to define
usercertificate in the service object's takes_params. This is
needed to generate the proper JSON metadata which is needed by
the UI. It also has been modified to accept null certificate for
deletion.
On the client side, the service details page has been modified to
display the base64-encoded certificate in a text area. When the
page is saved, the action handler will store the base64-encoded
certificate in the proper JSON structure. Also the service name
and service hostname are now displayed in separate fields.
The details configuration has been modified to support displaying
and updating certificates. The structure is changed to use maps
to define sections and fields. A section contains name, label,
and an array of fields. A field contains name, label, setup
function, load function, and save function. This is used to
implement custom interface and behavior for certificates.
All other entities, test cases, and test data have been updated
accordingly. Some functions and variables have been renamed to
improve clarity and consistency.
2010-10-07 14:02:44 -05:00
|
|
|
takes_options = LDAPSearch.takes_options
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPSearch.has_output_params + output_params
|
2011-11-10 06:46:16 -06:00
|
|
|
|
2010-11-23 08:02:54 -06:00
|
|
|
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(base_dn, DN)
|
2009-05-27 08:55:26 -05:00
|
|
|
# lisp style!
|
|
|
|
custom_filter = '(&(objectclass=ipaService)' \
|
|
|
|
'(!(objectClass=posixAccount))' \
|
|
|
|
'(!(|(krbprincipalname=kadmin/*)' \
|
|
|
|
'(krbprincipalname=K/M@*)' \
|
|
|
|
'(krbprincipalname=krbtgt/*))' \
|
|
|
|
')' \
|
|
|
|
')'
|
2016-06-23 13:01:34 -05:00
|
|
|
if options.get('pkey_only', False):
|
|
|
|
attrs_list.append('krbprincipalname')
|
|
|
|
|
2010-11-23 08:02:54 -06:00
|
|
|
return (
|
|
|
|
ldap.combine_filters((custom_filter, filter), rules=ldap.MATCH_ALL),
|
|
|
|
base_dn, scope
|
2009-05-27 08:55:26 -05:00
|
|
|
)
|
|
|
|
|
2010-08-05 21:41:32 -05:00
|
|
|
def post_callback(self, ldap, entries, truncated, *args, **options):
|
2016-06-23 13:01:34 -05:00
|
|
|
# we have to sort entries manually instead of relying on inherited
|
|
|
|
# mechanisms
|
|
|
|
def sort_key(x):
|
|
|
|
if 'krbcanonicalname' in x:
|
|
|
|
return x['krbcanonicalname'][0]
|
|
|
|
else:
|
|
|
|
return x['krbprincipalname'][0]
|
|
|
|
|
|
|
|
entries.sort(key=sort_key)
|
|
|
|
|
2011-10-26 04:12:38 -05:00
|
|
|
if options.get('pkey_only', False):
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2013-10-31 11:54:21 -05:00
|
|
|
for entry_attrs in entries:
|
|
|
|
self.obj.get_password_attributes(ldap, entry_attrs.dn, entry_attrs)
|
2016-06-09 06:13:24 -05:00
|
|
|
principal = entry_attrs['krbprincipalname']
|
|
|
|
if isinstance(principal, (tuple, list)):
|
|
|
|
principal = principal[0]
|
|
|
|
try:
|
|
|
|
set_certificate_attrs(entry_attrs)
|
|
|
|
except errors.CertificateFormatError as e:
|
|
|
|
self.add_message(
|
|
|
|
messages.CertificateInvalid(
|
|
|
|
subject=principal,
|
|
|
|
reason=e
|
|
|
|
)
|
|
|
|
)
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.error("Invalid certificate: %s", e)
|
2016-06-09 06:13:24 -05:00
|
|
|
del(entry_attrs['usercertificate'])
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2010-08-05 21:41:32 -05:00
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_show(LDAPRetrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Display information about an IPA service.')
|
|
|
|
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-12-10 09:53:20 -06:00
|
|
|
takes_options = LDAPRetrieve.takes_options + (
|
|
|
|
Str('out?',
|
|
|
|
doc=_('file to store certificate in'),
|
|
|
|
),
|
|
|
|
)
|
2011-11-10 06:46:16 -06:00
|
|
|
has_output_params = LDAPRetrieve.has_output_params + output_params
|
2010-10-15 12:22:01 -05:00
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2011-08-22 15:24:07 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2016-06-09 06:13:24 -05:00
|
|
|
principal = entry_attrs['krbprincipalname']
|
|
|
|
if isinstance(principal, (tuple, list)):
|
|
|
|
principal = principal[0]
|
|
|
|
try:
|
|
|
|
set_certificate_attrs(entry_attrs)
|
|
|
|
except errors.CertificateFormatError as e:
|
|
|
|
self.add_message(
|
|
|
|
messages.CertificateInvalid(
|
|
|
|
subject=principal,
|
|
|
|
reason=e,
|
|
|
|
)
|
|
|
|
)
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.error("Invalid certificate: %s", e)
|
2016-06-09 06:13:24 -05:00
|
|
|
del(entry_attrs['usercertificate'])
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2010-10-15 12:22:01 -05:00
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-11-03 08:35:19 -06:00
|
|
|
class service_add_host(LDAPAddMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add hosts that can manage this service.')
|
|
|
|
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPAddMember.has_output_params + output_params
|
2009-11-03 08:35:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-11-03 08:35:19 -06:00
|
|
|
class service_remove_host(LDAPRemoveMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Remove hosts that can manage this service.')
|
|
|
|
|
2009-11-03 08:35:19 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + output_params
|
2009-11-03 08:35:19 -06:00
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2014-10-02 09:57:08 -05:00
|
|
|
@register()
|
|
|
|
class service_allow_retrieve_keytab(LDAPAddMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Allow users, groups, hosts or host groups to retrieve a keytab'
|
|
|
|
' of this service.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_read_keys']
|
|
|
|
has_output_params = LDAPAddMember.has_output_params + output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
add_missing_object_class(ldap, u'ipaallowedoperations', dn)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class service_disallow_retrieve_keytab(LDAPRemoveMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Disallow users, groups, hosts or host groups to retrieve a '
|
|
|
|
'keytab of this service.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_read_keys']
|
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class service_allow_create_keytab(LDAPAddMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Allow users, groups, hosts or host groups to create a keytab '
|
|
|
|
'of this service.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_write_keys']
|
|
|
|
has_output_params = LDAPAddMember.has_output_params + output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
add_missing_object_class(ldap, u'ipaallowedoperations', dn)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class service_disallow_create_keytab(LDAPRemoveMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Disallow users, groups, hosts or host groups to create a '
|
|
|
|
'keytab of this service.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_write_keys']
|
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
2016-06-23 13:01:34 -05:00
|
|
|
self.obj.populate_krbcanonicalname(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2010-07-12 16:45:06 -05:00
|
|
|
class service_disable(LDAPQuery):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Disable the Kerberos key and SSL certificate of a service.')
|
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
has_output = output.standard_value
|
2011-02-16 03:35:49 -06:00
|
|
|
msg_summary = _('Disabled service "%(value)s"')
|
2010-08-05 21:41:32 -05:00
|
|
|
has_output_params = LDAPQuery.has_output_params + output_params
|
2010-07-12 16:45:06 -05:00
|
|
|
|
|
|
|
def execute(self, *keys, **options):
|
|
|
|
ldap = self.obj.backend
|
|
|
|
|
|
|
|
dn = self.obj.get_dn(*keys, **options)
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = ldap.get_entry(dn, ['usercertificate'])
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2016-06-23 11:54:49 -05:00
|
|
|
check_required_principal(ldap, keys[-1])
|
2012-03-19 09:16:49 -05:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
# See if we do any work at all here and if not raise an exception
|
|
|
|
done_work = False
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2015-05-27 07:02:08 -05:00
|
|
|
if self.api.Command.ca_is_enabled()['result']:
|
2016-08-26 00:31:13 -05:00
|
|
|
certs = self.api.Command.cert_find(service=keys)['result']
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2015-05-27 07:02:08 -05:00
|
|
|
if len(certs) > 0:
|
2016-08-26 00:31:13 -05:00
|
|
|
revoke_certs(certs)
|
2015-05-27 07:02:08 -05:00
|
|
|
# Remove the usercertificate altogether
|
|
|
|
entry_attrs['usercertificate'] = None
|
|
|
|
ldap.update_entry(entry_attrs)
|
|
|
|
done_work = True
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2011-08-22 15:24:07 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
|
|
|
if entry_attrs['has_keytab']:
|
2010-11-05 14:16:53 -05:00
|
|
|
ldap.remove_principal_key(dn)
|
|
|
|
done_work = True
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
if not done_work:
|
|
|
|
raise errors.AlreadyInactive()
|
2010-07-12 16:45:06 -05:00
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=True,
|
2014-03-27 08:04:00 -05:00
|
|
|
value=pkey_to_value(keys[0], options),
|
2010-07-12 16:45:06 -05:00
|
|
|
)
|
|
|
|
|
2015-06-23 06:42:01 -05:00
|
|
|
|
|
|
|
@register()
|
2016-06-23 12:14:53 -05:00
|
|
|
class service_add_cert(LDAPAddAttributeViaOption):
|
2015-06-23 06:42:01 -05:00
|
|
|
__doc__ = _('Add new certificates to a service')
|
|
|
|
msg_summary = _('Added certificates to service principal "%(value)s"')
|
|
|
|
attribute = 'usercertificate'
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2016-06-23 12:14:53 -05:00
|
|
|
class service_remove_cert(LDAPRemoveAttributeViaOption):
|
2015-06-23 06:42:01 -05:00
|
|
|
__doc__ = _('Remove certificates from a service')
|
|
|
|
msg_summary = _('Removed certificates from service principal "%(value)s"')
|
|
|
|
attribute = 'usercertificate'
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2016-08-26 00:31:13 -05:00
|
|
|
for cert in options.get('usercertificate', []):
|
2017-08-23 08:23:43 -05:00
|
|
|
revoke_certs(api.Command.cert_find(certificate=cert)['result'])
|
2015-06-23 06:42:01 -05:00
|
|
|
|
|
|
|
return dn
|
2016-06-23 13:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class service_add_principal(LDAPAddAttribute):
|
|
|
|
__doc__ = _('Add new principal alias to a service')
|
|
|
|
msg_summary = _('Added new aliases to the service principal "%(value)s"')
|
|
|
|
attribute = 'krbprincipalname'
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
|
|
|
util.check_principal_realm_in_trust_namespace(self.api, *keys)
|
|
|
|
util.ensure_krbcanonicalname_set(ldap, entry_attrs)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class service_remove_principal(LDAPRemoveAttribute):
|
|
|
|
__doc__ = _('Remove principal alias from a service')
|
|
|
|
msg_summary = _('Removed aliases to the service principal "%(value)s"')
|
|
|
|
attribute = 'krbprincipalname'
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
|
|
|
util.ensure_last_krbprincipalname(ldap, entry_attrs, *keys)
|
|
|
|
return dn
|