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

Linux: Fix nested group resolution for RBAC claims #35279

Closed
wants to merge 3 commits into from

Conversation

RoadTrain
Copy link
Contributor

@RoadTrain RoadTrain commented Aug 11, 2021

This PR fixes three issues with current RBAC claims resolution code. Every issue is fixed in a separate commit, to simplify review.


We have been trying to set up claims resolution for our services running in docker, and it was crashing when we set IgnoreNestedGroups = true. So I did some research, and found three issues which I managed to fix.

c6c4516: Fix nested claims retrieval -- use CN instead of DN
I think this one is simple. Naturally, we should use group canonical name (CN) as a claim value. But for some reason the code used group distinguished name (DN) instead. So instead of SomeGroup, the claim value would be CN=SomeGroup,DC=domain,DC=COM, which is obviously not what we want.

bba75b7: Keep track of already processed group to account for possible circular references
This one fixes a particular corner case which is possible in real-world AD deployments, namely circular group references.
That is, e.g. GroupA -> GroupB -> GroupC -> GroupA. This is a problematic scenario for any software working with AD.
The fix is basically to keep track of groups that we already processed.
Fixes #37225

7f72499: Escape LDAP filter arguments
This one fixes another real-world scenario. It's possible for a group CN to include characters such as ( or ), for example Some (very) important group. Parentheses in partucular are a part of filter syntax. When we construct the LDAP filter expression and don't escape these symbols, openldap fails with LdapException: The search filter is invalid. So the solution is to simply escape them according to the relevant RFC.
This one might be somewhat related to dotnet/runtime#38609.
The caveat here is that on Windows unescaped filter is working, while on Linux it doesn't. There's likely a difference in the way underlying native libraries (Wldap32 vs openldap) operate.

TODO:

  • Tests? Not sure where to implement them.

@RoadTrain RoadTrain requested a review from Tratcher as a code owner August 11, 2021 23:41
@ghost ghost added area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer community-contribution Indicates that the PR has been added by a community member labels Aug 11, 2021
@dnfadmin
Copy link

dnfadmin commented Aug 11, 2021

CLA assistant check
All CLA requirements met.

{
var filter = $"(&(objectClass=group)(sAMAccountName={groupCN}))"; // This is using ldap search query language, it is looking on the server for someUser
retrievedClaims.Add(groupCN);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved it here from under if clause, but I'm actually not sure.
Basically what I did was compare the results of this code in Linux vs Windows.
I noticed one difference in their behaviour:

  1. When using filter below on Windows, the results include all groups, including distribution groups (email distribution lists).
  2. On Linux, distribution groups are not resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it warrants a separate issue.

@blowdart
Copy link
Contributor

Generally we want individual issues rather than PRs first, so we can validate the scenario

As you can see with the lack of tests, this is frankly hard to test. We need a suitable ldap server configuration documented that we can reproduce, and then we run manual tests. So can you give us an idea of what setup you have, including some sample users, as well as your docker configuration and how you're authenticating and we can go from there.

@RoadTrain
Copy link
Contributor Author

Just to update, I plan on documenting the requested stuff here in 1-2 weeks.

@RoadTrain
Copy link
Contributor Author

Update on 7f72499:
After discussion at dotnet/runtime#38609 (comment), I think I will draft an API proposal directly to S.DS.P, and remove this code from here.

@RoadTrain
Copy link
Contributor Author

RoadTrain commented Oct 2, 2021

I've filed an API proposal at dotnet/runtime#59900

@macsux
Copy link

macsux commented Dec 1, 2021

Can the recursive issue be isolated as its own PR as it's likely to get merged upstream much faster than proposed API changes?

@macsux
Copy link

macsux commented Dec 1, 2021

Something worth mentioning. Kerberos tickets will come with AD group SIDs. If group names to sids mapping can be cached, LDAP queries can be avoided for a large number of requests when authentication is done via Kerberos. See this on how this can be implemented (though in the linked code I preloaded and keep in sync all AD groups as background process so no LDAP queries are ever issued per-request, greatly speeding up request pipeline. The downside of my approach is higher memory consumption if there are a lot of AD groups that need to be cached in memory).

@RoadTrain
Copy link
Contributor Author

Can the recursive issue be isolated as its own PR as it's likely to get merged upstream much faster than proposed API changes?

Yeah, I think that would be a better approach.
I will do that soon.

@RoadTrain
Copy link
Contributor Author

@macsux
I've cherry-picked recursion fixes to #38817

@adityamandaleeka
Copy link
Member

@RoadTrain Can this PR be closed now since the recursion fixes were done separately and the LDAP work is being tracked in the dotnet/runtime issue?

@RoadTrain
Copy link
Contributor Author

@adityamandaleeka Yes, I will close this PR for now.

@RoadTrain RoadTrain closed this Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linux: RBAC claims resolution hangs if nested groups have circular dependencies
5 participants