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

Modify VaultCredentialProvider to accept non-user/pass attributes #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jcooter
Copy link

@jcooter jcooter commented Jul 5, 2021

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.

Copy link
Owner

@jdelic jdelic left a 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 as DjangoDatabaseIntegration, 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):
Copy link
Owner

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")
Copy link
Owner

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))})
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants