-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support "user_claim_json_pointer" in create_role() for JWT/OIDC auth method #1006
Conversation
Apologies for issues on the branch changes, there should not have been any need to rename or change your original branch on the other PR. Though it is recommended to always create a new branch in your fork for your PRs, instead of using the default branch. Thanks for sticking with us through it all! |
One info about "make test". hvac/tests/utils/server_manager.py Lines 57 to 59 in 31aca14
Without understanding the reasons, when I removed the redirect of stdout and stderr, which means, the server output is displayed together with the test output, then it worked. :-)
the jwt and oidc tests were executed successfully. |
No problem. The few changes were quickly reapplied to the main branch. |
Thank you very much for reporting the problem with running the tests locally, I've opened a separate issue for that, please feel free to subscribe to it or add any additional info you might have: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor docstring changes but otherwise it looks good to me. Since the new parameter was added in Vault 1.11.x I was worried that maybe it would fail against older versions but the integration tests seemed to pass on those earlier versions.
I do wish we had more testing the of the parameter itself, but I don't have a lot of experience with OIDC/JWT auth in Vault. If you have an idea how we could add some actual tests for that it'd be great.
uhhh, good point. Thinking about this I also would expect the old version to fail. It depends on how unknown parameters are treated.
I can add some tests. But the current JWT used in the test is flat, no hierarchical values, which would need JSON Pointer. So, I also have to change this. |
I spent some more time looking at the test implementation yesterday, and to be honest I'm having trouble following it. I am wondering if the reason it didn't fail on the earlier versions of Vault is because some part of the process is being mocked out, but I wasn't able to tell definitively. As you said, adding an integration test is testing the server and not really our code; I am most interested in ensuring that 1) the code as written (without guarding for version number in our logic) will work with the earlier versions of Vault we still support, and 2) that our code consistently passes the parameters through, to prevent regressions. For 2), I would prefer that be in a unit test, but no unit tests exist for this auth method yet, and that isn't being tested for any other parameters, so I cannot expect that to be a blocker for this PR. If you are interested in adding units, that would be very appreciated but not required. In that case I would say to prefer pytest style rather UnitTest style which is currently in use, unless using UnitTest style would be easier due to it already being in the project as an example. If you are able to manually test this change against our oldest CI version of Vault (even a |
I run the jwt integration test against a manually started vault and I can see, that the create_role request is received. I run the testsuite against a vault version 1.4.7 without any problems.
The two parameters Also tested with curl to add an "unknown_parameter":
This works without problems. So, unknown keys are just ignored. |
About adding pytests: I am not experienced with this. Do you have a reference, which I can use as a template. |
I applied your proposed changes and created an initial unit test for jwt validating, that the parameter "user_claim_json_pointer" is contained in the http request according to the set value. Also I changed the default value for user_claim_json_pointer to None, so it behaves identical to the parameter "token_no_default_policy", which is also of type bool and the documented default value is "false". But the default value is set on server side and not in the python sdk. Also this ensures another layer of compatibility. If the parameter is "None" it will not be submitted in the request. So, even if unknown parameters are checked in older versions, as long, as it is not set, it is compatible. |
Codecov Report
@@ Coverage Diff @@
## main #1006 +/- ##
=======================================
Coverage 84.70% 84.70%
=======================================
Files 65 65
Lines 3066 3066
=======================================
Hits 2597 2597
Misses 469 469
|
unittests for JWT.create_role()
Co-authored-by: Brian Scholer <[email protected]>
Co-authored-by: Brian Scholer <[email protected]>
Co-authored-by: Brian Scholer <[email protected]>
Co-authored-by: Brian Scholer <[email protected]>
Co-authored-by: Brian Scholer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're good to go here. Thanks again @ferenc-hechler for the contribution (and adding tests) and your patience! Thanks to @adammike for helping me out with review .
This is a follow-up to PR #998 which was broken due to my attempts to switch from develop to main branch.
When creating a role for the JWT auth method, the optional parameter "user_claim_json_pointer" is missing.
See documentation here:
https://developer.hashicorp.com/vault/api-docs/auth/jwt#user_claim_json_pointer
The parameter is a bool value which defaults to false.
This pull request adds the missing parameter. I tested it for JWT auth and it works.
The OIDC auth mehod inherits create_role() from JWT.
So, I also added this parameter to ODIC.create_role().
The OIDC use case was not tested.
Documentation was updated.