Skip to content

Use most parameters from Credentials Cache key#3339

Closed
dimas-b wants to merge 1 commit into
apache:mainfrom
dimas-b:principal-in-cache
Closed

Use most parameters from Credentials Cache key#3339
dimas-b wants to merge 1 commit into
apache:mainfrom
dimas-b:principal-in-cache

Conversation

@dimas-b
Copy link
Copy Markdown
Contributor

@dimas-b dimas-b commented Dec 30, 2025

The Credentials Cache produces cache hits based on the cache key, but the cached data is generated from parameters that are not always reflected in the key (e.g. PolaricPrincipal). As a result, it is not evident that positive cache hits always represent exactly the same credentials that would be produced from scratch.

This change takes care of propagating all parameter through the cache key, except the entity, which is a bit complicated to handle and probably needs a separate PR.

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

The Credentials Cache produces cache hits based on the cache key,
but the cached data is generated from parameters that are not
always reflected in the key (e.g. `PolaricPrincipal`). As a result,
it is not evident that positive cache hits always represent exactly
the same credentials that would be produced from scratch.

This change takes care of propagating all parameter through the cache
key, except the entity, which is a bit complicated to handle and
probably needs a separate PR.
@dimas-b
Copy link
Copy Markdown
Contributor Author

dimas-b commented Dec 30, 2025

CC: @tokoko

@dimas-b dimas-b requested a review from singhpk234 December 30, 2025 20:35

@Value.Parameter(order = 8)
Optional<String> principalName();
Optional<PolarisPrincipal> principal();
Copy link
Copy Markdown
Contributor

@tokoko tokoko Dec 30, 2025

Choose a reason for hiding this comment

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

I thought of doing something like this before. (using key to get the value feels right). Having said that, I convinced myself that it wasn't worth it because now you're using whole PolarisPrincipal object as part of the cache key which contains more than just the name. I doubt using roles and properties will cause cache misses all that much, but you're also relying on the fact that someone in the future won't go ahead and write something more dynamic in there (like a token which was discussed before iirc).

Or maybe I'm completely misunderstanding how this immutables library works...

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.

right... the background for this is #3327 where, indeed, roles are used in STS calls

Copy link
Copy Markdown
Contributor

@tokoko tokoko Dec 30, 2025

Choose a reason for hiding this comment

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

okay, got it. I still think it's a ticking time bomb 😆 especially that it will affect cache even if only includePrincipalNameInSubscopedCredential is activated.

I guess the only actual solution I see for these sorts of issues is to delegate key generation to Integration classes themselves:

  • Manager always loads Integration class (might have to introduce some sort of a cache for Integration classes, maybe..)
  • passes all the parameters and asks for a key
  • checks the cache and returns if non-empty
  • passes all the parameters again now asking for a value.

But that will need a major refactor that I'm still gonna get back to soon 😆 Until then, I guess it's okay to merge this not to block the feature.

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.

I guess the only actual solution I see for these sorts of issues is to delegate key generation to Integration classes themselves

Yes, I actually thought about that exact approach too. I agree that it's ultimately the better solution.

I'm going to close this PR. I think there is no bug in current cache behaviour. Let's go for the proper solution.

@dimas-b dimas-b closed this Dec 30, 2025
@github-project-automation github-project-automation Bot moved this from PRs In Progress to Done in Basic Kanban Board Dec 30, 2025
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

Successfully merging this pull request may close these issues.

2 participants