-
Notifications
You must be signed in to change notification settings - Fork 5
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
Modify VaultCredentialProvider to accept non-user/pass attributes #7
base: master
Are you sure you want to change the base?
Conversation
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.
Hi! Thank you for filing a PR. It's very interesting. I added some initial thoughts.
Additionally to my in-line comments:
- Please update the docstring, it now doesn't fit with your proposed changes
DjangoIntegration
might be better off asDjangoDatabaseIntegration
, what do you think?
I haven't yet looked into the meta-programming you're doing in _attach_secret_attribute
, so I might have some additional comments later, but the above is all I managed to do before I now have to go into some meetings :).
self._leasetime = None # type: datetime.datetime | ||
self._updatetime = None # type: datetime.datetime | ||
self._lease_id = None # type: str | ||
self._refresh() | ||
|
||
def _attach_secret_attribute(instance, attribute): |
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.
- Please add PEP484 type annotations for
attribute
and the return value (None
) - Please don't override the
self
convention (as per PEP-8)
self.secretpath, | ||
self._lease_id, str(self._leasetime), result["lease_duration"], self._cache["username"], | ||
self._cache["password"] if self.debug_output else "Password withheld, debug output is disabled") |
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 it would be useful to log the returned data similarly to what I did here (i.e. withhold the output if debug_output
isn't set, but log it otherwise). I found that always useful for debugging interactions with secret engines etc.
|
||
def _attach_secret_attribute(instance, attribute): | ||
class_name = instance.__class__.__name__ + 'Child' | ||
child_class = type(class_name, (instance.__class__,), {attribute: property(lambda self: self._get_or_update(attribute))}) |
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.
instead either shadow self
here or rename this instance of the parameter name? This way this should be able to stay PEP-8 compliant, right?
if not result: | ||
try: | ||
mountpoint, path = self.secretpath.split('/', 1) | ||
result = vcl.secrets.kv.v2.read_secret_version(mount_point=mountpoint,path=path) |
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.
result = vcl.secrets.kv.v2.read_secret_version(mount_point=mountpoint,path=path) | |
result = vcl.secrets.kv.v2.read_secret_version(mount_point=mountpoint, path=path) |
This modification turns the VaultCredentialProvider into a more generic vault secret object. This opens up use of vault for secrets other than DB username and password.
The change primarily reads the secret keys returned from vault and dynamically assigns them as properties of the credential provider object. This PR also modifies the request logic to properly handle secrets stored under a kv engine, which returns data in a slightly different format and requires a different hvac call.