Skip to content
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

fix vault client certificates loaded from envirnoment variables #943

Merged
merged 6 commits into from
Mar 1, 2023

Conversation

BrandonHoffman
Copy link
Contributor

@BrandonHoffman BrandonHoffman commented Feb 11, 2023

It seems like the hvac library does not handle the VAULT_CLIENT_CERT and VAULT_CLIENT_KEY variables properly.

  • public/private key-pairs in requests need to be passed as a tuple
  • environment variables are overriding the values directly passed in

Fixes #938
Fixes #787

@BrandonHoffman BrandonHoffman requested a review from a team as a code owner February 11, 2023 02:44
@BrandonHoffman
Copy link
Contributor Author

#938

and

#787

are both related

@briantist
Copy link
Contributor

@BrandonHoffman welcome and thanks for submitting this! I've been away traveling but I intend to take a look at the backlog some more after I get back and get caught up on other things, so it might take a little while but I will review this!

In the meantime run petry run black . and poetry run flake8 . to check for some formatting lint errors.

@BrandonHoffman
Copy link
Contributor Author

@briantist - no worries, just know we were hitting issues with this in my org and figured it would effect others. The fmt/lint issue is fixed.

@BrandonHoffman
Copy link
Contributor Author

also fixed an integration test issue related to integration tests running in python 3.7 which does not support the nested with syntax I initially used.

Copy link
Member

@adammike adammike left a comment

Choose a reason for hiding this comment

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

I can't imagine how that original code worked, with the list split into a string like that. @briantist I've reviewed this. The code looks good, and I've validated that what's being passed to the adapter is what requests is expecting.

Rather than change all tests to use the environment, we should add new tests for this use case specifically - mTLS authentication with the certs passed to the client as parameters, and mtls with the certs passed in the environment.

Another issue I have, and this is not aimed at this committer, we are implicitly passing authentication parameters from the adapter to the requests session. While functional and technically not a bug, Its best practice to be implicit with authentication and authorization parameters.

@adammike
Copy link
Member

The issue with the implicit auth parameters does not need to be fixed in this PR, just pointing out the issue. It should probably be tracked as a security enhancement bug.

@BrandonHoffman
Copy link
Contributor Author

BrandonHoffman commented Feb 14, 2023

Hey @adammike,

toggling everything to use the environment variables was actually a mistake...... accidentally checked in the global toggle to true that I used locally just to validate everything was working with this flow.

I actually only intended for this one subclass to be the test case for using the environment variables since it seemed like it would be enough to validate this flow.

https://github.com/hvac/hvac/pull/943/files#diff-f12f973ead75ad35d6886ad63a746f8a3c2f540b4ea538845ac6346353a65a74R158

@adammike
Copy link
Member

Looks good to me!

@codecov
Copy link

codecov bot commented Feb 18, 2023

Codecov Report

Merging #943 (c765e42) into develop (b11a2ec) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #943      +/-   ##
===========================================
+ Coverage    83.60%   83.67%   +0.06%     
===========================================
  Files           65       65              
  Lines         3007     3007              
===========================================
+ Hits          2514     2516       +2     
+ Misses         493      491       -2     
Impacted Files Coverage Δ
hvac/v1/__init__.py 88.53% <100.00%> (+1.27%) ⬆️

briantist
briantist previously approved these changes Feb 18, 2023
Copy link
Contributor

@briantist briantist left a comment

Choose a reason for hiding this comment

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

This all looks good! Thanks for this fix @BrandonHoffman .

The only thing I want to consider before merging is whether we're able to release this in a minor version or whether we should wait until a major out of an abundance of caution.

It's technically a breaking change. It should only hit someone who:

  • is passing values for these both directly and in environment variables
  • is passing the desired values in environment variables
  • is passing undesired values directly

While the remedy is clear for such a use case, the change is still unexpected for that user.

In any case we'll get this out as soon as we can!

@briantist
Copy link
Contributor

@adammike is there anything else you'd like to review here?
If not, could you approve or dismiss your previous review?

Any thoughts on the breaking change consideration I posted above?

@briantist
Copy link
Contributor

Fixes #938
Fixes #787

@BrandonHoffman @adammike I don't see any reason why merging this shouldn't close the issues above, do you agree?

@BrandonHoffman
Copy link
Contributor Author

So, @briantist you’re a lot more familiar with the code base then I am. But here is my 2 cents, from what I have seen any case where the environment variables are set results in a traceback so I don’t believe that anyone using the library as it is now could use the environment variable without having A trace back occur. That leads me to believe it should be safe, but maybe there is some edge case I’m not considering.

@BrandonHoffman
Copy link
Contributor Author

I think both those issues should be addressed with this.

@briantist
Copy link
Contributor

from what I have seen any case where the environment variables are set results in a traceback so I don’t believe that anyone using the library as it is now could use the environment variable without having A trace back occur. That leads me to believe it should be safe, but maybe there is some edge case I’m not considering.

Ah that's right, I forgot that the env code as is wouldn't have worked anyway, so I think you're right, and that we can safely call this a bugfix, thanks again!

@BrandonHoffman
Copy link
Contributor Author

BrandonHoffman commented Feb 18, 2023

Yeah no problem thank you for being so welcoming.

@briantist briantist added this to the 1.1.0 milestone Feb 19, 2023

from hvac import Client
from packaging.version import Version
Copy link
Contributor

Choose a reason for hiding this comment

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

packaging is a dep for various packages but should still add it as a dev dep

Copy link
Contributor

@briantist briantist Feb 23, 2023

Choose a reason for hiding this comment

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

good catch! Added in c765e42

briantist
briantist previously approved these changes Feb 23, 2023
Copy link
Member

@adammike adammike left a comment

Choose a reason for hiding this comment

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

LG2M

@briantist briantist merged commit 16d1af8 into hvac:develop Mar 1, 2023
briantist added a commit that referenced this pull request Mar 6, 2023
* fix vault client certificates loaded from envirnoment variables

* add integration test for configuration via environment variables

* fix lint issues

* fix python 3.7 compatability issue with tests

* remove print + flip default for use_env flag

* add packaging to dev dependencies

---------

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
briantist added a commit to briantist/hvac that referenced this pull request May 10, 2023
…#943)

* fix vault client certificates loaded from envirnoment variables

* add integration test for configuration via environment variables

* fix lint issues

* fix python 3.7 compatability issue with tests

* remove print + flip default for use_env flag

* add packaging to dev dependencies

---------

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VAULT_CLIENT_CERT will always override cert param Client certs are incorrectly handled
4 participants