Repository navigation
rgw/sts: enhancements and improvements to JWT validation - #41525
pritha-srivastava wants to merge 3 commits into
Conversation
mattbenjamin
left a comment
There was a problem hiding this comment.
does this leave any further known gaps wrt, e.g., onelogin?
There was a problem hiding this comment.
it's not very important right now, but this copy could probably be avoided?
There was a problem hiding this comment.
BN_bin2bn gave a compilation error with char*
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
: // ...
{}
@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. |
3af2474 to
94d38e2
Compare
|
I'll put a few specifics in - but 2 general comments: |
There was a problem hiding this comment.
style nit: I don't like ".." in include filenames. Might be best to call this "rgw-jwt.h" instead of "jwt-cpp/jwt.h".
There was a problem hiding this comment.
Or just explicitly #include "rgw/rgw_b64.h"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'd recommend putting __PRETTY_FUNCTION__ << ":" << __LINE__ in these things just so we can find them easily.
There was a problem hiding this comment.
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.
|
|
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. |
There was a problem hiding this comment.
found_valid_cert = get true value if we enter the previous loop? and in line 278 again it will be true?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
94d38e2 to
12682ef
Compare
| std::shared_ptr<EVP_PKEY> pkey; | ||
| /// Hash generator | ||
| const EVP_MD*(*md)(); | ||
| // Modulus |
There was a problem hiding this comment.
NIT: Make these /// style doxygen comments to match the rest.
There was a problem hiding this comment.
I'd recommend putting __PRETTY_FUNCTION__ << ":" << __LINE__ in these things just so we can find them easily.
There was a problem hiding this comment.
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.
|
|
||
| verifier.verify(decoded); | ||
| } | ||
| } catch (std::runtime_error& e) { |
There was a problem hiding this comment.
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.
|
|
||
| string jwks_url = get_jwks_url(iss, dpp, y); | ||
| if (jwks_url.empty()) { | ||
| throw -EINVAL; |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
The issue Marcus raised in response to my question.
@marcus: could we potentially well-define the scenario where there is no chain of intermediates, and restrict validation to that case? |
|
I tried this for authenticating against an openid-server that does not expose an |
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]>
|
The 2nd commit will be squashed once the changes are approved. |
|
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. |
|
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 Here's the 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. |
|
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. |
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).
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. |
|
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.
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? |
|
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. |
Ok.
|
|
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. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
1 similar comment
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
@pritha-srivastava what's left to do here? |
Properly validating the certificate chain is still left to be done. |
|
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. |
|
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! |
|
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. |
|
@pritha-srivastava ping? |
|
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. |
|
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! |
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
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume tox