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

K/V v2: add suport for lease_duration using ttl key #6274

Open
asaintsever opened this issue Feb 21, 2019 · 15 comments
Open

K/V v2: add suport for lease_duration using ttl key #6274

asaintsever opened this issue Feb 21, 2019 · 15 comments
Labels
community-sentiment Tracking high-profile issues from the community enhancement secret/kv

Comments

@asaintsever
Copy link

asaintsever commented Feb 21, 2019

Is your feature request related to a problem? Please describe.
Using K/V v2, which is enabled by default with Vault server in dev mode, adding a ttl key has no effect on lease_duration attribute (remains 0). With K/V v1, ttl key allows to set lease duration which is very handy. It seems that with K/V v2 we cannot benefit from this feature.

Describe the solution you'd like
Same special handling of ttl key as we currently have in K/V v1 (see https://www.vaultproject.io/docs/secrets/kv/kv-v1.html#ttls)

Describe alternatives you've considered
N/A

Explain any additional use-cases
Cannot use the versioned version of K/V (i.e. v2) if we want to set a ttl and have consul template refresh its template based on lease_duration value (and not vault token ttl). Stuck on K/V v1 for the moment.

Additional context
N/A

@ghost ghost self-assigned this Feb 21, 2019
@briankassouf
Copy link
Member

duplicate of #6184

@seh
Copy link

seh commented Jan 28, 2020

@briankassouf, I don't think this is a duplicate of #6184. At present, if one runs vault kv patch ttl=60s, you wind up with a value vault.Secret.Data["data"]["ttl"] = "60s", which is placing the TTL value in the secret payload, not in its metadata.

My goal is to populate vault.Secret.Data["ttl"] for KV v2 secrets, so that (*vault.Secret).TokenTTL picks up the value here.

@asaintsever, do you concur?

@seh seh unassigned ghost Jan 28, 2020
@asaintsever
Copy link
Author

@seh yes totally, for KV v2, a "ttl" secret value should end up in Data["ttl"] (as it is the case with KV v1), not in Data["data"]["ttl"] where it is not considered currently (as you pointed out: https://github.com/hashicorp/vault/blob/master/api/secret.go#L263-L272).

@takaishi
Copy link

lease_duration is used in consul-template (https://github.com/hashicorp/consul-template/blob/master/dependency/vault_common.go#L126-L167) to wait next update.
But consul-tempalte's behavior is not compatible for K/V v1 and K/V v2 now, consul-template wait default ttl (5 minutes).

When enable secret and put data as following:

vault secrets enable -version=1 kv-v1
vault secrets enable -version=2 kv-v2
vault kv put kv-v1/with-ttl a=111 ttl=60s
vault kv put kv-v2/with-ttl a=111 ttl=60s

When I get from kv-v1, lease_duration is same value with ttl field.

vault kv get -format=json kv-v1/with-ttl
{
  "request_id": "b30f388d-b12b-f37d-b491-05d7ea04c0a2",
  "lease_id": "",
  "lease_duration": 60,
  "renewable": false,
  "data": {
    "a": "111",
    "ttl": "60s"
  },
  "warnings": null
}

But I get from kv-v2, inspite of ttl field exists, lease_duration is 0.

vault kv get -format=json kv-v2/with-ttl
{
  "request_id": "2a51dd87-0995-c493-59ea-38432e6ed4b3",
  "lease_id": "",
  "lease_duration": 0,
  "renewable": false,
  "data": {
    "data": {
      "a": "111",
      "ttl": "60s"
    },
    "metadata": {
      "created_time": "2020-03-17T02:52:12.804263Z",
      "deletion_time": "",
      "destroyed": false,
      "version": 1
    }
  },
  "warnings": null
}

lease_duration field is updated from input's Secret field in LogicalResponseToHTTPResponse, but input doesn't has Secret when K/V v2.

https://github.com/hashicorp/vault/blob/master/sdk/logical/translate_response.go#L14-L46

K/V v1 inputs's Secret field inserted in following code:
https://github.com/hashicorp/vault-plugin-secrets-kv/blob/master/passthrough.go#L166-L184

K/V v2 inputs's Secret field does'nt inserted.
https://github.com/hashicorp/vault-plugin-secrets-kv/blob/master/path_data.go#L84-L170

If K/V v1 and K/V v2 should be have lease_duration from ttl field, I ready to send a patch.

@mimperatore
Copy link

Should this issue be reopened?

@seh felt that this was not a duplicate of #6184, and I tend to agree, because that issue is about destroying the secret after the TTL, whereas this request is about providing equivalent support as v1 for the lease duration.

@takaishi provided some ideas about how to address this, and was willing to put a PR together.

Without support for this feature, I am reluctant to adopt kv-v2 because it doesn't give me the ability to auto-renew my secrets automatically (for example, when I want to use the vault agent injector sidecar).

@Chrisss93
Copy link

This has become a major issue for us as well. Is the lease_duration concept being deprecated? If not what is the advised way of setting lease_duration on KV v2 engine secrets? We are considering moving our engines back to KV v1 if we are unable to set the lease_duration in v2.

@voiprodrigo
Copy link

Hello. Can this issue be re-opened, please? It was incorrectly closed by @briankassouf as a duplicate of #6184.
Thanks.

kppullin pushed a commit to kppullin/secret-provider that referenced this issue 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 lensesio#4

Ref: hashicorp/vault#6274
@huntc
Copy link

huntc commented May 25, 2022

Requesting that this issue be re-opened also. That, or the documentation at https://www.vaultproject.io/docs/secrets/kv/kv-v1#ttls be updated to reflect v2 behaviour. Thanks.

@hsimon-hashicorp
Copy link
Contributor

Hi folks - we hear you! I'll re-open this and engage the engineers in another discussion about it. Thanks for your patience!

@ccapurso
Copy link
Contributor

Hi, everyone! The Vault team has discussed this internally in order to identify a path forward. The ttl and lease_duration option for KVv1 is a workaround that we do not wish to perpetuate to KVv2. The various options of TTL support that we have discussed includes deletion and cache control.

The concept of deletion has been addressed via the delete_version_after KVv2 metadata field. As mentioned in multiple comments, this does not address the ttl field in KVv1 which ultimately maps to lease_duration in the response. The Vault team's preferred solution would be to properly support cache control via appropriate response headers. Our proposals are still under review, however. That said, whatever option is chosen will need to be used within consul-template as well to provide a full solution when this work is prioritized.

We will keep this issue open and be sure to keep everyone updated with our status. We appreciate all of your feedback!

@eikenb
Copy link
Contributor

eikenb commented Aug 19, 2022

The Vault team's preferred solution would be to properly support cache control via appropriate response headers.

How will this be made available through the API? Lease duration is made available on the data structure returned. How will API clients be able to access this value to determine how long to wait when polling secrets?

@huntc
Copy link

huntc commented Aug 19, 2022

The Vault team's preferred solution would be to properly support cache control via appropriate response headers.

How would TTL be expressed when creating/updating a secret?

@the-maldridge
Copy link

Any update on this limitation? I find myself reminded of this roughly every 70 days when letsencrypt certs roll over, are reloaded into vault, and then not updated by consumers.

@thallesdaniell
Copy link

thallesdaniell commented Jun 4, 2023

To handle K/V v2 lease I am using static_secret_render_interval and it has been working for me temporarily.

config.hcl: |
    template_config {
      exit_on_retry_failure = true
      static_secret_render_interval = "30s"
    }
    
    template {
      contents = "{{- with secret \"staging/data/database/config\" -}}{{- range $k, $v := .Data.data }}{{ printf \"%s=\\\"%s\\\"\\n\" $k $v }}{{- end }}{{- end }}"
      destination = "/vault/secrets/.env"
    }

@the-maldridge
Copy link

That's a good shout. Unfortunately I'm running into this problem inside Nomad where that key isn't exposed. I've opened hashicorp/nomad#17423 to see if I can gain access to that key inside the nomad environment.

@hsimon-hashicorp hsimon-hashicorp added the community-sentiment Tracking high-profile issues from the community label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-sentiment Tracking high-profile issues from the community enhancement secret/kv
Projects
None yet
Development

No branches or pull requests