Skip to content

agent/proxy: stop caching lease and token renewal responses#32009

Open
tomer-1 wants to merge 3 commits into
hashicorp:mainfrom
tomer-1:fix-agent-lease-cache-renewal
Open

agent/proxy: stop caching lease and token renewal responses#32009
tomer-1 wants to merge 3 commits into
hashicorp:mainfrom
tomer-1:fix-agent-lease-cache-renewal

Conversation

@tomer-1

@tomer-1 tomer-1 commented Jun 23, 2026

Copy link
Copy Markdown

Description

Vault Agent and Proxy can fail to refresh a dynamic secret before its lease
expires when the lease cache is enabled (typically alongside
use_auto_auth_token). The lease cache decides what to cache from the response
shape, so a response to sys/leases/renew (which echoes the lease_id) or
auth/token/renew (which echoes the auth) is treated as a newly issued
lease/token: it is stored and given its own background renewer. A proxied
client's own lifetime watcher (for example consul-template running inside
Agent) then keeps receiving the cached, non-decreasing TTL, never observes the
lease/token approaching its max_ttl, and lets it expire before fetching a
replacement.

This PR stops caching responses to lease- and token-renewal requests and proxies
them through to Vault verbatim, so the client's lifetime watcher sees the true
remaining TTL. The lease cache's own background renewer is unaffected — it renews
the leases it cached at issuance time via a direct client clone, not back through
Send().

  • Pass sys/leases/renew (including the :lease_id URL form and the legacy
    sys/renew alias), auth/token/renew, and auth/token/renew-self through
    instead of caching them.
  • Add isRenewalRequest, reusing the existing path/namespace matching convention
    already used for revocation paths.
  • Add regression tests for the path matcher and for the non-caching behavior of
    both lease and token renewals.

Fixes #19684

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch.
    • LTS: If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • Jira: If this change has an associated Jira, it's referenced either in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.
  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
  • If applicable, I've documented the impact of any changes to security controls.

Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

- The lease cache keyed cacheability off the response shape, so a
  response to sys/leases/renew (which echoes the lease_id) was cached
  and given its own renewer.
- A proxied client's lifetime watcher then kept receiving a stale,
  non-decreasing TTL from the cache and could not see the lease nearing
  its max_ttl, letting dynamic-secret leases expire before a refresh.
- Pass lease renewal requests through to Vault instead of caching them.
  The cache's own background renewer is unaffected: it renews via a
  direct client clone, not back through Send().
- Add isLeaseRenewalRequest, reusing the existing path/namespace
  convention; it covers sys/leases/renew, the lease-id URL form, and the
  legacy sys/renew alias.
- Add regression tests for the matcher and for the non-caching behavior.
- Fixes hashicorp#19684

Signed-off-by: Tomer H <tomer@rhinofcp.com>
@tomer-1
tomer-1 requested a review from a team as a code owner June 23, 2026 13:01
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: should NOT have additional property `public`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. agent labels Jun 23, 2026
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vault-ui Error Error Jun 24, 2026 11:49am

Request Review

@dosubot dosubot Bot added core/lease regression Used to indicate possible regressions between versions labels Jun 23, 2026
@hashicorp-cla-app

hashicorp-cla-app Bot commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Signed-off-by: Tomer H <tomer@rhinofcp.com>
@tomer-1 tomer-1 changed the title agent/proxy: stop caching lease renewal responses agent/proxy: stop caching lease and token renewal responses Jun 24, 2026
- Extend the renewal pass-through to auth/token/renew and
  auth/token/renew-self, whose responses echo the existing token's auth
  and were otherwise cached and given their own renewer.
- A proxied client renewing its own token through the proxy hit the same
  stale, non-decreasing TTL problem as dynamic-secret leases.
- Rename isLeaseRenewalRequest to isRenewalRequest and add the token
  endpoints to renewalPaths.
- Extend regression tests to cover token renewal.
@tomer-1

tomer-1 commented Jul 6, 2026

Copy link
Copy Markdown
Author

sorry for the delay.
i'm currently pending company CLA approval.

@heatherezell

Copy link
Copy Markdown
Contributor

sorry for the delay. i'm currently pending company CLA approval.

Sounds good! Make sure the corporate CLA has your GitHub-associated email address and this username. Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent core/lease regression Used to indicate possible regressions between versions size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vault Agent lease cache interferes with template refresh for dynamic secrets

2 participants