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/>.
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
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:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa service-add-host --hosts=web.example.com HTTP/web.example.com
|
2010-12-01 10:23:52 -06:00
|
|
|
ipa role-add-member --hosts=web.example.com certadmin
|
2010-06-02 13:08:50 -05:00
|
|
|
|
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
|
|
|
|
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
|
|
|
import base64
|
2010-12-10 09:53:20 -06:00
|
|
|
import os
|
2009-05-27 08:55:26 -05:00
|
|
|
|
2010-07-22 13:16:22 -05:00
|
|
|
from ipalib import api, errors, util
|
2009-05-27 08:55:26 -05:00
|
|
|
from ipalib import Str, Flag, Bytes
|
2009-09-15 06:04:09 -05:00
|
|
|
from ipalib.plugins.baseldap import *
|
2009-11-24 15:07:44 -06:00
|
|
|
from ipalib import x509
|
2010-02-01 13:00:28 -06:00
|
|
|
from ipalib import _, ngettext
|
2010-10-08 12:15:03 -05:00
|
|
|
from ipalib import util
|
2010-10-15 12:22:01 -05:00
|
|
|
import nss.nss as nss
|
2010-08-05 21:41:32 -05:00
|
|
|
from nss.error import NSPRError
|
2010-12-10 09:53:20 -06:00
|
|
|
from ipapython.ipautil import file_exists
|
2009-05-27 08:55:26 -05:00
|
|
|
|
|
|
|
|
2010-08-05 21:41:32 -05:00
|
|
|
output_params = (
|
|
|
|
Flag('has_keytab',
|
|
|
|
label=_('Keytab'),
|
|
|
|
),
|
|
|
|
Str('managedby_host',
|
|
|
|
label='Managed by',
|
|
|
|
),
|
2010-11-05 14:16:53 -05:00
|
|
|
Str('subject',
|
|
|
|
label=_('Subject'),
|
|
|
|
),
|
|
|
|
Str('serial_number',
|
|
|
|
label=_('Serial Number'),
|
|
|
|
),
|
|
|
|
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
|
|
|
)
|
|
|
|
|
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:
|
|
|
|
raise errors.MalformedServicePrincipal(reason='missing service')
|
|
|
|
|
|
|
|
service = sp[0]
|
2011-02-15 11:37:25 -06:00
|
|
|
if len(service) == 0:
|
|
|
|
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(
|
|
|
|
reason='unable to determine realm'
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
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])
|
|
|
|
|
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',
|
|
|
|
'ipaservice', 'pkiuser'
|
|
|
|
]
|
2010-07-12 16:45:06 -05:00
|
|
|
search_attributes = ['krbprincipalname', 'managedby']
|
|
|
|
default_attributes = ['krbprincipalname', 'usercertificate', 'managedby', 'krblastpwdchange']
|
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_'),
|
|
|
|
}
|
2009-09-15 06:04:09 -05:00
|
|
|
|
2010-02-08 06:03:28 -06:00
|
|
|
label = _('Services')
|
2011-06-23 19:48:50 -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',],
|
2010-10-15 12:22:01 -05:00
|
|
|
)
|
2009-05-27 08:55:26 -05:00
|
|
|
)
|
|
|
|
|
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):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new IPA new service.
|
2009-05-27 08:55:26 -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
|
2009-05-27 08:55:26 -05:00
|
|
|
takes_options = (
|
|
|
|
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
|
|
|
),
|
|
|
|
)
|
2009-12-10 09:39:24 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
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:
|
|
|
|
raise errors.NotFound(reason="The host '%s' does not exist to add a service to." % hostname)
|
|
|
|
|
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:
|
|
|
|
entry_attrs['managedby'] = hostresult['dn']
|
2009-05-27 08:55:26 -05:00
|
|
|
|
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):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
2010-08-24 22:40:32 -05:00
|
|
|
Delete an IPA service.
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
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):
|
|
|
|
if self.api.env.enable_ra:
|
|
|
|
(dn, entry_attrs) = ldap.get_entry(dn, ['usercertificate'])
|
|
|
|
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):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
2010-08-24 22:40:32 -05:00
|
|
|
Modify an existing IPA service.
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
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
|
|
|
|
2009-09-15 06:04:09 -05:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
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)
|
2010-07-22 15:08:17 -05:00
|
|
|
(dn, entry_attrs_old) = ldap.get_entry(dn, ['usercertificate'])
|
|
|
|
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
|
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):
|
|
|
|
set_certificate_attrs(entry_attrs)
|
|
|
|
|
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):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
2010-08-24 22:40:32 -05:00
|
|
|
Search for IPA services.
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
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
|
2010-11-23 08:02:54 -06:00
|
|
|
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options):
|
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):
|
|
|
|
for entry in entries:
|
|
|
|
entry_attrs = entry[1]
|
|
|
|
if 'krblastpwdchange' in entry_attrs:
|
|
|
|
entry_attrs['has_keytab'] = True
|
|
|
|
if not options.get('all', False):
|
|
|
|
del entry_attrs['krblastpwdchange']
|
|
|
|
else:
|
|
|
|
entry_attrs['has_keytab'] = False
|
2010-11-05 14:16:53 -05:00
|
|
|
set_certificate_attrs(entry_attrs)
|
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):
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
2010-08-24 22:40:32 -05:00
|
|
|
Display information about an IPA service.
|
2009-05-27 08:55:26 -05:00
|
|
|
"""
|
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'),
|
|
|
|
),
|
|
|
|
)
|
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):
|
|
|
|
if 'krblastpwdchange' in entry_attrs:
|
|
|
|
entry_attrs['has_keytab'] = True
|
|
|
|
if not options.get('all', False):
|
|
|
|
del entry_attrs['krblastpwdchange']
|
|
|
|
else:
|
|
|
|
entry_attrs['has_keytab'] = False
|
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
set_certificate_attrs(entry_attrs)
|
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):
|
|
|
|
"""
|
2009-11-24 15:07:44 -06:00
|
|
|
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):
|
|
|
|
"""
|
2009-11-24 15:07:44 -06:00
|
|
|
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-02-16 03:35:49 -06:00
|
|
|
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)
|
2010-11-05 14:16:53 -05:00
|
|
|
(dn, entry_attrs) = ldap.get_entry(dn, ['krblastpwdchange', 'usercertificate'])
|
|
|
|
|
|
|
|
# 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:
|
2011-06-08 09:54:41 -05:00
|
|
|
cert = x509.normalize_certificate(entry_attrs.get('usercertificate')[0])
|
2010-11-05 14:16:53 -05:00
|
|
|
try:
|
|
|
|
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
|
|
|
|
|
|
|
|
# Remove the usercertificate altogether
|
|
|
|
ldap.update_entry(dn, {'usercertificate': None})
|
|
|
|
done_work = True
|
|
|
|
|
|
|
|
if 'krblastpwdchange' in entry_attrs:
|
|
|
|
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)
|