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
|
|
|
|
|
|
|
import base64
|
|
|
|
import os
|
|
|
|
|
|
|
|
from ipalib import api, errors, util
|
2013-03-18 06:31:23 -05:00
|
|
|
from ipalib import Str, Flag, Bytes, StrEnum, Bool
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib.plugins.baseldap import *
|
|
|
|
from ipalib import x509
|
|
|
|
from ipalib import _, ngettext
|
|
|
|
from ipalib import util
|
|
|
|
import nss.nss as nss
|
|
|
|
from nss.error import NSPRError
|
|
|
|
from ipapython.ipautil import file_exists
|
|
|
|
|
|
|
|
__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
|
|
|
|
|
|
|
|
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
|
|
|
|
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',
|
|
|
|
),
|
2010-11-05 14:16:53 -05:00
|
|
|
Str('subject',
|
|
|
|
label=_('Subject'),
|
|
|
|
),
|
|
|
|
Str('serial_number',
|
|
|
|
label=_('Serial Number'),
|
|
|
|
),
|
2012-03-06 14:53:07 -06:00
|
|
|
Str('serial_number_hex',
|
|
|
|
label=_('Serial Number (hex)'),
|
|
|
|
),
|
2010-11-05 14:16:53 -05:00
|
|
|
Str('issuer',
|
|
|
|
label=_('Issuer'),
|
|
|
|
),
|
|
|
|
Str('valid_not_before',
|
|
|
|
label=_('Not Before'),
|
|
|
|
),
|
|
|
|
Str('valid_not_after',
|
|
|
|
label=_('Not After'),
|
|
|
|
),
|
|
|
|
Str('md5_fingerprint',
|
|
|
|
label=_('Fingerprint (MD5)'),
|
|
|
|
),
|
|
|
|
Str('sha1_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA1)'),
|
|
|
|
),
|
|
|
|
Str('revocation_reason?',
|
|
|
|
label=_('Revocation reason'),
|
|
|
|
)
|
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'],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
_ticket_flags_map = {
|
|
|
|
'ipakrbrequirespreauth': 0x00000080,
|
|
|
|
'ipakrbokasdelegate': 0x00100000,
|
|
|
|
}
|
|
|
|
|
|
|
|
_ticket_flags_default = _ticket_flags_map['ipakrbrequirespreauth']
|
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
def split_principal(principal):
|
|
|
|
service = hostname = realm = None
|
|
|
|
|
|
|
|
# Break down the principal into its component parts, which may or
|
|
|
|
# may not include the realm.
|
|
|
|
sp = principal.split('/')
|
|
|
|
if len(sp) != 2:
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.MalformedServicePrincipal(reason=_('missing service'))
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
service = sp[0]
|
2011-02-15 11:37:25 -06:00
|
|
|
if len(service) == 0:
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.MalformedServicePrincipal(reason=_('blank service'))
|
2009-05-27 08:55:26 -05:00
|
|
|
sr = sp[1].split('@')
|
|
|
|
if len(sr) > 2:
|
|
|
|
raise errors.MalformedServicePrincipal(
|
2012-07-04 07:52:47 -05:00
|
|
|
reason=_('unable to determine realm'))
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
hostname = sr[0].lower()
|
|
|
|
if len(sr) == 2:
|
|
|
|
realm = sr[1].upper()
|
|
|
|
# At some point we'll support multiple realms
|
|
|
|
if realm != api.env.realm:
|
|
|
|
raise errors.RealmMismatch()
|
|
|
|
else:
|
|
|
|
realm = api.env.realm
|
|
|
|
|
|
|
|
# Note that realm may be None.
|
|
|
|
return (service, hostname, realm)
|
|
|
|
|
|
|
|
def validate_principal(ugettext, principal):
|
|
|
|
(service, hostname, principal) = split_principal(principal)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def normalize_principal(principal):
|
|
|
|
# The principal is already validated when it gets here
|
|
|
|
(service, hostname, realm) = split_principal(principal)
|
|
|
|
# Put the principal back together again
|
|
|
|
principal = '%s/%s@%s' % (service, hostname, realm)
|
|
|
|
return unicode(principal)
|
|
|
|
|
|
|
|
def validate_certificate(ugettext, cert):
|
|
|
|
"""
|
|
|
|
For now just verify that it is properly base64-encoded.
|
|
|
|
"""
|
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
|
|
|
if cert and util.isvalid_base64(cert):
|
2010-10-08 12:15:03 -05:00
|
|
|
try:
|
|
|
|
base64.b64decode(cert)
|
|
|
|
except Exception, e:
|
|
|
|
raise errors.Base64DecodeError(reason=str(e))
|
|
|
|
else:
|
|
|
|
# We'll assume this is DER data
|
|
|
|
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']
|
2011-06-08 09:54:41 -05:00
|
|
|
cert = x509.normalize_certificate(cert)
|
2010-11-05 14:16:53 -05:00
|
|
|
cert = x509.load_certificate(cert, datatype=x509.DER)
|
|
|
|
entry_attrs['subject'] = unicode(cert.subject)
|
|
|
|
entry_attrs['serial_number'] = unicode(cert.serial_number)
|
2012-03-06 14:53:07 -06:00
|
|
|
entry_attrs['serial_number_hex'] = u'0x%X' % cert.serial_number
|
2010-11-05 14:16:53 -05:00
|
|
|
entry_attrs['issuer'] = unicode(cert.issuer)
|
|
|
|
entry_attrs['valid_not_before'] = unicode(cert.valid_not_before_str)
|
|
|
|
entry_attrs['valid_not_after'] = unicode(cert.valid_not_after_str)
|
|
|
|
entry_attrs['md5_fingerprint'] = unicode(nss.data_to_hex(nss.md5_digest(cert.der_data), 64)[0])
|
|
|
|
entry_attrs['sha1_fingerprint'] = unicode(nss.data_to_hex(nss.sha1_digest(cert.der_data), 64)[0])
|
|
|
|
|
2012-03-19 09:16:49 -05:00
|
|
|
def check_required_principal(ldap, hostname, service):
|
|
|
|
"""
|
|
|
|
Raise an error if the host of this prinicipal is an IPA master and one
|
|
|
|
of the principals required for proper execution.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
host_is_master(ldap, hostname)
|
|
|
|
except errors.ValidationError, e:
|
2012-04-05 10:28:43 -05:00
|
|
|
service_types = ['HTTP', 'ldap', 'DNS', 'dogtagldap']
|
2012-03-19 09:16:49 -05:00
|
|
|
if service in service_types:
|
|
|
|
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
|
|
|
|
|
|
|
|
for (name, value) in _ticket_flags_map.iteritems():
|
|
|
|
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)
|
|
|
|
|
|
|
|
for (name, value) in _ticket_flags_map.iteritems():
|
|
|
|
if name in options or all_opt:
|
|
|
|
entry_attrs[name] = bool(ticket_flags & value)
|
|
|
|
|
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
|
|
|
]
|
2012-10-01 09:49:34 -05:00
|
|
|
possible_objectclasses = ['ipakrbprincipal']
|
2014-01-09 07:43:37 -06:00
|
|
|
permission_filter_objectclasses = ['ipaservice']
|
2012-08-01 09:14:11 -05:00
|
|
|
search_attributes = ['krbprincipalname', 'managedby', 'ipakrbauthzdata']
|
|
|
|
default_attributes = ['krbprincipalname', 'usercertificate', 'managedby',
|
|
|
|
'ipakrbauthzdata',]
|
2009-09-15 06:04:09 -05:00
|
|
|
uuid_attribute = 'ipauniqueid'
|
2009-11-03 08:35:19 -06:00
|
|
|
attribute_members = {
|
|
|
|
'managedby': ['host'],
|
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_'),
|
|
|
|
}
|
2011-08-22 15:24:07 -05:00
|
|
|
password_attributes = [('krbprincipalkey', 'has_keytab')]
|
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 = (
|
|
|
|
Str('krbprincipalname', validate_principal,
|
|
|
|
cli_name='principal',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Principal'),
|
|
|
|
doc=_('Service principal'),
|
2009-05-27 08:55:26 -05:00
|
|
|
primary_key=True,
|
|
|
|
normalizer=lambda value: normalize_principal(value),
|
|
|
|
),
|
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
|
|
|
Bytes('usercertificate?', validate_certificate,
|
|
|
|
cli_name='certificate',
|
|
|
|
label=_('Certificate'),
|
|
|
|
doc=_('Base-64 encoded server certificate'),
|
2011-02-09 12:24:47 -06:00
|
|
|
flags=['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
|
|
|
csv=True,
|
|
|
|
),
|
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'))
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(service)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
2009-09-15 06:04:09 -05:00
|
|
|
class service_add(LDAPCreate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add a new IPA new service.')
|
|
|
|
|
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',
|
2011-02-18 00:02:51 -06:00
|
|
|
label=_('Force'),
|
2010-03-05 15:11:21 -06:00
|
|
|
doc=_('force principal name even if not in DNS'),
|
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)
|
2009-09-15 06:04:09 -05:00
|
|
|
(service, hostname, realm) = split_principal(keys[-1])
|
|
|
|
if service.lower() == 'host' and not options['force']:
|
2009-05-27 08:55:26 -05:00
|
|
|
raise errors.HostService()
|
|
|
|
|
2009-10-20 21:23:15 -05:00
|
|
|
try:
|
2010-08-05 21:41:32 -05:00
|
|
|
hostresult = api.Command['host_show'](hostname)['result']
|
2009-10-20 21:23:15 -05:00
|
|
|
except errors.NotFound:
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.NotFound(
|
|
|
|
reason=_("The host '%s' does not exist to add a service to.") %
|
|
|
|
hostname)
|
2009-10-20 21:23:15 -05:00
|
|
|
|
2012-10-02 10:06:10 -05:00
|
|
|
self.obj.validate_ipakrbauthzdata(entry_attrs)
|
|
|
|
|
2010-10-08 12:15:03 -05:00
|
|
|
cert = options.get('usercertificate')
|
2009-09-15 06:04:09 -05:00
|
|
|
if cert:
|
2011-06-08 09:54:41 -05:00
|
|
|
dercert = x509.normalize_certificate(cert)
|
|
|
|
x509.verify_cert_subject(ldap, hostname, dercert)
|
|
|
|
entry_attrs['usercertificate'] = dercert
|
2009-09-15 06:04:09 -05:00
|
|
|
|
2010-07-22 13:16:22 -05:00
|
|
|
if not options.get('force', False):
|
|
|
|
# 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.validate_host_dns(self.log, hostname)
|
2010-08-05 21:41:32 -05:00
|
|
|
if not '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
|
|
|
|
2012-03-26 06:23:42 -05:00
|
|
|
# Enforce ipaKrbPrincipalAlias to aid case-insensitive searches
|
|
|
|
# as krbPrincipalName/krbCanonicalName are case-sensitive in Kerberos
|
|
|
|
# schema
|
|
|
|
entry_attrs['ipakrbprincipalalias'] = keys[-1]
|
|
|
|
|
2012-10-01 09:49:34 -05:00
|
|
|
# Objectclass ipakrbprincipal providing ipakrbprincipalalias is not in
|
|
|
|
# in a list of default objectclasses, add it manually
|
|
|
|
entry_attrs['objectclass'].append('ipakrbprincipal')
|
|
|
|
|
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)
|
2009-09-15 06:04:09 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2009-06-16 09:51:44 -05:00
|
|
|
api.register(service_add)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
(service, hostname, realm) = split_principal(keys[-1])
|
2012-03-19 09:16:49 -05:00
|
|
|
check_required_principal(ldap, hostname, service)
|
2009-09-15 06:04:09 -05:00
|
|
|
if self.api.env.enable_ra:
|
2012-07-04 07:52:47 -05:00
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = ldap.get_entry(dn, ['usercertificate'])
|
2012-07-04 07:52:47 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
2009-09-15 06:04:09 -05:00
|
|
|
cert = entry_attrs.get('usercertificate')
|
|
|
|
if cert:
|
2010-06-24 10:40:02 -05:00
|
|
|
cert = cert[0]
|
2009-12-01 16:17:15 -06:00
|
|
|
try:
|
2010-08-05 21:41:32 -05:00
|
|
|
serial = unicode(x509.get_serial_number(cert, x509.DER))
|
|
|
|
try:
|
|
|
|
result = api.Command['cert_show'](unicode(serial))['result']
|
|
|
|
if 'revocation_reason' not in result:
|
|
|
|
try:
|
|
|
|
api.Command['cert_revoke'](unicode(serial), revocation_reason=4)
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
|
|
|
except NSPRError, nsprerr:
|
|
|
|
if nsprerr.errno == -8183:
|
|
|
|
# If we can't decode the cert them proceed with
|
|
|
|
# removing the service.
|
|
|
|
self.log.info("Problem decoding certificate %s" % nsprerr.args[1])
|
|
|
|
else:
|
|
|
|
raise nsprerr
|
2009-09-15 06:04:09 -05:00
|
|
|
return dn
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2009-06-16 09:51:44 -05:00
|
|
|
api.register(service_del)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2010-07-22 15:08:17 -05:00
|
|
|
if 'usercertificate' in options:
|
2011-04-26 15:45:19 -05:00
|
|
|
(service, hostname, realm) = split_principal(keys[-1])
|
2010-07-22 15:08:17 -05:00
|
|
|
cert = options.get('usercertificate')
|
|
|
|
if cert:
|
2011-06-08 09:54:41 -05:00
|
|
|
dercert = x509.normalize_certificate(cert)
|
|
|
|
x509.verify_cert_subject(ldap, hostname, dercert)
|
2012-07-04 07:52:47 -05:00
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs_old = ldap.get_entry(dn, ['usercertificate'])
|
2012-07-04 07:52:47 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
2010-07-22 15:08:17 -05:00
|
|
|
if 'usercertificate' in entry_attrs_old:
|
|
|
|
# FIXME: what to do here? do we revoke the old cert?
|
|
|
|
fmt = 'entry already has a certificate, serial number: %s' % (
|
|
|
|
x509.get_serial_number(entry_attrs_old['usercertificate'][0], x509.DER)
|
|
|
|
)
|
|
|
|
raise errors.GenericError(format=fmt)
|
2011-06-08 09:54:41 -05:00
|
|
|
entry_attrs['usercertificate'] = dercert
|
2010-07-22 15:08:17 -05:00
|
|
|
else:
|
|
|
|
entry_attrs['usercertificate'] = None
|
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)
|
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-06-16 07:38:27 -05:00
|
|
|
api.register(service_mod)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
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']
|
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/*))' \
|
|
|
|
')' \
|
|
|
|
')'
|
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):
|
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)
|
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)
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2010-08-05 21:41:32 -05:00
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(service_find)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
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
|
|
|
|
2010-12-10 09:53:20 -06:00
|
|
|
def forward(self, *keys, **options):
|
|
|
|
if 'out' in options:
|
2011-06-08 09:54:41 -05:00
|
|
|
util.check_writable_file(options['out'])
|
2010-12-10 09:53:20 -06:00
|
|
|
result = super(service_show, self).forward(*keys, **options)
|
|
|
|
if 'usercertificate' in result['result']:
|
2011-06-08 09:54:41 -05:00
|
|
|
x509.write_certificate(result['result']['usercertificate'][0], options['out'])
|
2010-12-10 09:53:20 -06:00
|
|
|
result['summary'] = _('Certificate stored in file \'%(file)s\'') % dict(file=options['out'])
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
raise errors.NoCertificateError(entry=keys[-1])
|
|
|
|
else:
|
|
|
|
return super(service_show, self).forward(*keys, **options)
|
|
|
|
|
2009-06-16 07:38:27 -05:00
|
|
|
api.register(service_show)
|
2009-05-27 08:55:26 -05:00
|
|
|
|
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
|
|
|
|
|
|
|
api.register(service_add_host)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
api.register(service_remove_host)
|
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
|
|
|
|
2012-03-19 09:16:49 -05:00
|
|
|
(service, hostname, realm) = split_principal(keys[-1])
|
|
|
|
check_required_principal(ldap, hostname, service)
|
|
|
|
|
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
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
if 'usercertificate' in entry_attrs:
|
2013-08-29 01:44:43 -05:00
|
|
|
if self.api.env.enable_ra:
|
|
|
|
cert = x509.normalize_certificate(entry_attrs.get('usercertificate')[0])
|
2010-11-05 14:16:53 -05:00
|
|
|
try:
|
2013-08-29 01:44:43 -05:00
|
|
|
serial = unicode(x509.get_serial_number(cert, x509.DER))
|
|
|
|
try:
|
|
|
|
result = api.Command['cert_show'](unicode(serial))['result']
|
|
|
|
if 'revocation_reason' not in result:
|
|
|
|
try:
|
|
|
|
api.Command['cert_revoke'](unicode(serial), revocation_reason=4)
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
|
|
|
except errors.NotImplementedError:
|
|
|
|
# some CA's might not implement revoke
|
|
|
|
pass
|
|
|
|
except NSPRError, nsprerr:
|
|
|
|
if nsprerr.errno == -8183:
|
|
|
|
# If we can't decode the cert them proceed with
|
|
|
|
# disabling the service
|
|
|
|
self.log.info("Problem decoding certificate %s" % nsprerr.args[1])
|
|
|
|
else:
|
|
|
|
raise nsprerr
|
2010-11-05 14:16:53 -05:00
|
|
|
|
|
|
|
# Remove the usercertificate altogether
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs['usercertificate'] = None
|
|
|
|
ldap.update_entry(entry_attrs)
|
2010-11-05 14:16:53 -05:00
|
|
|
done_work = True
|
|
|
|
|
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,
|
|
|
|
value=keys[0],
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(service_disable)
|