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

Use Kerberos PAC to allow group based fine-grained access control #288

Open
ondrejv2 opened this issue Aug 23, 2023 · 9 comments
Open

Use Kerberos PAC to allow group based fine-grained access control #288

ondrejv2 opened this issue Aug 23, 2023 · 9 comments

Comments

@ondrejv2
Copy link

Hello,

I am wondering if it would be possible to extend mod_auth_gssapi abilities to decode Kerberos PAC and allow finer grained access control based on groups the authenticated user is member of.
These groups can be extracted from the Kerberos PAC (i.e. without any additional ldap lookup).
Is something like this doable?

Thanks

@simo5
Copy link
Contributor

simo5 commented Aug 23, 2023

In theory yes, but we defer that kind of action to the underlying krb5 library and then use the available APIs to extract that data like we do for other info already.

Keep in mind that the PAC just includes bare bones Identifiers, not user or group names.
So extracting the info in itself is probably not sufficient if you plan to perform access control using groups. Unless you'd be willing to use raw SIDs in the configuration.

In order to resolve users/groups from the PAC you would have to use a system mapping facility like SSSD or Windbind that can cache and unroll the extracted SIDs to the relative accounts.

In libkrb5 there is already a module (used by SSSD too) that can extract a PAC and feed it to SSSD for priming its caches, winbindd can do something similar I believe.

You can take a look at https://github.com/adelton/mod_lookup_identity/ it is a module that can talk to SSSD on its dbus listener to resolve identities properly.

You may also want to test the GssapiNameAttributes option with the "json" value to see if you already have the information you want there. I know that krb5 libraries we use already extract some info from the authroization data, but I do not recall if they do any parsing of the PAC itself and expose it via Named Attributes.

@ondrejv2
Copy link
Author

In theory yes, but we defer that kind of action to the underlying krb5 library and then use the available APIs to extract that
data like we do for other info already.

Looks like the library is doing that already, see:
https://mailman.mit.edu/pipermail/kerberos/2023-August/022991.html

In order to resolve users/groups from the PAC you would have to use a system mapping facility like SSSD or Windbind that
can cache and unroll the extracted SIDs to the relative accounts.

Well, true - having to resolve SIDs to something more meaningful makes the whole idea somewhat less appealing.
The thing is that mod_lookup_identity can not do any authentication/authorization on it's own - can we use it to resolve SIDs or we have to query SSSD via D-BUS directly?

Anyway, I think for a start it would be nice to have this implemented via group SIDs at least - just to see how much audience it would get. I mean I can always stick the CN of the group in the config file as a comment.

BTW: Is IPA also using PAC attributes or it's Microsoft thing only?

@simo5
Copy link
Contributor

simo5 commented Aug 25, 2023

In theory yes, but we defer that kind of action to the underlying krb5 library and then use the available APIs to extract that
data like we do for other info already.

Looks like the library is doing that already, see: https://mailman.mit.edu/pipermail/kerberos/2023-August/022991.html

The library is extracting only some krb5 level fields unfortunately, there is no parsing of the actual authorization data you care for due to the encoding format used (MS NDR).

In order to resolve users/groups from the PAC you would have to use a system mapping facility like SSSD or Windbind that
can cache and unroll the extracted SIDs to the relative accounts.

Well, true - having to resolve SIDs to something more meaningful makes the whole idea somewhat less appealing. The thing is that mod_lookup_identity can not do any authentication/authorization on it's own - can we use it to resolve SIDs or we have to query SSSD via D-BUS directly?

The thing would work this way:
[authentication] httpd -> mod_auth_gssapi -> libkrb5 - --PAC---> SSSD
[authorization] httpd -> mod_lookup_identity <--- SSSD

You would have to have both basically.

Anyway, I think for a start it would be nice to have this implemented via group SIDs at least - just to see how much audience it would get. I mean I can always stick the CN of the group in the config file as a comment.

Requires parsing NDR structures, and that is not very simple, samba has code for it, and SSSD uses some of it for parsing the PAC, but it is not something I would shove into mod_auth_gssapi, it is a huge dependency, for a rarely used feature..

BTW: Is IPA also using PAC attributes or it's Microsoft thing only?

IPA uses (and can generate) MS-PAC structures for its AD trust codepaths.

@ondrejv2
Copy link
Author

ondrejv2 commented Aug 25, 2023

Ok I see.
I was hoping to get some modern replacement for (a bit old-school) mod_authnz_ldap.
Now mod_auth_gssapi looked promising at first, but since it has no support for SSSD, it can't query SSSD for groups the user is member of so we can't really use it.

Is at least support for SSSD on your roadmap? I mean it could work even without PAC support, i.e.:
httpd -> mod_auth_gssapi -> SSSD (query groups the authenticated user is member of)
SSSD -> mod_auth_gssapi -> httpd (allow/deny access based on the configuration)

Unfortunately AFAIK mod_lookup_identity can not be used (or I do not know how to do it and did not find any fruitful documentation for that) for authentication process.

IPA uses (and can generate) MS-PAC structures for its AD trust codepaths.

I see - but since IPA does not use PAC to store auxiliary groups the user is member of, then it probably does not make much sense to add support here, I agree.

@simo5
Copy link
Contributor

simo5 commented Aug 25, 2023

Is at least support for SSSD on your roadmap? I mean it could work even without PAC support, i.e.: httpd -> mod_auth_gssapi -> SSSD (query groups the authenticated user is member of) SSSD -> mod_auth_gssapi -> httpd (allow/deny access based on the configuration)

No, this definitely will not happen.

mod_auth_gssapi is an authc (authentication) module, and does not deal with authorization beyond telling the principal/local name of the user and proding data (like that PAC) that some other module can deal with.

Group based authorization is deferred to specialized authz (authorization) modules that can do that, like mod_lookup_identity.

@michael-o
Copy link
Contributor

michael-o commented Feb 8, 2024

It still would be very helpful if require group S-1-..., means group SIDs are available for authz. I'd be able to throw out my Python scripts to scrape groups via LDAP once in while.

@ondrejv2
Copy link
Author

I have created mod_authnz_sss which provides the functionality (requires SSSD so slightly more complicated to use, but works), see https://issues.redhat.com/browse/RHEL-3699.
Also not sure what the PAC attribute actually contains, does it contain all groups the user is member of (i.e. including nested ones)?

@michael-o
Copy link
Contributor

I have created mod_authnz_sss which provides the functionality (requires SSSD so slightly more complicated to use, but works), see https://issues.redhat.com/browse/RHEL-3699. Also not sure what the PAC attribute actually contains, does it contain all groups the user is member of (i.e. including nested ones)?

Yes, it should all groups in all domains.

@simo5
Copy link
Contributor

simo5 commented Feb 12, 2024

It contains all of the SIDs as unpacked by the KDC, SSSD is needed to translate those into Unix Groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants