Skip to content

Add cache for retrieved RBAC claims - #25698

Merged
JunTaoLuo merged 5 commits into
release/5.0-rc2from
johluo/claim-cache
Sep 9, 2020
Merged

Add cache for retrieved RBAC claims#25698
JunTaoLuo merged 5 commits into
release/5.0-rc2from
johluo/claim-cache

Conversation

@JunTaoLuo

@JunTaoLuo JunTaoLuo commented Sep 8, 2020

Copy link
Copy Markdown
Contributor

fixes #25329.

Tested manually, I have a feeling unit tests are going to be tricky.

@JunTaoLuo
JunTaoLuo requested a review from Tratcher as a code owner September 8, 2020 17:30
@ghost ghost added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Sep 8, 2020
/// </summary>
public int ClaimsCacheSize { get; set; } = 1024;

internal MemoryCache ClaimsCache { get; set; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is different from the certificate validation cache in that it's not stored in DI. It might be a bit odd to have the cache in LdapSettings but I'm not sure if there's any value in putting this cache in DI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Main value of putting it in DI is if you want to make it easy for them to plug in their own cache implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While that's true, I'm not sure we'd want that kind of flexibility here at the moment. I don't see it as particularly useful in this scenario.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's fine, I was just pointing out what advantages putting it in DI has

Comment thread src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs Outdated
@Tratcher
Tratcher requested a review from HaoK September 8, 2020 20:10
@Tratcher

Tratcher commented Sep 8, 2020

Copy link
Copy Markdown
Member

You can write a test that seeds the cache and verifies those are the values returned.

{
ldapSettings.Domain = "domain.NET";
ldapSettings.ClaimsCache = claimsCache;
ldapSettings.EnableLdapClaimResolution = false; // This disables binding to the LDAP connection on startup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As I expected, this is really hacky but it works.

Comment thread src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs Outdated
Comment thread src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs Outdated
Comment thread src/Security/Authentication/Negotiate/src/LdapSettings.cs Outdated
Comment thread src/Security/Authentication/Negotiate/src/LdapSettings.cs Outdated
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
@JunTaoLuo JunTaoLuo added the Servicing-consider Shiproom approval is required for the issue label Sep 9, 2020
@ghost

ghost commented Sep 9, 2020

Copy link
Copy Markdown

Hello human! Please make sure you've included the Shiproom Template in a comment or (preferably) the PR description. Also, make sure this PR is not marked as a draft and is ready-to-merge.

@JunTaoLuo JunTaoLuo added this to the 5.0.0-rc2 milestone Sep 9, 2020
@JunTaoLuo

Copy link
Copy Markdown
Contributor Author

cc @Pilchie for rc2 approval.

@Pilchie Pilchie added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Sep 9, 2020
@Pilchie

Pilchie commented Sep 9, 2020

Copy link
Copy Markdown
Member

Approved for .NET 5 RC2 pending CI completion.

@JunTaoLuo
JunTaoLuo merged commit 035221d into release/5.0-rc2 Sep 9, 2020
@JunTaoLuo
JunTaoLuo deleted the johluo/claim-cache branch September 9, 2020 21:24
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 Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants