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

Vault - Support default TTLs #33

Closed
wants to merge 6 commits into from

Conversation

kppullin
Copy link

@kppullin kppullin commented Dec 2, 2021

Vault's KV2 engine does not return the lease_duration TTL value
that is provided by the original KV1 engine. When this value is 0
or missing it effectively disables the caching support of the
VaultSecretProvider.

This commit adds support for configuring an optional default TTL to apply
when the lease_duration value is 0.

To maintain backwards compatibility the default value remains 0.

Fixes #4

Ref: hashicorp/vault#6274

Vault's KV2 engine does not return the `lease_duration` TTL value
that is provided by the original KV1 engine. When this value is 0
or missing it effectively disables the caching support of the
`VaultSecretProvider`.

This commit adds support for configuring an optional default TTL to apply
when the `lease_duration` value is 0.

To maintain backwards compatibility the default value remains 0.

Fixes lensesio#4

Ref: hashicorp/vault#6274
Copy link

@conradkleinespel conradkleinespel left a comment

Choose a reason for hiding this comment

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

I am not a maintainer, however I am interested in seeing this PR move forward. Here are some suggestions. cc @andrewstevenson

Type.INT,
0,
Importance.MEDIUM,
"Default TTL for secrets returned from Vault. Defaults to 0 to not break existing configurations. Work around for the lack of `lease_duration` values returned from the Vault KV2 engine: https://github.com/hashicorp/vault/issues/6274"

Choose a reason for hiding this comment

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

The referenced issue is closed, I suggest the following wording to keep things simple:

Suggested change
"Default TTL for secrets returned from Vault. Defaults to 0 to not break existing configurations. Work around for the lack of `lease_duration` values returned from the Vault KV2 engine: https://github.com/hashicorp/vault/issues/6274"
"Default TTL for secrets returned by Vault. Defaults to 0 for backwards compatibility

} else if (settings.secretTtlDefault > 0) {
Some(now.plusSeconds(settings.secretTtlDefault))
} else {
None

Choose a reason for hiding this comment

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

Shouldn't this be Some(now) given that previously with a duration, we returned now.plusSeconds(duration)?

Copy link
Author

Choose a reason for hiding this comment

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

It's been a "long time" since I wrote this code (3 weeks! 😆 ) and some of the changes mixed in here were required when combined with other changes (#32 and #34). It was a bit of a mess to try to split these 3 PRs up into cleanly applicable units after the fact and it looks like other unrelated changes have also made their way in too, such as the /database/creds code.

If I recall correctly, returning None here is necessary when once the fix for making TTLs work is applied (#34), but you're likely correct that returning now.plusSeconds(duration) would work here. However, since I think this may all be moot without #34, as the TTLs don't work anyway, it may be better to combine the two PRs.

I lack time at the moment to untangle this, but will note that we've been running a patched version that combines #32, #33, and #34 for a few weeks now without issues (https://github.com/NextDeveloperTeam/secret-provider/commits/master).

Also thanks for all the feedback and hoping to find some time to revisit in more detail in the new year.

@@ -162,4 +168,20 @@ class VaultSecretProvider() extends ConfigProvider with VaultHelper {
)
}
}

private def readSecretFromVault(path: String): LogicalResponse = {
// Check if the path looks like it's referencing the vault database engine. If so, use the `database()` api of the

Choose a reason for hiding this comment

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

This comment can be removed I think, it states what the code does line by line without adding value.

if (parts.length == 3) {
vaultClient.get.database().creds(parts(2))
} else {
throw new Exception("Database path is invalid. Path must be in the form 'database/creds/<role_name>'")

Choose a reason for hiding this comment

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

Suggested change
throw new Exception("Database path is invalid. Path must be in the form 'database/creds/<role_name>'")
throw new IllegalArgumentException("Database path is invalid, must be in the form 'database/creds/<role_name>'")

private def readSecretFromVault(path: String): LogicalResponse = {
// Check if the path looks like it's referencing the vault database engine. If so, use the `database()` api of the
// vault client to obtain this secret. Otherwise, fall back to the default key-vaule engine.
if (path.startsWith("database/creds/")) {

Choose a reason for hiding this comment

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

We may want to have a test case for database creds. A good place to start from would probably be the test case for kv secrets.

@davidsloan
Copy link
Contributor

@kppullin Some similar functionality has been implemented in #47 . We have added the flag secret.default.ttl. Sorry to not have taken your contribution, this was part of a package of other changes and wider refactoring.

Do you want to check this and see if it fit your requirements, and if so close this one off?

@davidsloan
Copy link
Contributor

Closing as similar functionality was implemented by #47 . Thank you for the contribution!

@davidsloan davidsloan closed this Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hashicorp VaultProvider config option to override secret's lease duration.
4 participants