Skip to content

rgw/keystone: use the sse-kms cache parts for the secret cache - #71929

Open
mheler wants to merge 2 commits into
ceph:mainfrom
mheler:wip-rgw-67793
Open

mheler wants to merge 2 commits into
ceph:mainfrom
mheler:wip-rgw-67793

Conversation

@mheler

@mheler mheler commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Build the keystone EC2 secret cache on the WebCache and once_result parts from the sse-kms secrets cache in #61256, so concurrent requests for the same access key share one keystone lookup.

Fixes: https://tracker.ceph.com/issues/67793
Fixes: https://tracker.ceph.com/issues/80504

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

Build SecretCache on WebCache and once_result, the parts the sse-kms
secrets cache is made of. A miss now fetches once and every concurrent
request for the same access key waits for that result instead of
sending its own s3tokens and credential requests to keystone. Failures
are not cached.

Signed-off-by: Matthew N. Heler <[email protected]>
@github-actions github-actions Bot added the rgw label Sep 20, 2026
@mheler
mheler requested review from irq0 and supriti September 20, 2026 20:20
@mheler
mheler marked this pull request as ready for review September 20, 2026 20:21
@mheler
mheler requested a review from a team as a code owner September 20, 2026 20:21
@supriti

supriti commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@mheler I will do a detailed review later, but some quick thoughts. Some unit tests would be good to have. Also, could you share whether you tested this against the reproducer in the tracker?

I was working on a possible solution for the same tracker
WIP branch: https://github.com/supriti/ceph/tree/wip-keystone-cache. Your approach of using WebCache + call_once is the right one.

While investigating I found other places where the same keystone stampede happens:

  1. Service::get_admin_token(): called before every keystone request, and has no in-flight state of its own. I have not tested whether this shows up when running the reproducer against a freshly started RGW, where that cache is cold too.
  2. TokenEngine::authenticate(), the swift token path.
  3. Service token path.

None of these are in 67793, which is specifically about concurrent s3 requests causing repeated get_secret_from_keystone(). This PR covers that.

So I would open a separate tracker per path and do them on top of this rather than growing this PR. Happy to take them on, or to hand them over if you would rather.

get_admin_token sends its own v3/auth/tokens request for every caller
that misses the cache, so when the admin token expires every request
in flight asks keystone for a new one at the same time. Hold the request
in flight in TokenCache and run it through call_once, so callers that
miss together wait on the same one.

Signed-off-by: Matthew N. Heler <[email protected]>
@mheler

mheler commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@mheler I will do a detailed review later, but some quick thoughts. Some unit tests would be good to have. Also, could you share whether you tested this against the reproducer in the tracker?

I was working on a possible solution for the same tracker WIP branch: https://github.com/supriti/ceph/tree/wip-keystone-cache. Your approach of using WebCache + call_once is the right one.

While investigating I found other places where the same keystone stampede happens:

1. Service::get_admin_token(): called before every keystone request, and has no in-flight state of its own. I have not tested whether this shows up when running the reproducer against a freshly started RGW, where that cache is cold too.

2. TokenEngine::authenticate(), the swift token path.

3. Service token path.

None of these are in 67793, which is specifically about concurrent s3 requests causing repeated get_secret_from_keystone(). This PR covers that.

So I would open a separate tracker per path and do them on top of this rather than growing this PR. Happy to take them on, or to hand them over if you would rather.

I added a second commit to cover the admin token path. I am not sure there's a huge benefit for the service token path though, and I am skeptical there is significant use of swift to warrant this work (I would love to see swift completely disabled someday though).

for (;;) {
auto value = secret_cache.lookup_or_insert(key);
bool fetched = false;
result = call_once(*value, y, [&] { fetched = true; return fetch(); });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: fetch() only catches int, so an unexpected std::exception (e.g. bad_alloc) would be stored by call_once and skip the remove() calls below, leaving the entry replaying that exception. Unlikely, but a catch (...) { secret_cache.remove(key, value); throw; } around call_once would make it robust. Same for admin_request_done() in get_admin_token().

@supriti

supriti commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Please find some more comments on the PR.

  1. Verification against the reproducer

Did you run this PR against the reproducer at https://github.com/kayrus/ceph-auth-poc. The original report in https://tracker.ceph.com/issues/67793 shows 1000 simultaneous requests producing 2000 simultaneous requests to Keystone. Could you share how many Keystone requests you see with this PR applied? I can also run it later against my local keystone docker that I use for testing.

  1. The secret cache should only hold validated credentials

In the current code, an access key is added to the secret cache only after Keystone has validated it:

if (secret) {
/* Add token, secret pair to cache, and set timeout */
secret_cache.add(std::string(access_key_id), *token, *secret);

In this PR, lookup_or() inserts an entry for the in-flight lookup before Keystone has answered. If the cache is full, that insert evicts an existing entry. If Keystone then rejects the lookup (for example, an unknown access key), remove_if() drops the in-flight entry as well. We end up evicting a validly cached key and gaining nothing.

With the default rgw_keystone_token_cache_size of 10000, this is unlikely on smaller deployments. But expired entries are only removed when the same access key is looked up again, both in the current code and in this PR, so on a daemon that has seen more than 10000 distinct access keys the cache stays full. It's also a design issue: the cache should only hold validated credentials, as it does today.

Suggestion: keep in-flight lookups in a separate map whose entries only exist while the fetch is running, and add to the secret cache only on success. That keeps the coalescing and avoids evicting good entries on failed lookups.

  1. Unit tests would be nice to have.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Nov 28, 2026
@kayrus

kayrus commented Nov 28, 2026

Copy link
Copy Markdown

/unstale

@mheler

mheler commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

I plan to revisit this shortly.

@mheler mheler removed the stale label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants