Skip to content

rgw/sts: enhancements and improvements to JWT validation - #41525

Closed
pritha-srivastava wants to merge 3 commits into
ceph:mainfrom
pritha-srivastava:wip-rgw-sts-signature-validation
Closed

pritha-srivastava wants to merge 3 commits into
ceph:mainfrom
pritha-srivastava:wip-rgw-sts-signature-validation

Conversation

@pritha-srivastava

@pritha-srivastava pritha-srivastava commented May 25, 2021 •

Copy link
Copy Markdown
Contributor

in AssumeRoleWithWebIdentity.

added code for token validation using x5c, x5u, x5t, x5t#S256, kid
in header and x5u and modulus, exponent (for RSA group of algos)
in JWKS (JSON Web Key Set).

Fixes: https://tracker.ceph.com/issues/51018
Signed-off-by: Pritha Srivastava [email protected]

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

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 api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

@mattbenjamin mattbenjamin 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.

does this leave any further known gaps wrt, e.g., onelogin?

Comment thread src/rgw/jwt-cpp/jwt.h Outdated

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.

it's not very important right now, but this copy could probably be avoided?

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.

BN_bin2bn gave a compilation error with char*

Comment thread src/rgw/jwt-cpp/jwt.h Outdated

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 had to add an integer to this constructor to avoid the ambiguous constructor problem, is there a better suggestion for this. This I dont think is elegant.

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.

a tag struct with a good name, maybe? like,

struct i_am_a_good_name_t {};
rs512(const i_am_a_good_name_t&, int number, const std::string& modulus, const std::string& exponent) 
 : // ...
{}

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

does this leave any further known gaps wrt, e.g., onelogin?

@mattbenjamin : I have tried to cover almost everything here from what I could understand of the JWT spec. The ECDSA keys could also come in like the way we have for RSA (like n,e). But I could not find enough information to compute the public key using those params. Since RSA is a more commonly used algorithm, I have addressed that here. I will open a separate PR for the ECDSA algos when I have adequate information. But we should still encourage the IDPs to upload a cert either as x5c or x5u, because in CreateOpenIDConnectProvider, we save the thumbprint of the cert, which we use to verify the certs in x5c and x5u. If we use params such as n, e, we can not use the thumbprint to validate the public key.

@pritha-srivastava
pritha-srivastava force-pushed the wip-rgw-sts-signature-validation branch from 3af2474 to 94d38e2 Compare May 28, 2021 13:58
@mdw-at-linuxbox

Copy link
Copy Markdown
Contributor

I'll put a few specifics in - but 2 general comments:
1/ the cert validation doesn't look right - looks like it's just validating the consistency of the thumbprints
2/ you might consider using rapidjson.

Comment thread src/rgw/jwt-cpp/jwt.h Outdated

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.

style nit: I don't like ".." in include filenames. Might be best to call this "rgw-jwt.h" instead of "jwt-cpp/jwt.h".

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.

Or just explicitly #include "rgw/rgw_b64.h"

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.

+1

Comment thread src/rgw/rgw_rest_sts.cc Outdated

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.

This debug statement looks exactly like the one on line 196. Is the error code logged elsewhere? If not, might be helpful to write it out here.

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'd recommend putting __PRETTY_FUNCTION__ << ":" << __LINE__ in these things just so we can find them easily.

Comment thread src/rgw/rgw_rest_sts.cc Outdated

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.

This debug statement looks exactly like the one on line 192. It would almost certainly be helpful to capture the exception and stringify it out in the message.

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

I'll put a few specifics in - but 2 general comments:
1/ the cert validation doesn't look right - looks like it's just validating the consistency of the thumbprints
2/ you might consider using rapidjson.
I'll explain 1. The cert validation using thumbprints is based on the fact that CreateOpenIdconnectProvider call in RGW takes a list of thumbprints that the IDP will be using to sign the JWT. And later in RGW when the JWT is received the thumbprint of x5c is calculated and verified against the registered thumbprints. If a match is found, then the incoming x5c cert is used to calculate the signature of the token according to the 'algo' in the JWT and the calculated signature is verified against the incoming signature. Everything that I have read online tells me that this is how we can validate the thumbprints - if you know of anything else that we can do with the thumbprint then please let me know.

@mdw-at-linuxbox

Copy link
Copy Markdown
Contributor

My comment re x5c is based on RFC # 7515 which tells me to look at RFC # 5280 for how to validate a certificate chain. There's nothing in there about "thumbprints". What is in there is all about validating a chain of signatures ending in a trust anchor, + some mumbly-foo about making sure issuer/subject match up. { this is the same algorithm used routinely in https to validate certificate chains. }

There is stuff in the openid world about using thumbprints, which at first blush seems somewhat hand-wavey. Some of it, including the aws doc I found, appears to be describing how to register trust anchors. Some of it appears to be using thumbprints in a more generic sense. I gather the rest interface you provide, CreateOpenIDConnectProvider, is intended to register that trust anchor. (the doc you have for that seems a tad sketchy.) What's not obvious to me is if you are correctly handling the case where you have one or more intermediate certificates between your trust anchor and the jwt.

Comment thread src/rgw/rgw_rest_sts.cc Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

found_valid_cert = get true value if we enter the previous loop? and in line 278 again it will be true?

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.

Can you elaborate on that? I don't think I see the issue. It looks like it's false when we enter the loop and breaks out as soon as it's set true, where it will be at 278.

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.

In the version he was looking at, there was an extra line "found_valid_cert = true;" at the end of the loop. That means if there was more than one cert (likely always the case) it would always think it had found a trust anchor. The latest version that pritha pushed removed that line.

If I understand the code that's there now, it will correctly validate that one of the certificates is a trust anchor, but it doesn't validate the chain to see if each signed the previous certificate. If that's what it's doing, then this logic could be fooled by supplying cert[0] = bad-guy, cert[1]=trusted, cert[0] not signed by cert[1].

in AssumeRoleWithWebIdentity.

added code for token validation using x5c, x5u, x5t, x5t#S256, kid
in header and x5u and modulus, exponent (for RSA group of algos)
in JWKS (JSON Web Key Set).

Fixes: https://tracker.ceph.com/issues/51018
Signed-off-by: Pritha Srivastava <[email protected]>
@pritha-srivastava
pritha-srivastava force-pushed the wip-rgw-sts-signature-validation branch from 94d38e2 to 12682ef Compare June 6, 2021 09:02
Comment thread src/rgw/jwt-cpp/jwt.h Outdated
std::shared_ptr<EVP_PKEY> pkey;
/// Hash generator
const EVP_MD*(*md)();
// Modulus

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: Make these /// style doxygen comments to match the rest.

Comment thread src/rgw/rgw_rest_sts.cc Outdated

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'd recommend putting __PRETTY_FUNCTION__ << ":" << __LINE__ in these things just so we can find them easily.

Comment thread src/rgw/rgw_rest_sts.cc Outdated

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.

Can you elaborate on that? I don't think I see the issue. It looks like it's false when we enter the loop and breaks out as soon as it's set true, where it will be at 278.

Comment thread src/rgw/rgw_rest_sts.cc Outdated

verifier.verify(decoded);
}
} catch (std::runtime_error& e) {

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.

Why std::runtime_error here instead of std::exception?

Also catch by const reference (const std::runtime_error& e). A bit of a nitpick. At one time it was thought to increase exception performance but on modern compilers it doesn't seem to make a difference.

Comment thread src/rgw/rgw_rest_sts.cc

string jwks_url = get_jwks_url(iss, dpp, y);
if (jwks_url.empty()) {
throw -EINVAL;

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.

At some point I want to find all the places that are expecting to catch integers and make them stop. (Though this isn't really your problem since it was like that when you got it.)

@adamemerson
adamemerson self-requested a review June 9, 2021 12:01

@adamemerson adamemerson 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.

The issue Marcus raised in response to my question.

@mattbenjamin

Copy link
Copy Markdown
Contributor

My comment re x5c is based on RFC # 7515 which tells me to look at RFC # 5280 for how to validate a certificate chain. There's nothing in there about "thumbprints". What is in there is all about validating a chain of signatures ending in a trust anchor, + some mumbly-foo about making sure issuer/subject match up. { this is the same algorithm used routinely in https to validate certificate chains. }

There is stuff in the openid world about using thumbprints, which at first blush seems somewhat hand-wavey. Some of it, including the aws doc I found, appears to be describing how to register trust anchors. Some of it appears to be using thumbprints in a more generic sense. I gather the rest interface you provide, CreateOpenIDConnectProvider, is intended to register that trust anchor. (the doc you have for that seems a tad sketchy.) What's not obvious to me is if you are correctly handling the case where you have one or more intermediate certificates between your trust anchor and the jwt.

@marcus: could we potentially well-define the scenario where there is no chain of intermediates, and restrict validation to that case?

@scolphoy

Copy link
Copy Markdown

I tried this for authenticating against an openid-server that does not expose an x5c field, but does expose n and e, and have so far been unsuccessful. I'm using the boto3 client with python3, and assume_role_with_web_identity on client side returns with botocore.exceptions.ClientError: An error occurred (Unknown) when calling the AssumeRoleWithWebIdentity operation: Unknown. From the Radosgw log it seems that it starts processing the request the right way, finding the issuer from the id token, finding the correct jwks-endpoint from the issuer's .well-known/openid-configuration, finding the n and e in the keysets, but then suddenly I see parts of some of the trusted CA certificates, some broken characters, and then it apparently check aborts with Failed the auth strategy, reason=-13. I have not yet managed to isolate where my problem is.

@pritha-srivastava

pritha-srivastava commented Jun 11, 2021 •

Copy link
Copy Markdown
Contributor Author

I tried this for authenticating against an openid-server that does not expose an x5c field, but does expose n and e, and have so far been unsuccessful. I'm using the boto3 client with python3, and assume_role_with_web_identity on client side returns with botocore.exceptions.ClientError: An error occurred (Unknown) when calling the AssumeRoleWithWebIdentity operation: Unknown. From the Radosgw log it seems that it starts processing the request the right way, finding the issuer from the id token, finding the correct jwks-endpoint from the issuer's .well-known/openid-configuration, finding the n and e in the keysets, but then suddenly I see parts of some of the trusted CA certificates, some broken characters, and then it apparently check aborts with Failed the auth strategy, reason=-13. I have not yet managed to isolate where my problem is.

This is strange, because the n and e computation has been tested by me and and elsewhere and have succeeded in both the places. Please paste snippets of log here if it is possible for you. I am not sure what it means to see 'parts of the trusted CA certificates'.

Signed-off-by: Pritha Srivastava <[email protected]>
@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

The 2nd commit will be squashed once the changes are approved.

@mdw-at-linuxbox

Copy link
Copy Markdown
Contributor

The only case where x5c.size() == 1 would be valid is if it had a self-signed certificate. People commonly do that for popup dev environments, but I would not expect to see that in an enterprise environment. The only other way to avoid validating the certificate chain would be to require that x5c[0] be the trust anchor. That could work for small to medium scale deployments, but it's going to require due diligence to replace those footprints when they change, which is almost certainly at least yearly (when the certificate expires) . A large scale deployment of openidconnect (google?) seems very likely to have x5c.size() > 1 with a more or less transient x5c[0], so that's the use case you'd likely exclude by punting on certificate chain validation.

The reason I mentioned intermediate certificates is because I don't fully understand what this code is actually doing. It may be validating x5c[0] against the system's capath (or some such). That is certainly not obvious - but since the documentation for registering thumbprints doesn't actually claim to be registering a trust anchor I suppose one could argue it's a documentation problem. But, since the logic doesn't pass x5c[1+] to the certificate validation process, if there's an intermediate certificate involved between x5c[0] & the system capath, this looks like it has to fail. If the code is structured right, the same loop that handles intermediate certificates should handle all the other cases (with no more complexity than just handling the smplier cases), so it was the simplest way I could find to exemplify how "this code looks wrong".

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

The only case where x5c.size() == 1 would be valid is if it had a self-signed certificate. People commonly do that for popup dev environments, but I would not expect to see that in an enterprise environment. The only other way to avoid validating the certificate chain would be to require that x5c[0] be the trust anchor. That could work for small to medium scale deployments, but it's going to require due diligence to replace those footprints when they change, which is almost certainly at least yearly (when the certificate expires) . A large scale deployment of openidconnect (google?) seems very likely to have x5c.size() > 1 with a more or less transient x5c[0], so that's the use case you'd likely exclude by punting on certificate chain validation.

The reason I mentioned intermediate certificates is because I don't fully understand what this code is actually doing. It may be validating x5c[0] against the system's capath (or some such). That is certainly not obvious - but since the documentation for registering thumbprints doesn't actually claim to be registering a trust anchor I suppose one could argue it's a documentation problem. But, since the logic doesn't pass x5c[1+] to the certificate validation process, if there's an intermediate certificate involved between x5c[0] & the system capath, this looks like it has to fail. If the code is structured right, the same loop that handles intermediate certificates should handle all the other cases (with no more complexity than just handling the smplier cases), so it was the simplest way I could find to exemplify how "this code looks wrong".

This code is not completely wrong, but yes it does not validate a chain of certs, it only validates a cert when x5c[0] is the trust anchor. As discussed with @mattbenjamin , can I target that bit of code for another PR after opening a tracker issue for the same, and have this merged after running tests, unless @scolphoy has further comments on the modulus and exponent part. This PR was mainly targeted at token validation using modulus and exponent. And I have addressed other comments related to styling and log messages.

@scolphoy

Copy link
Copy Markdown

Hi, sorry for taking a while to get back to this. Here's some log of a failed assume_role_with_web_identity. I cleaned my id token from the log, but originally it showed as parsed properly. Towards the end of the log, some certificate begin- and end-lines appear abruptly, they seem to match with those found in /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt, which I believe openssl is using while trying to verify something in our oidc-servers response.

Here's the log:
scolphoy-openidassumerolewithwebid-error.log

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

Hi, sorry for taking a while to get back to this. Here's some log of a failed assume_role_with_web_identity. I cleaned my id token from the log, but originally it showed as parsed properly. Towards the end of the log, some certificate begin- and end-lines appear abruptly, they seem to match with those found in /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt, which I believe openssl is using while trying to verify something in our oidc-servers response.

Here's the log:
scolphoy-openidassumerolewithwebid-error.log

@scolphoy : I checked the logs and I can see this line: Cert URL is: https://test-user-auth.csc.fi/idp/profile/oidc/keyset. If you check the code here, I have removed the line 'Cert URL is': and replaced it with 'JWKS URL is:'. Are you sure that you used this PR for testing e, and n? I think you still have the old code.

@scolphoy

Copy link
Copy Markdown

Thanks for checking the log. I was pretty sure, but I guess I've messed up somewhere. I'll start over and try to get back tomorrow.

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

I was suggesting storing the thumbprint in the CreateOpenIdConnectProvider call, yes.

And you're right, looks like AWS is not using JWK thumbprints either. It seems that instead they are using thumbprints of the X509 certificate that is used to authenticate the HTTPS connection to the ID provider's endpoint, i.e. they seem to be pinning what is a trusted channel for delivering the public keys, rather than pinning the public keys themselves. I suppose this works too, just that these certificates tend to get renewed relatively frequently these days and would have to be updated to rgw each time.

What I was actually thinking about was using JWK thumbprints, which can be derived from the e, kty and n fields of a key, storing the thumbprint when the id provider is added, and calculating and comparing the thumbprint again when fetching the jwks_keys as part of verifying a token. I'm not sure if it would be possible to derive this from the x5c field. These would pin us to the keys used for signing the tokens, rather than to the connection through which those keys are delivered. But since this doesn't seem to be what AWS is doing after all, if we want to be compatible, perhaps we shouldn't do it now either.

I had checked and couldn't find deriving the thumbprint from x5c for a public key to be possible (if i am understanding correctly what you mean), I will double check again. Meanwhile I will also discuss with my team members if we can store the thumbprint of the public key while creating a openidconnectprovider in RGW (after all its a thumbprint).

There is no guarantee that the X509 certificate used to authenticate the connection and the X509 certificate used to sign the tokens would be the same certificate, especially since you can serve tokens for many realms (with hopefully separate keys) from the same id provider. I believe computing the thumbprint from the x5c field would be wrong. Instead the correct X509 certificate should be found from the parameters of the underlying HTTPS connection when connecting to the the jwks_keys endpoint and the thumbprint computed from that. With a quick search, I can find shell scripts that do this (e.g. here), but how to integrate it properly in rgw would need more work.

If you are talking about the current x5c cert validation - yes there is a gap. Right now it only addresses the case when there is a single cert which is the cert that signs the tokens and the root CA. I plan to open a tracker issue and address this properly in another PR which takes the thumbprint and validates the certificate chain in the incoming token according to the RFC. Other reviewers have raised this point here.

@scolphoy

scolphoy commented Jun 24, 2021 •

Copy link
Copy Markdown

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.

  1. The X509 thumbprint one can compute from a certificate in the x5c chain
  2. The JWK thumbprint one can compute from e, kty and n
  3. 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.

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

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.

  1. The X509 thumbprint one can compute from a certificate in the x5c chain
  2. The JWK thumbprint one can compute from e, kty and n
  3. 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.

So if there is a single certificate in the certificate chain (like self signed certs) 1 and 3 become the same and that is what has been addressed here in RGW so far. ( I have checked using the instructions given in AWS documentation). As I told before we know this is a gap, and we intend to address this in another PR where we will cover other cases when we store the root CA thumbprint (following AWS instructions) while creating an openidconnectprovider in rgw, and then later when we verify the x5c certs in the incoming token, we need to check the thumbprint of the root CA in the x5c certs as well as verify each intermediate certificate in the certificate chain.

Meanwhile, I will add the thumbprint verification for n and e using n, kty and e to this PR.

@pritha-srivastava

pritha-srivastava commented Jun 24, 2021 •

Copy link
Copy Markdown
Contributor Author

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.

  1. The X509 thumbprint one can compute from a certificate in the x5c chain
  2. The JWK thumbprint one can compute from e, kty and n
  3. 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.

So if there is a single certificate in the certificate chain (like self signed certs) 1 and 3 become the same and that is what has been addressed here in RGW so far. ( I have checked using the instructions given in AWS documentation). As I told before we know this is a gap, and we intend to address this in another PR where we will cover other cases when we store the root CA thumbprint (following AWS instructions) while creating an openidconnectprovider in rgw, and then later when we verify the x5c certs in the incoming token, we need to check the thumbprint of the root CA in the x5c certs as well as verify each intermediate certificate in the certificate chain.

Meanwhile, I will add the thumbprint verification for n and e using n, kty and e to this PR.

Or are you saying that even for n,e we can store the thumbprint according to AWS documentation, and then we can use the jwks_uri and compute the thumbprint and validate it against the one stored? And that there is no need for public key fingerprint verification using n, e and kty?

@scolphoy

scolphoy commented Jun 24, 2021 •

Copy link
Copy Markdown

Yes, even with n,e, we can use the AWS documentation and what I described as type 3 above.

There would be no need to compute using n, e and kty ; unless we want to also lock on to the particular signature scheme and particular keys, instead of just particular endpoint on where to find the keys. It's a tradeoff. Seems AWS is not doing this.

Also I don't think what you said about type 1 and type 3 becoming the same is generally true. For example, if CSC and Red hat wanted to use a shared OpenID provider, but separate realms, we might want to have one certificate for the https endpoint, one for signing tokens for the CSC realm and one for signing tokens for the Red hat realm. In this case we would have two type 1 certificates/thumbprints and one type 3, and these would all be different. In a single realm setup one might put the same certificate for the token signing and for the web server, in which case they indeed would become the same, but it sounds like a bad practice and we should not assume that anyone does that.

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

Yes, even with n,e, we can use the AWS documentation and what I described as type 3 above.

Ok.

There would be no need to compute using n, e and kty ; unless we want to also lock on to the particular signature scheme and particular keys, instead of just particular endpoint on where to find the keys. It's a tradeoff. Seems AWS is not doing this.

Also I don't think what you said about type 1 and type 3 becoming the same is generally true. For example, if CSC and Red hat wanted to use a shared OpenID provider, but separate realms, we might want to have one certificate for the https endpoint, one for signing tokens for the CSC realm and one for signing tokens for the Red hat realm. In this case we would have two type 1 certificates/thumbprints and one type 3, and these would all be different. In a single realm setup one might put the same certificate for the token signing and for the web server, in which case they indeed would become the same, but it sounds like a bad practice and we should not assume that anyone does that.
Ok.

@scolphoy

Copy link
Copy Markdown

Come to think of it, what we now have in this PR is already a significant improvement over what was there before. I'd be happy to see this merged soon. It does now check that the tokens are valid and signed properly. To replace the accepted signing keys from the outside, one would have to redirect the jwks_keys query to their own endpoint and also have a valid, even if not pinned, certificate for the domain so that libcurl will accept to fetch the keys. My biggest concern with this is that someone is going to deploy this and then neglect following the state of the providers on their list properly.

If the thumbprint validation is going to be a separate pull request, I'm ok with that. Though I do maintain that there is a difference between thumbprinting from the x5c chain and thumbprinting form the certificate from the TLS handshake with the endpoint (what AWS does). The latter is more generic, doesn't make us depend on the x5c field being present, and doesn't lock us to a particular key, but to a particular key delivery endpoint.

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

Come to think of it, what we now have in this PR is already a significant improvement over what was there before. I'd be happy to see this merged soon. It does now check that the tokens are valid and signed properly. To replace the accepted signing keys from the outside, one would have to redirect the jwks_keys query to their own endpoint and also have a valid, even if not pinned, certificate for the domain so that libcurl will accept to fetch the keys. My biggest concern with this is that someone is going to deploy this and then neglect following the state of the providers on their list properly.

If the thumbprint validation is going to be a separate pull request, I'm ok with that. Though I do maintain that there is a difference between thumbprinting from the x5c chain and thumbprinting form the certificate from the TLS handshake with the endpoint (what AWS does). The latter is more generic, doesn't make us depend on the x5c field being present, and doesn't lock us to a particular key, but to a particular key delivery endpoint.

I have created a tracker issue here: https://tracker.ceph.com/issues/51346 for tracking the thumbprint validation code. Please feel free to take it up if you can before I get to it. And thanks for all the input.

@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

1 similar comment
@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

@cbodley

cbodley commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

@pritha-srivastava what's left to do here?

@pritha-srivastava

Copy link
Copy Markdown
Contributor Author

@pritha-srivastava what's left to do here?

Properly validating the certificate chain is still left to be done.

@djgalloway
djgalloway changed the base branch from master to main July 4, 2022 00:00
@github-actions

github-actions Bot commented Sep 2, 2022

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 Sep 2, 2022
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Nov 28, 2022
@mattbenjamin mattbenjamin reopened this Dec 17, 2022
@github-actions github-actions Bot removed the stale label Dec 17, 2022
@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 Feb 15, 2023
@mattbenjamin

Copy link
Copy Markdown
Contributor

@pritha-srivastava ping?

@github-actions github-actions Bot removed the stale label Feb 15, 2023
@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 Apr 17, 2023
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

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.

8 participants