mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Since November 2020, Active Directory KDC generates a new type of signature as part of the PAC. It is called "ticket signature", and is generated based on the encrypted part of the ticket. The presence of this signature is not mandatory in order for the PAC to be accepted for S4U requests. However, the behavior is different for MIT krb5. Support was added as part of the 1.20 release, and this signature is required in order to process S4U requests. Contrary to the PAC extended KDC signature, the code generating this signature cannot be isolated and backported to older krb5 versions because this version of the KDB API does not allow passing the content of the ticket's encrypted part to IPA. This is an issue in gradual upgrade scenarios where some IPA servers rely on 1.19 and older versions of MIT krb5, while others use version 1.20 or newer. A service ticket that was provided by 1.19- IPA KDC will be rejected when used by a service against a 1.20+ IPA KDC for S4U requests. On Fedora, CentOS 9 Stream, and RHEL 9, when the krb5 version is 1.20 or newer, it will include a downstream-only update adding the "optional_pac_tkt_chksum" KDB string attribute allowing to tolerate the absence of PAC ticket signatures, if necessary. This commit adds an extra step during the installation and update processes where it adds a "pacTktSignSupported" ipaConfigString attribute in "cn=KDC,cn=[server],cn=masters,cn=ipa,cn=etc,[basedn]" if the MIT krb5 version IPA what built with was 1.20 or newer. This commit also set "optional_pac_tkt_chksum" as a virtual KDB entry attribute. This means the value of the attribute is not actually stored in the database (to avoid race conditions), but its value is determined at the KDC starting time by search the "pacTktSignSupported" ipaConfigString in the server list. If this value is missing for at least of them is missing, enforcement of the PAC ticket signature is disabled by setting "optional_pac_tkt_chksum" to true for the local realm TGS KDB entry. For foreign realm TGS KDB entries, the "optional_pac_tkt_chksum" virtual string attribute is set to true systematically, because, at least for now, trusted AD domains can still have PAC ticket signature support disabled. Given the fact the "pacTktSignSupported" ipaConfigString for a single server is added when this server is updated, and that the value of "optional_pac_tkt_chksum" is determined at KDC starting time based on the ipaConfigString attributes of all the KDCs in the domain, this requires to restart all the KDCs in the domain after all IPA servers were updated in order for PAC ticket signature enforcement to actually take effect. Fixes: https://pagure.io/freeipa/issue/9371 Signed-off-by: Julien Rische <jrische@redhat.com> Reviewed-By: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
200 lines
6.0 KiB
Python
200 lines
6.0 KiB
Python
#
|
|
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
|
|
#
|
|
"""Helpers services in for cn=masters,cn=ipa,cn=etc
|
|
"""
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import collections
|
|
import logging
|
|
import random
|
|
|
|
from ipapython.dn import DN
|
|
from ipalib import api
|
|
from ipalib import errors
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# constants for ipaConfigString
|
|
CONFIGURED_SERVICE = u'configuredService'
|
|
ENABLED_SERVICE = u'enabledService'
|
|
HIDDEN_SERVICE = u'hiddenService'
|
|
PAC_TKT_SIGN_SUPPORTED = u'pacTktSignSupported'
|
|
PKINIT_ENABLED = u'pkinitEnabled'
|
|
|
|
# The service name as stored in cn=masters,cn=ipa,cn=etc. The values are:
|
|
# 0: systemd service name
|
|
# 1: start order for system service
|
|
# 2: LDAP server entry CN, also used as SERVICE_LIST key
|
|
service_definition = collections.namedtuple(
|
|
"service_definition",
|
|
"systemd_name startorder service_entry"
|
|
)
|
|
|
|
SERVICES = [
|
|
service_definition('krb5kdc', 10, 'KDC'),
|
|
service_definition('kadmin', 20, 'KPASSWD'),
|
|
service_definition('named', 30, 'DNS'),
|
|
service_definition('httpd', 40, 'HTTP'),
|
|
service_definition('ipa-custodia', 41, 'KEYS'),
|
|
service_definition('pki-tomcatd', 50, 'CA'),
|
|
service_definition('pki-tomcatd', 51, 'KRA'),
|
|
service_definition('smb', 60, 'ADTRUST'),
|
|
service_definition('winbind', 70, 'EXTID'),
|
|
service_definition('ipa-otpd', 80, 'OTPD'),
|
|
service_definition('ipa-ods-exporter', 90, 'DNSKeyExporter'),
|
|
service_definition('ods-enforcerd', 100, 'DNSSEC'),
|
|
service_definition('ipa-dnskeysyncd', 110, 'DNSKeySync'),
|
|
]
|
|
|
|
SERVICE_LIST = {s.service_entry: s for s in SERVICES}
|
|
|
|
|
|
def find_providing_servers(svcname, conn=None, preferred_hosts=(), api=api):
|
|
"""Find servers that provide the given service.
|
|
|
|
:param svcname: The service to find
|
|
:param preferred_hosts: preferred servers
|
|
:param conn: a connection to the LDAP server
|
|
:param api: ipalib.API instance
|
|
:return: list of host names in randomized order (possibly empty)
|
|
|
|
Preferred servers are moved to the front of the list if and only if they
|
|
are found as providing servers.
|
|
"""
|
|
assert isinstance(preferred_hosts, (tuple, list))
|
|
if svcname not in SERVICE_LIST:
|
|
raise ValueError("Unknown service '{}'.".format(svcname))
|
|
if conn is None:
|
|
conn = api.Backend.ldap2
|
|
|
|
dn = DN(api.env.container_masters, api.env.basedn)
|
|
|
|
query_filter = conn.combine_filters(
|
|
[
|
|
conn.make_filter(
|
|
{
|
|
'objectClass': 'ipaConfigObject',
|
|
'cn': svcname
|
|
},
|
|
rules=conn.MATCH_ALL,
|
|
),
|
|
conn.make_filter(
|
|
{
|
|
'ipaConfigString': [ENABLED_SERVICE, HIDDEN_SERVICE]
|
|
},
|
|
rules=conn.MATCH_ANY
|
|
),
|
|
],
|
|
rules=conn.MATCH_ALL
|
|
)
|
|
|
|
try:
|
|
entries, _trunc = conn.find_entries(
|
|
filter=query_filter,
|
|
attrs_list=['ipaConfigString'],
|
|
base_dn=dn
|
|
)
|
|
except errors.NotFound:
|
|
return []
|
|
|
|
# DNS is case insensitive
|
|
preferred_hosts = list(host_name.lower() for host_name in preferred_hosts)
|
|
servers = []
|
|
for entry in entries:
|
|
servername = entry.dn[1].value.lower()
|
|
cfgstrings = entry.get('ipaConfigString', [])
|
|
# always consider enabled services
|
|
if ENABLED_SERVICE in cfgstrings:
|
|
servers.append(servername)
|
|
# use hidden services on preferred hosts
|
|
elif HIDDEN_SERVICE in cfgstrings and servername in preferred_hosts:
|
|
servers.append(servername)
|
|
# unique list of host names
|
|
servers = list(set(servers))
|
|
# shuffle the list like DNS SRV would randomize it
|
|
random.shuffle(servers)
|
|
# Move preferred hosts to front
|
|
for host_name in reversed(preferred_hosts):
|
|
try:
|
|
servers.remove(host_name)
|
|
except ValueError:
|
|
# preferred server not found, log and ignore
|
|
logger.warning(
|
|
"Lookup failed: Preferred host %s does not provide %s.",
|
|
host_name, svcname
|
|
)
|
|
else:
|
|
servers.insert(0, host_name)
|
|
return servers
|
|
|
|
|
|
def find_providing_server(svcname, conn=None, preferred_hosts=(), api=api):
|
|
"""Find a server that provides the given service.
|
|
|
|
:param svcname: The service to find
|
|
:param conn: a connection to the LDAP server
|
|
:param host_name: the preferred server
|
|
:param api: ipalib.API instance
|
|
:return: the selected host name or None
|
|
"""
|
|
servers = find_providing_servers(
|
|
svcname, conn=conn, preferred_hosts=preferred_hosts, api=api
|
|
)
|
|
if not servers:
|
|
return None
|
|
else:
|
|
return servers[0]
|
|
|
|
|
|
def get_masters(conn=None, api=api):
|
|
"""Get all master hostnames
|
|
|
|
:param conn: a connection to the LDAP server
|
|
:param api: ipalib.API instance
|
|
:return: list of hostnames
|
|
"""
|
|
if conn is None:
|
|
conn = api.Backend.ldap2
|
|
|
|
dn = DN(api.env.container_masters, api.env.basedn)
|
|
entries = conn.get_entries(dn, conn.SCOPE_ONELEVEL, None, ['cn'])
|
|
return list(e['cn'][0] for e in entries)
|
|
|
|
|
|
def is_service_enabled(svcname, conn=None, api=api):
|
|
"""Check if service is enabled on any master
|
|
|
|
The check function only looks for presence of service entries. It
|
|
ignores enabled/hidden flags.
|
|
|
|
:param svcname: The service to find
|
|
:param conn: a connection to the LDAP server
|
|
:param api: ipalib.API instance
|
|
:return: True/False
|
|
"""
|
|
if svcname not in SERVICE_LIST:
|
|
raise ValueError("Unknown service '{}'.".format(svcname))
|
|
if conn is None:
|
|
conn = api.Backend.ldap2
|
|
|
|
dn = DN(api.env.container_masters, api.env.basedn)
|
|
query_filter = conn.make_filter(
|
|
{
|
|
'objectClass': 'ipaConfigObject',
|
|
'cn': svcname
|
|
},
|
|
rules='&'
|
|
)
|
|
try:
|
|
conn.find_entries(
|
|
filter=query_filter,
|
|
attrs_list=[],
|
|
base_dn=dn
|
|
)
|
|
except errors.NotFound:
|
|
return False
|
|
else:
|
|
return True
|