Skip to content

rgw: extending STS support for AssumeRoleWithWebIdentity - #60985

Closed
awojno-bloomberg wants to merge 4 commits into
ceph:mainfrom
awojno-bloomberg:extending-sts
Closed

awojno-bloomberg wants to merge 4 commits into
ceph:mainfrom
awojno-bloomberg:extending-sts

Conversation

@awojno-bloomberg

@awojno-bloomberg awojno-bloomberg commented Dec 6, 2024 •

Copy link
Copy Markdown
Contributor

In order to support the enhancement, the jwt-cpp library was updated to the latest version and the code was updated to reflect that. The relevant changes to the STS logic include:

-- Adding support for matching JWT to JWK key id. Per RFC 7515, the kid field is used as a hint to which JWK to be used. While the use is optional, the implication seems to be that if present, it should be used to match to a corresponding JWK kid. If kid is present in the JWT but not able to be matched to a JWK, this is a verification failure.

-- Added RSA bare key validation. Per RFC 7517 the x5c JWK parameter is optional. If not present and the key is an RSA key type (RS256/384/512), then the n and e values can be used to generate a public key that can be used for signature verification.

-- Extended the existing x5c validation with new logic to search all of the JWKs for a x5c certificate that matches the thumbprints. Per RFC 7517, the first certificate in the x5c parameter is the one containing the key value to be used for verification.


Addresses: https://tracker.ceph.com/issues/54562
-- The previous logic did not check all of the JWKs correctly. This was extended to loop through all of the JWKs when applicable.

Addresses: https://tracker.ceph.com/issues/69106
-- x5c is an optional field but RGW STS logic assumes it is mandatory. There are other ways to validate a JWT other than x5c, such as bare key validation. Support for that is added.

Enhancement: Use Key ID to match.
-- JWT Key ID provides a hint as to which JWK to use. This field when present should be used to match the JWK. This provides faster checking as not every JWK needs to be checked.

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
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

Adding support for matching JWT to JWK by key ID.
Adding support for RSA bare key validation.
Updating current x5c logic to search all JWKS by thumbprint.

Signed-off-by: Alex Wojno <[email protected]>
@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@pritha-srivastava

Copy link
Copy Markdown
Contributor

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

I updated the summary with more information in the second section about what issues we ran into and how this PR addresses those issues and linked a tracker that describes the x5c optional issue. When solving these issues, I tried to conform to the JWT standard as much as possible and referenced the relevant RFCs.

As far as trust chaining for AWS, JWT is an industry standard so the way trust is established with JWKs should conform to that standard. Maybe I'm missing something here so please correct me if so. I didn't change any of the previous logic with regards to using thumbprints to check for matches against the x5c certs but with the lack of x5c field, that logic wouldn't apply.

@pritha-srivastava

pritha-srivastava commented Dec 16, 2024 •

Copy link
Copy Markdown
Contributor

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

I updated the summary with more information in the second section about what issues we ran into and how this PR addresses those issues and linked a tracker that describes the x5c optional issue. When solving these issues, I tried to conform to the JWT standard as much as possible and referenced the relevant RFCs.

As far as trust chaining for AWS, JWT is an industry standard so the way trust is established with JWKs should conform to that standard. Maybe I'm missing something here so please correct me if so. I didn't change any of the previous logic with regards to using thumbprints to check for matches against the x5c certs but with the lack of x5c field, that logic wouldn't apply.

As mentioned in AWS documentation, which I think is not very obvious but has been pointed out in tracker https://tracker.ceph.com/issues/69106, AWS secures communication with OIDC identity providers (IdPs) using our library of trusted root certificate authorities (CAs) to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. If your OIDC IdP relies on a certificate that is not signed by one of these trusted CAs, only then we secure communication using the thumbprints set in the IdP's configuration. in https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateOpenIDConnectProvider.html#API_CreateOpenIDConnectProvider_RequestParameters, it states that "verify the JSON Web Key Set (JWKS) endpoint's TLS certificate", in our case using the thumbprint configured while creating openid connect provider. Is that being done in the changes done by you (To me it appears the previous x5c logic has been extended)

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

I updated the summary with more information in the second section about what issues we ran into and how this PR addresses those issues and linked a tracker that describes the x5c optional issue. When solving these issues, I tried to conform to the JWT standard as much as possible and referenced the relevant RFCs.
As far as trust chaining for AWS, JWT is an industry standard so the way trust is established with JWKs should conform to that standard. Maybe I'm missing something here so please correct me if so. I didn't change any of the previous logic with regards to using thumbprints to check for matches against the x5c certs but with the lack of x5c field, that logic wouldn't apply.

As mentioned in AWS documentation, which I think is not very obvious but has been pointed out in tracker https://tracker.ceph.com/issues/69106, AWS secures communication with OIDC identity providers (IdPs) using our library of trusted root certificate authorities (CAs) to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. If your OIDC IdP relies on a certificate that is not signed by one of these trusted CAs, only then we secure communication using the thumbprints set in the IdP's configuration. in https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateOpenIDConnectProvider.html#API_CreateOpenIDConnectProvider_RequestParameters, it states that "verify the JSON Web Key Set (JWKS) endpoint's TLS certificate", in our case using the thumbprint configured while creating openid connect provider. Is that being done in the changes done by you (To me it appears the previous x5c logic has been extended)

RE: AWS secures communication with OIDC identity providers (IdPs) using our library of trusted root certificate authorities (CAs) to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. : I believe that's due to the nature of AWS being a public cloud solution so it maintains those common certs so I don't believe that needs to implemented in Ceph.

For the extension to the x5c logic, I only updated it so that each JWK has the x5c checked to fix tracker https://tracker.ceph.com/issues/54562. Previously only the first JWK was tested according to the tracker. The x5c logic does use the thumbprint for validation to make sure the certificates match. Not quite sure about that logic but this PR didn't fundamentally change (or at least it was not my intention) the thumbprint logic with x5c. Perhaps the bare key validation should follow the thumbprint logic with the generated cert.

@pritha-srivastava

Copy link
Copy Markdown
Contributor

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

I updated the summary with more information in the second section about what issues we ran into and how this PR addresses those issues and linked a tracker that describes the x5c optional issue. When solving these issues, I tried to conform to the JWT standard as much as possible and referenced the relevant RFCs.
As far as trust chaining for AWS, JWT is an industry standard so the way trust is established with JWKs should conform to that standard. Maybe I'm missing something here so please correct me if so. I didn't change any of the previous logic with regards to using thumbprints to check for matches against the x5c certs but with the lack of x5c field, that logic wouldn't apply.

As mentioned in AWS documentation, which I think is not very obvious but has been pointed out in tracker https://tracker.ceph.com/issues/69106, AWS secures communication with OIDC identity providers (IdPs) using our library of trusted root certificate authorities (CAs) to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. If your OIDC IdP relies on a certificate that is not signed by one of these trusted CAs, only then we secure communication using the thumbprints set in the IdP's configuration. in https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateOpenIDConnectProvider.html#API_CreateOpenIDConnectProvider_RequestParameters, it states that "verify the JSON Web Key Set (JWKS) endpoint's TLS certificate", in our case using the thumbprint configured while creating openid connect provider. Is that being done in the changes done by you (To me it appears the previous x5c logic has been extended)

RE: AWS secures communication with OIDC identity providers (IdPs) using our library of trusted root certificate authorities (CAs) to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. : I believe that's due to the nature of AWS being a public cloud solution so it maintains those common certs so I don't believe that needs to implemented in Ceph.

Well, I am not talking about verification using trusted root certs in AWS, if they are not there then there is an alternative given to use the thumbprint configured in the IDP to verify the JSON Web Key Set (JWKS) endpoint's TLS certificate. We need to have a discussion around this before concluding anything as we would like to maintain compatibility with AWS as much as possible. @mattbenjamin @mdw-at-linuxbox can you weigh in here? what is the correct thing to do?

For the extension to the x5c logic, I only updated it so that each JWK has the x5c checked to fix tracker https://tracker.ceph.com/issues/54562. Previously only the first JWK was tested according to the tracker. The x5c logic does use the thumbprint for validation to make sure the certificates match. Not quite sure about that logic but this PR didn't fundamentally change (or at least it was not my intention) the thumbprint logic with x5c. Perhaps the bare key validation should follow the thumbprint logic with the generated cert.

@pritha-srivastava

pritha-srivastava commented Dec 17, 2024 •

Copy link
Copy Markdown
Contributor

If you follow the discussion on this PR: #41525, even here it has been pointed out that AWS uses the thumbprints to verify the jwks_keys https endpoint:

I checked the other reviewers comments, and what I'm talking about is something else. I'm not talking about validating the certificate chain in the x5c field.

As I see it, there are three kinds of thumbprints involved.

The X509 thumbprint one can compute from a certificate in the x5c chain
The JWK thumbprint one can compute from e, kty and n
The X509 thumbprint one can compute from the X509 certificate (the SSL/TLS-certificate) used for the https connection to the jwks_keys endpoint that delivers all the other keys and certificates

Types 1 and 2 are used to pin to the keys used to verify tokens, the type 3 is used to pin to the delivery channel for keys used to verify tokens, but not the keys themselves. Type 1 is possible only for providers that provide the x5c field. Type 2 is available with or without the x5c field; if x5c is provided it is expected to be configured properly, so that the key in the root certificate matches the key made of e and n. JWK thumbprints are of different length than X509 thumbprints, so our current "exactly 40 characters" in the thumbprints would not support JWK thumbprints.

Type 3 is the lowest common denominator that works regardless of what fields our jwks_keys endpoint supports, if the x5c field is there or not, what signature scheme (if any) we use, and so on. It pins the delivery of the verification keys saying "trust whatever this https endpoint says, but only if it's secured using these certificates in particular" and means that if someone later gains rightful access to the domain and gets a new valid certificate for it, the thumbprint-check would be the last line of defence that prevents us from accidentally trusting them.

Judging by AWS instructions, seeing how they are using an X509 thumbprint and how they are not extracting the x5c field in any of the steps, but are computing a fingerprint from one of the certificates returned when connecting to the jwks_keys https endpoint, they must be using type 3. If we want to do it the same way as AWS, this is what we should do too. The particular certificates used in type 1 and type 3 are very likely different, and that's why using the x5c field for computing the thumbprint would very likely cause at least the above AWS instructions to fail in many cases.

@bootc

bootc commented Dec 20, 2024 •

Copy link
Copy Markdown

Addresses: https://tracker.ceph.com/issues/69106

As @pritha-srivastava points out, this PR doesn't seem to address my bug; it does make the x5c field optional but just geerates a hash from the keys retrieved from the jwks endpoint, whereas for compatibility with AWS it should be generating a hash from the TLS certificate(s) on the HTTPS endpoint, and not looking at the contents of the request at all.

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

Addresses: https://tracker.ceph.com/issues/69106

As @pritha-srivastava points out, this PR doesn't seem to address my bug; it does make the x5c field optional but just geerates a hash from the keys retrieved from the jwks endpoint, whereas for compatibility with AWS it should be generating a hash from the TLS certificate(s) on the HTTPS endpoint, and not looking at the contents of the request at all.

There seem to be two steps to STS:

  1. The JWKS endpoint needs to be validated using the thumbprint provided during OIDC creation to ensure trust of the JWKS endpoint. This is using the TLS certificate of the JWKS endpoint to ensure it matches with the key.

  2. Once the JWKS endpoint trust is established, the signature of the JWT token must be validated. This is done through standard RFC approaches of using the JWKs. AWS provides some documentation here but there are more ways to do so.

The current RGW logic is to use the thumbprint to match the JWKs' x5c. This implies the assumption that the same certificate is used as the TLS certificate for the JWKS endpoint and also a certificate added as a JWK. This is a strong assumption that won't be correct for most set ups. Instead, we should use this thumbprint to validate the JWKS url only. This has not been done in my PR currently but can be another tracker.

The changes in my PR address the second step, which involves JWT validation, which should be based on the outstanding RFCs. @bootc , I would question that AWS just validates the JWKS url with the thumbprint without looking at the contents as that tells one nothing about the validity of the JWT token. Both are important steps that could use improvement.

@bootc

bootc commented Dec 20, 2024

Copy link
Copy Markdown

@bootc , I would question that AWS just validates the JWKS url with the thumbprint without looking at the contents as that tells one nothing about the validity of the JWT token. Both are important steps that could use improvement.

Right, I meant the actual JWKs don't factor into the fingerprint comparison, only the HTTPS TLS certificates do. Once the endpoint has been validated the JWKs are then trusted to validate the JWT in the request.

These days AWS also have a set of trusted roots so fingerprints are unnecessary at all in many cases, but I think it would be fine to add that later.

@pritha-srivastava

Copy link
Copy Markdown
Contributor

Addresses: https://tracker.ceph.com/issues/69106

As @pritha-srivastava points out, this PR doesn't seem to address my bug; it does make the x5c field optional but just geerates a hash from the keys retrieved from the jwks endpoint, whereas for compatibility with AWS it should be generating a hash from the TLS certificate(s) on the HTTPS endpoint, and not looking at the contents of the request at all.

There seem to be two steps to STS:

  1. The JWKS endpoint needs to be validated using the thumbprint provided during OIDC creation to ensure trust of the JWKS endpoint. This is using the TLS certificate of the JWKS endpoint to ensure it matches with the key.
  2. Once the JWKS endpoint trust is established, the signature of the JWT token must be validated. This is done through standard RFC approaches of using the JWKs. AWS provides some documentation here but there are more ways to do so.

The signature must be validated and there should be a way to validate that the token is originating from the OIDC provider registered with rgw. ( We do match the 'aud' claim and use the 'iss' claim to fetch the oidc provider info registered with rgw).

And for the different ways to validate the signature, some work following RFC https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.1 has been done in the PR: #41525

The current RGW logic is to use the thumbprint to match the JWKs' x5c. This implies the assumption that the same certificate is used as the TLS certificate for the JWKS endpoint and also a certificate added as a JWK. This is a strong assumption that won't be correct for most set ups. Instead, we should use this thumbprint to validate the JWKS url only. This has not been done in my PR currently but can be another tracker.

The changes in my PR address the second step, which involves JWT validation, which should be based on the outstanding RFCs. @bootc , I would question that AWS just validates the JWKS url with the thumbprint without looking at the contents as that tells one nothing about the validity of the JWT token. Both are important steps that could use improvement.

@pritha-srivastava

Copy link
Copy Markdown
Contributor

@awojno-bloomberg:

  1. Can you list out what issues this PR addresses?
  2. The tracker that you have referenced in the ticket, is meant for the wrong certificate being picked and does not mention the modulo and exponent parts, so please reference other trackers for this
  3. Does this PR handle trust chaining in the AWS compliant way?
  4. I had pointed out that there is a PR addressing the modulo and exponent changes here: rgw/sts: enhancements and improvements to JWT validation #41525, so please give credit to that work.

I updated the summary with more information in the second section about what issues we ran into and how this PR addresses those issues and linked a tracker that describes the x5c optional issue. When solving these issues, I tried to conform to the JWT standard as much as possible and referenced the relevant RFCs.

As far as trust chaining for AWS, JWT is an industry standard so the way trust is established with JWKs should conform to that standard. Maybe I'm missing something here so please correct me if so. I didn't change any of the previous logic with regards to using thumbprints to check for matches against the x5c certs but with the lack of x5c field, that logic wouldn't apply.

The trust chaining that I am referring to is actually there in the RFC https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.6 which states that The certificate containing the public key corresponding to the key used to digitally sign the JWS MUST be the first certificate. This MAY be followed by additional certificates, with each subsequent certificate being the one used to certify the previous one. The recipient MUST validate the certificate chain according to [RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280) [[RFC5280](https://datatracker.ietf.org/doc/html/rfc5280)] and consider the certificate or certificate chain to be invalid if any validation failure occurs.

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

Update: I pushed a commit that changes the core logic to address the changes we have been discussing. The main changes are:

  • Using the thumbprint to validate the JWKS endpoint (this is currently stubbed and to be implemented).
  • Using x5c field to validate signature. The standard does require validating the whole chain as @pritha-srivastava mentions but I would think this is out of scope for the issues I am trying to address in this PR (would be happy to open up a separate tracker). I left this logic in to deal with non-RSA algorithms so that they can be validated using the first certificate in the x5c array, which is the signing certificate.
  • Maintaining the bare key validation for RSA algorithms and the kid field logic.

FYI @bootc

@github-actions

github-actions Bot commented Mar 3, 2025

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 Mar 3, 2025
@awojno-bloomberg
awojno-bloomberg marked this pull request as ready for review March 10, 2025 20:16
@awojno-bloomberg
awojno-bloomberg requested a review from a team as a code owner March 10, 2025 20:16
@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

Apologies for the delay in publishing the PR. I was able to successfully test the use cases that the PR addressed. Please take a look when you get a chance @pritha-srivastava @adamemerson

@adamemerson

Copy link
Copy Markdown
Contributor

Apologies for the delay in publishing the PR. I was able to successfully test the use cases that the PR addressed. Please take a look when you get a chance @pritha-srivastava @adamemerson

Do you have something we could add to our test suite?

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@awojno-bloomberg

Copy link
Copy Markdown
Contributor Author

Closed in favor of #63047

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.

4 participants