Skip to content

rgw: replace vendored legacy jwt-cpp with updated submodule - #73914

Open
ta1hia wants to merge 2 commits into
ceph:mainfrom
ta1hia:wip-70910-rgw-replace-jwt-cpp-with-submodule
Open

ta1hia wants to merge 2 commits into
ceph:mainfrom
ta1hia:wip-70910-rgw-replace-jwt-cpp-with-submodule

Conversation

@ta1hia

@ta1hia ta1hia commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: sts: replace src/rgw/jwt-cpp/ with submodule

The vendored jwt-cpp headers had local additions like setModulusExponentCalcPublicKey and manual BIGNUM/RSA helpers that aren't in any upstream releases. Because of that, swapping to upstream v0.7.2 as a submodule wasn't a clean drop-in file swap and needed some extra effort to adapt to API/template changes:

  • Replaced src/rgw/jwt-cpp/ with the upstream submodule and guarded against the picojson expect macro collision in rgw_rest_sts.h with #pragma push_macro / #pop_macro.
  • Updated rgw_rest_sts.cc/.h for upstream jwt-cpp types/methods, used jwt::helper::create_public_key_from_rsa_components for RSA JWK components, and refactored recurse_and_insert() (skipping null values and dropping the dummy sentinel in favor of is_root_tags and princTagsNamespace) alongside splitting principal tag extraction into get_principal_tags().
  • Added WebTokenEngineTestAccess hooks and unit tests in test_rgw_web_token.cc covering the refactored behavior.

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.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@ta1hia
ta1hia force-pushed the wip-70910-rgw-replace-jwt-cpp-with-submodule branch from 698ed9c to 4a2a732 Compare November 16, 2026 18:13
@ta1hia
ta1hia marked this pull request as ready for review November 16, 2026 18:17
@ta1hia
ta1hia requested a review from a team as a code owner November 16, 2026 18:17
@ta1hia ta1hia changed the title [DRAFT] rgw: replace legacy jwt-cpp with upstream v0.7.2 rgw: replace vendored legacy jwt-cpp with updated submodule Nov 16, 2026
@pritha-srivastava

Copy link
Copy Markdown
Contributor

This has been attempted in the past and has introduced regressions in the tags parsing code in AssumeRoleWithWebIdentity

@ta1hia

ta1hia commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

This has been attempted in the past and has introduced regressions in the tags parsing code in AssumeRoleWithWebIdentity

@pritha-srivastava I believe this is the regression you're referencing: #61796 (comment). I'll take some time to assess what it would take to cover the regression. Thank you so much for the context!

@ta1hia
ta1hia force-pushed the wip-70910-rgw-replace-jwt-cpp-with-submodule branch from 4a2a732 to 1b1faae Compare November 18, 2026 01:47
@github-actions github-actions Bot added the tests label Nov 20, 2026
@pritha-srivastava

Copy link
Copy Markdown
Contributor

@ta1hia : give me a couple of days, I will review this PR

Comment thread src/rgw/rgw_rest_sts.cc Outdated
jwt::json::type c_type = c.get_type();

// Ignore root placeholder or namespace keys if passed on non-container types
if ((key == "dummy" || key == "https://aws.amazon.com/tags") &&

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.

what if the claim name is actually "dummy"

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 check was there to catch the placeholder key passed from get_from_jwt when starting recursion on principal tags, but you're right that an actually "dummy" claim would get silently ignored here

instead of overloading the key name, i can add a bool is_root_tags param to recurse_and_insert and check that instead to be explicit

Comment thread src/rgw/rgw_rest_sts.cc Resolved
Comment thread src/rgw/rgw_rest_sts.cc Outdated
}

std::string
WebTokenEngine::get_pem_from_jwk(const std::string& n_b64url, const std::string& e_b64url) const

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.

I believe jwt::helper::create_public_key_from_rsa_components(n, e) can be used to convert n& e JWK to PEM

Comment thread src/rgw/rgw_b64.h Outdated
b64_iter(sview.data() + sview.size()));

return outstr;
try {

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.

avoid decoder changes here and let the error be visible to the callers so that they decide what to do with the error

Comment thread src/test/rgw/test_rgw_web_token.cc Resolved
@pritha-srivastava

Copy link
Copy Markdown
Contributor

@cbodley : this is a PR that aims to replace jwt-cpp from our code with the updated submodule. Earlier this attempt had introduced regressions in principal tags parsing in PR #61796 (comment) and hence the submodule was dropped. But this PR attempts to overcome the regression. I have already reviewed the PR. Request you to also take a look.

Once the PR is approved and passes qa (to confirm there's no regression), we would need someone in the community to help test web keys with n&e as Keycloak does not provide web keys with n&e (atleast it didn't till I looked into it last)

@ta1hia
ta1hia force-pushed the wip-70910-rgw-replace-jwt-cpp-with-submodule branch 2 times, most recently from f621c96 to 69010a6 Compare November 24, 2026 20:42
Comment thread src/rgw/rgw_rest_sts.cc Outdated
continue;
}
// Drop wrapper keys for child containers; preserve valid keys for array items
std::string next_key = (is_root_tags || key == princTagsNamespace) ? "" : key;

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.

consider JWT that has the following structure:

{
  "custom": {
    "https://aws.amazon.com/tags": ["engineering"],
    "": ["enabled"]
  }
}

where someone has decided to use "https://aws.amazon.com/tags" and "" as keys.
The code here causes it to drop real data, including scalar values under a nested field named https://aws.amazon.com/tags and array values under a valid empty key "". The new is_root_tags flag fixes the "dummy" collision, but those two cases remain.

You can keep the AWS namespace check at the top-level lookup and give the recurse_and_insert method a std::optionalstd::string_view key. Pass std::nullopt at the unnamed tags root (e.g for custom). Objects supply each member’s real key, arrays pass the current key through, and scalars are emitted whenever a key is present, even if it’s "". Keep skipping JSON null

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 simplified recurse_and_insert with your suggestions to fix the two data loss edge cases + added some additional test cases to verify the behaviour. thank you for catching this again!

@cbodley

cbodley commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Once the PR is approved and passes qa (to confirm there's no regression), we would need someone in the community to help test web keys with n&e as Keycloak does not provide web keys with n&e (atleast it didn't till I looked into it last)

@pritha-srivastava i don't understand the contents of these json documents well enough to review in detail, so i would rely on test coverage to validate. my recollection is that nesting didn't work in the earlier attempt, and i see that there are unit tests for that here

if we don't have access to a non-keycloak server to test against, could we at least get a sample json document that we build a unit test for?

@pritha-srivastava

pritha-srivastava commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Once the PR is approved and passes qa (to confirm there's no regression), we would need someone in the community to help test web keys with n&e as Keycloak does not provide web keys with n&e (atleast it didn't till I looked into it last)

@pritha-srivastava i don't understand the contents of these json documents well enough to review in detail, so i would rely on test coverage to validate. my recollection is that nesting didn't work in the earlier attempt, and i see that there are unit tests for that here

if we don't have access to a non-keycloak server to test against, could we at least get a sample json document that we build a unit test for?

I'll see if we can build a sample JSON for n&e testing. The unit tests here cover various kinds of nested and flattened JSON samples including the one that caused regression last time.

Can you please review the submodule part as I am not very well versed with that.

@pritha-srivastava

Copy link
Copy Markdown
Contributor

ok I generated a sample JWT using codex:
eyJhbGciOiJSUzI1NiIsImtpZCI6InJndy1uZS11bml0LXRlc3QiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2lzc3Vlci5leGFtcGxlLnRlc3QiLCJhdWQiOiJyZ3ctdW5pdC10ZXN0Iiwic3ViIjoiandrcy1maXh0dXJlIn0.KEqRzk_Z8KXSe3k5_AfpORuHUbCpDxxrSL9rAVsqXZmBa7XTRVEd6-KNfnf7FGcQcVcYoCfPofV9osXtBFfxB6wph563I6NrZu80scrO6nLOyc0e6DS1TML4N58FTRVkmGUvkbtiTGHrMM6JofY6t7HSoMovJUM8nSioR5EG5tzisIVvJEwu9qx9SE_uSwibEI4UfWYD6nTGfoYqhbQDCAdJniRq2euREQWcMefkBcqJbyC17seWd1fBHFgTHgC0sEHgeywstmTyqJNkw5xjmaOOvLxTj-R-vUz6nxFRm33tNXIqi0C5oCSK91dV_BNW3D25Cu5nG5W1hDTJ7U5AZA

and its corresponding JWKS:
{
"keys": [
{
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "rgw-ne-unit-test",
"n": "oXX0SRv9u8FXUHmGPSZXpiKKRXUFJcz5837PVwETo8G3b6kPK6BkLRBdeG5wFQs5w7Sj8LrbI7k0pDH6d8jKoZM62g9QKZnpji9VJkgoVi1U63vQJbdkSlGaY3zsc09OPQnCsdRcOhpcSbAr1VvoMSXlJIiYww3_x9QgfxblTrHk1GSYPt7x5pISBa7TUtIySiaOVKlB-KsJSfCar_MJX_JHV4tJtqRIWf5oHWHnHj8sr2Lj93z9dG5QLuzy3AfgaubnZO6vuPzfW1g2zH5D4A6I-yfcEXuyjfOUG8U0wLU97Z31IGIUBGWugdg86MgaymBPx841Mh_oUI1Cb75L5Q",
"e": "AQAB"
}
]
}

and verified the JWT and its signature on https://www.jwt.io/
@ta1hia : you can add a unit test for n&e testing as well using the above JWT and JWKS

@cbodley cbodley left a comment •

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.

submodule changes look good 👍 the submodule points to the v0.7.2 release. i see that 0.7.3 was just tagged yesterday. it might be worth seeing whether that includes any changes that are relevant here

otherwise just minor comments on cmake bits

Comment thread src/rgw/CMakeLists.txt Resolved
Comment thread src/rgw/CMakeLists.txt Resolved
@ta1hia
ta1hia force-pushed the wip-70910-rgw-replace-jwt-cpp-with-submodule branch from 65969e0 to 99c7ac5 Compare November 29, 2026 19:17
@ta1hia

ta1hia commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

thank you both for taking a look! i’ve updated the PR with the following-

@pritha-srivastava: i updated recurse_and_insert with your suggestions and added test cases for nested namespace/empty keys, unkeyed root scalars, and validate_signature_using_n_e() based on the JWT you provided

@cbodley: i removed the redundant statements in cmake and bumped jwt-cpp to v0.7.3

by the way, is it preferable if i squash my commits into a single commit right now, or is that done at the time of merging?

@pritha-srivastava

Copy link
Copy Markdown
Contributor

the code looks good to me. you can separate out the commits into two - 1. code changes 2. unit tests and add an assisted-by line in the commit before Signed-off by according to open source coding guidelines like the following (we used it to generate the token):
Assisted-by: Codex GPT 6.2 Sol

@cbodley : do the cmake changes look fine?

Replaces the vendored jwt-cpp headers with a git submodule pinned to
the upstream v0.7.3 release.

Update the STS web token engine for the new jwt-cpp API and extract
principal tags in get_principal_tags(). Change recurse_and_insert() to
take std::optional<std::string_view> and check the AWS tags namespace
only at the top level so nested keys matching the namespace and empty
keys are preserved.

Fixes: https://tracker.ceph.com/issues/70910
Signed-off-by: Tahia Khan <[email protected]>
Adds unittest_rgw_web_token, covering claim flattening in
recurse_and_insert(), get_token_claims() and get_principal_tags(),
and RS256 signature validation from JWKS n/e components. Fixes
failing BADINPUT tests in test_rgw_token.

Fixes: https://tracker.ceph.com/issues/70910
Assisted-by: Codex GPT 6.2 Sol
Signed-off-by: Tahia Khan <[email protected]>
@ta1hia
ta1hia force-pushed the wip-70910-rgw-replace-jwt-cpp-with-submodule branch from 99c7ac5 to eace527 Compare December 2, 2026 18:43
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