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-25341 Address issue where having no permissions to renew caused auto-auth to attempt to renew with no backoff #26844

Merged
merged 11 commits into from
May 9, 2024

Conversation

VioletHynes
Copy link
Contributor

@VioletHynes VioletHynes commented May 6, 2024

The issue was twofold:

  • We shouldn't fail in the case where a token can't be renewed due to permissions, we should just treat it as non-renewable
  • We should add backoff in cases where errors do occur so that we don't spam the Vault server with requests

Both issues should be resolved by this PR.

Closes #22575

@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label May 6, 2024
@@ -478,10 +479,9 @@ func (ah *AuthHandler) Run(ctx context.Context, am AuthMethod) error {
}

metrics.IncrCounter([]string{ah.metricsSignifier, "auth", "success"}, 1)
// We don't want to trigger the renewal process for tokens with
// unlimited TTL, such as the root token.
if leaseDuration == 0 && isTokenFileMethod {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, this was a bug, and could occur for non-renewable tokens that happened to check it as their lease ticked down, causing re-authentication to not happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to keep a check doesn't trigger lifetime watcher if the secret.Renewable == false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the secret's not renewable, then the LifetimeWatcher still needs to get triggered given the current architecture, so that auth gets re-triggered at the correct time. If we need to authenticate again for any reason, we should run the lifetimewatcher -- the root token is the only token where we don't need to reauthenticate (since it never expires)

e.g. for a 10s TTL non-renewable token, it might look like this

  • LifetimeWatcher triggered
  • It waits for ~8.5 seconds, does not try to renew
  • Triggers the done channel with no error
  • Auth gets re-triggered

We're essentially making renewable tokens without the permission to renew follow the same path as the above ^

Copy link

github-actions bot commented May 6, 2024

CI Results:
All Go tests succeeded! ✅

// so that we don't go into a loop, as the LifetimeWatcher will immediately
// return for tokens like this.
if leaseDuration == 0 {
time.Sleep(1 * time.Second)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this sleep, we'd reauthenticate then receive something on the DoneCh immediately a few times. It's a bit of an edge case but it seemed important. I wanted to avoid using backoffSleep since that's intended to be for errors only.

@VioletHynes VioletHynes added this to the 1.17.0 milestone May 6, 2024
@VioletHynes VioletHynes requested a review from divyaac May 6, 2024 18:37
@VioletHynes VioletHynes marked this pull request as ready for review May 6, 2024 18:38
Copy link

github-actions bot commented May 6, 2024

Build Results:
All builds succeeded! ✅

@VioletHynes VioletHynes added the backport/1.16.x Backport changes to `release/1.16.x` label May 7, 2024
command/agent_test.go Outdated Show resolved Hide resolved
// Prior to the fix made in the same PR this test was added, it would trigger many, many
// retries (hundreds to thousands in less than a minute).
// We really want to make sure that doesn't happen.
numberOfRenewSelves := strings.Count(stringAudit, "auth/token/renew-self")
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool strategy!

Copy link
Contributor

@divyaac divyaac left a comment

Choose a reason for hiding this comment

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

Looks good to me! Small comments.

VioletHynes and others added 2 commits May 7, 2024 14:15
Co-authored-by: divyaac <divya.chandrasekaran@hashicorp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.16.x Backport changes to `release/1.16.x` hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vault agent silently DoSes Vault server when token policy does not include auth/token/renew-self
2 participants