ipaserver/dcerpc.py: use Kerberos authentication for discovery

In FIPS mode we cannot rely on NTLMSSP at all, so we have ensure
Kerberos is used by Samba Python libraries. This is achieved by
requiring credentials objects to always use Kerberos authentication.

Additionally, we have to normalize the principal used to authenticate.
In case it was passed without realm, add forest root domain as a realm.
In case it was passed with NetBIOS domain name, remove it and replace
with a realm. Since we only know about the forest root domain as a
realm, require that for other domains' users a real Kerberos principal
is specified.

Fixes: https://pagure.io/freeipa/issue/8655
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Alexander Bokovoy authored and Florence Blanc-Renaud committed 2021-01-14 10:05:12 +01:00
1 parent 753246f4e8
commit 8ab9bf68a4
1 file changed
+15 -2
+15 -2
View File
@@ -1618,14 +1618,27 @@ def retrieve_remote_domain(hostname, local_flatname,
rd.read_only = True
if realm_admin and realm_passwd:
if 'name' in rd.info:
realm_netbios = ""
names = realm_admin.split('\\')
if len(names) > 1:
# realm admin is in DOMAIN\user format
# strip DOMAIN part as we'll enforce the one discovered
realm_admin = names[-1]
auth_string = r"%s\%s%%%s" \
% (rd.info['name'], realm_admin, realm_passwd)
realm_netbios = names[0]
names = realm_admin.split('@')
if len(names) == 1:
if all([len(realm_netbios) != 0,
realm_netbios.lower() != rd.info['name'].lower()]):
raise errors.ValidationError(
name=_('Credentials'),
error=_('Non-Kerberos user name was specified, '
'please provide user@REALM variant instead'))
realm_admin = r"%s@%s" % (
realm_admin, rd.info['dns_forest'].upper())
auth_string = r"%s%%%s" \
% (realm_admin, realm_passwd)
td = get_instance(local_flatname)
td.creds.set_kerberos_state(credentials.MUST_USE_KERBEROS)
td.creds.parse_string(auth_string)
td.creds.set_workstation(hostname)
if realm_server is None: