Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden PAC processing #6076

Closed
wants to merge 9 commits into from
Closed

Conversation

abbra
Copy link
Contributor

@abbra abbra commented Nov 9, 2021

Implement suggestions outlined in https://www.samba.org/samba/security/CVE-2020-25721.html

In order to avoid issues like CVE-2020-25717 AD Kerberos accepting
services need access to unique, and ideally long-term stable
identifiers of a user to perform authorization.

The AD PAC provides this, but the most useful information is kept in a
buffer which is NDR encoded, which means that so far in Free Software
only Samba and applications which use Samba components under the hood
like FreeIPA and SSSD decode PAC.

Recognising that the issues seen in Samba are not unique, Samba now
provides an extension to UPN_DNS_INFO, a component of the AD PAC, in a
way that can be parsed using basic pointer handling.

From this, future non-Samba based Kerberised applications can easily obtain
the user's SID, in the same packing as objectSID in LDAP, confident
that the ticket represents a specific user, not matter subsequent
renames.

This will allow such non-Samba applications to avoid confusing one
Kerberos user for another, even if they have the same string name (due
to the gap between time of ticket printing by the KDC and time of
ticket acceptance).

Implement PAC_UPN_DNS_INFO_EX, PAC_ATTRIBUTES_INFO, PAC_REQUESTER_SID, and other hardening improvements as suggested by Samba Team and Microsoft.

Additional information:
Microsoft: https://support.microsoft.com/en-us/topic/kb5008380-authentication-updates-cve-2021-42287-9dafac11-e0d0-4cb8-959a-143bd0201041
Samba Team: https://www.samba.org/samba/latest_news.html#4.15.2

@abbra
Copy link
Contributor Author

abbra commented Nov 9, 2021

This PR intentionally lacks changes changes for freeipa.spec.in to bump dependency on new Samba releases. They aren't packaged yet anywhere. The patches are done in such way that new functionality is detected at build time -- except the server role update which will be tried at run-time every time upgrade is run. Samba prevents setting server role to not supported value, thus we simply catch this error code and older value is kept.

@abbra abbra added the ipa-4-9 Mark for backport to ipa 4.9 label Nov 9, 2021
@abbra
Copy link
Contributor Author

abbra commented Nov 9, 2021

I'm going to look into failures tomorrow, one of the issues is a missing domain SID on the service principal, I know where to check...

Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](Error): PAC issue: PAC record claims domain SID different to local domain SID: local [S-0-0], PAC [S-1-5-21-1063033738-2461379948-1565617345]
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): TGS_REQ : handle_authdata (-1765328372)
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): TGS_REQ (6 etypes {aes256-cts-hmac-sha1-96(18), aes256-cts-hmac-sha384-192(20), camellia256-cts-cmac(26), aes128-cts-hmac-sha256-128(19), aes128-cts-hmac-sha1-96(17), camellia128-cts-cmac(25)}) 172.18
.0.2: HANDLE_AUTHDATA: authtime 1636487556, etypes {rep=UNSUPPORTED:(0)} HTTP/master1.ipa.test@IPA.TEST for ldap/master1.ipa.test@IPA.TEST, KDC policy rejects request
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): ... CONSTRAINED-DELEGATION s4u-client=admin@IPA.TEST

@abbra
Copy link
Contributor Author

abbra commented Nov 9, 2021

One more note: we need to add processing of the 'server role' with older value for the configuration with old samba. Looks like the value of server role needs to be templated here.

@abbra
Copy link
Contributor Author

abbra commented Nov 10, 2021

I'm going to look into failures tomorrow, one of the issues is a missing domain SID on the service principal, I know where to check...

Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](Error): PAC issue: PAC record claims domain SID different to local domain SID: local [S-0-0], PAC [S-1-5-21-1063033738-2461379948-1565617345]
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): TGS_REQ : handle_authdata (-1765328372)
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): TGS_REQ (6 etypes {aes256-cts-hmac-sha1-96(18), aes256-cts-hmac-sha384-192(20), camellia256-cts-cmac(26), aes128-cts-hmac-sha256-128(19), aes128-cts-hmac-sha1-96(17), camellia128-cts-cmac(25)}) 172.18
.0.2: HANDLE_AUTHDATA: authtime 1636487556, etypes {rep=UNSUPPORTED:(0)} HTTP/master1.ipa.test@IPA.TEST for ldap/master1.ipa.test@IPA.TEST, KDC policy rejects request
Nov 09 19:52:37 master1.ipa.test krb5kdc[4608](info): ... CONSTRAINED-DELEGATION s4u-client=admin@IPA.TEST

this part is probably happening shortly after SID was associated with the domain but before KDB driver noticed this change. We definitely need to reinit mspac object cache if this is detected. I am going to add it here.

@abbra
Copy link
Contributor Author

abbra commented Nov 10, 2021

Out of other Azure CI failures, one looks like a flaky 'user-add returns an object with ipaNTUserAttrs or not' type. @flo-renaud, does it sound familiar?

@abbra abbra added the re-run Trigger a new run of PR-CI label Nov 10, 2021
@flo-renaud
Copy link
Contributor

Out of other Azure CI failures, one looks like a flaky 'user-add returns an object with ipaNTUserAttrs or not' type. @flo-renaud, does it sound familiar?

I found the root cause, working on a fix.

@freeipa-pr-ci freeipa-pr-ci removed the re-run Trigger a new run of PR-CI label Nov 10, 2021
@abbra abbra added the re-run Trigger a new run of PR-CI label Nov 10, 2021
@freeipa-pr-ci freeipa-pr-ci removed the re-run Trigger a new run of PR-CI label Nov 10, 2021
@abbra
Copy link
Contributor Author

abbra commented Nov 10, 2021

With the latest fixes, I don't see anymore Kerberos-related issues. New PAC buffers will be visible once Samba updates land in Fedora.
I am waiting for the last four test suites to complete -- two of them failed for unrelated reasons and re-scheduled.

@abbra
Copy link
Contributor Author

abbra commented Nov 10, 2021

FYI, GATING upgrade_1_to_1 encounters a crash in 389-ds contentsync plugin. I opened an issue for 389-ds, as it is unrelated to the changes in this PR: 389ds/389-ds-base#4998

If the principal entry in LDAP has SID associated with it, store it to
be able to quickly assess the SID when processing PAC.

Also rename string_to_sid to IPA-specific version as it uses different
prototype than Samba version.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Robert Crittenden <rcritten@redhat.com>
Check that a domain SID and a user SID in the PAC passed to us are what
they should be for the local realm's principal.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Robert Crittenden <rcritten@redhat.com>
When working with aliased entries, we need a reliable way to detect
whether two principals reference the same database entry. This is
important in S4U checks.

Ideally, we should be using SIDs for these checks as S4U requires PAC
record presence which cannot be issued without a SID associated with an
entry. This is true for user principals and a number of host/service
principals associated with Samba. Other service principals do not have
SIDs because we do not allocate POSIX IDs to them in FreeIPA. When PAC
is issued for these principals, they get SID of a domain computer or
domain controller depending on their placement (IPA client or IPA
server).

Since 389-ds always returns unique entry DN for the same entry, rely on
this value instead. We could have used ipaUniqueID but for Kerberos
principals created through the KDB (kadmin/kdb5_util) we don't have
ipaUniqueID in the entry.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
According to new Samba Kerberos tests and [MS-SFU] 3.2.5.2.4
'KDC Replies with Service Ticket', the target should not include the
realm.

Fixes: https://pagure.io/freeipa/issue/9031

Pair-programmed-with: Andreas Schneider <asn@redhat.com>
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Signed-off-by: Andreas Schneider <asn@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
CVE-2020-25721 mitigation: KDC must provide the new HAS_SAM_NAME_AND_SID
buffer with sAMAccountName and ObjectSID values associated with the
principal.

The mitigation only works if NDR library supports the
PAC_UPN_DNS_INFO_EX buffer type. In case we cannot detect it at compile
time, a warning will be displayed at configure stage.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
CVE-2020-25721 mitigation: KDC must provide the new PAC_REQUESTER_SID
buffer with ObjectSID value associated with the requester's principal.

The mitigation only works if NDR library supports the PAC_REQUESTER_SID
buffer type. In case we cannot detect it at compile time, a warning will
be displayed at configure stage.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
PAC_ATTRIBUTES_INFO PAC buffer allows both client and KDC to tell
whether a PAC structure was requested by the client or it was provided
by the KDC implicitly. Kerberos service then can continue processing or
deny access in case client explicitly requested to operate without PAC.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
As part of CVE-2020-25717 mitigations, Samba expects correct user
account flags in the PAC. This means for services and host principals we
should be using ACB_WSTRUST or ACB_SVRTRUST depending on whether they
run on IPA clients ("workstation" or "domain member") or IPA servers
("domain controller").

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
As a part of CVE-2020-25717 mitigations, Samba now assumes 'CLASSIC
PRIMARY DOMAIN CONTROLLER' server role does not support Kerberos
operations.  This is the role that IPA domain controller was using for
its hybrid NT4/AD-like operation.

Instead, 'IPA PRIMARY DOMAIN CONTROLLER' server role was introduced in
Samba. Switch to this role for new installations and during the upgrade
of servers running ADTRUST role.

Fixes: https://pagure.io/freeipa/issue/9031

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-by: Rob Crittenden <rcritten@redhat.com>
@rcritten rcritten added ack Pull Request approved, can be merged pushed Pull Request has already been pushed labels Nov 10, 2021
@rcritten
Copy link
Contributor

master:

  • 6cfb9b7 ipa-kdb: store SID in the principal entry
  • 637653a ipa-kdb: enforce SID checks when generating PAC
  • 443a990 ipa-kdb: use entry DN to compare aliased entries in S4U operations
  • 6828273 ipa-kdb: S4U2Proxy target should use a service name without realm
  • 2333616 ipa-kdb: add support for PAC_UPN_DNS_INFO_EX
  • 9a0bcbb ipa-kdb: add support for PAC_REQUESTER_SID buffer
  • 0022bd7 ipa-kdb: add PAC_ATTRIBUTES_INFO PAC buffer support
  • 3042a1d ipa-kdb: Use proper account flags for Kerberos principal in PAC
  • 6e6fad4 SMB: switch IPA domain controller role

@rcritten rcritten closed this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged ipa-4-9 Mark for backport to ipa 4.9 pushed Pull Request has already been pushed
Projects
None yet
4 participants