Skip to content

Vault Agent flooding the server with "/v1/sys/leases/renew" requests after the lease expired #25712

Description

@jrutkowski

I have noticed a strange pattern, when looking through vault server load balancer metrics. There were tons of request, with "403 Forbidden" response code recorded. Quick investigation led me to instances of vault agent, configured with AWS IAM auto_auth and dynamic credentials caching enabled.

tcpdump showed, that after some time from obtaining first auth token and a set of dynamic credentials, agent started flooding the server with the lease renewal request (/v1/sys/leases/renew), that at that time were no longer in vault (evicted due to the auth token expiration). The server kept responding with "403 Forbidden", because the lease was no longer valid and the agent kept repeating the request over and over again.
The interesting part was that those request were not visible in agent logs, even with most detailed "TRACE" log level.

I think, that this happens, when vault agent tries to determine whether cached credentials are still valid or if they can be renewed. In usual use case a response is returned, which is then used to decide if data should be evicted from the cache or renewed. When the auth token (with which credentials were generated) has expired, that is no longer possible. Program gets trapped in a loop and keeps sending the "/v1/sys/leases/renew" request.

Details specific to the configuration which triggers the issue:

agent-config.hcl:

pid_file = "./agent.pid"
log_level = "trace"

vault {
  address = "http://vault_addr:8200"
  retry {
    num_retries = 5
  }
}

auto_auth {
  method "aws" {
    mount_path = "auth/aws"

    config = {
      type = "iam"
      role = "auth_role"
    }
  }
}

cache {
  use_auto_auth_token = true
}

listener "tcp" {
  address = "0.0.0.0:8100"
  tls_disable = true
}

auth_role:

Key                               Value
---                               -----
allow_instance_migration          false
auth_type                         iam
bound_account_id                  []
bound_ami_id                      []
bound_ec2_instance_id             <nil>
bound_iam_instance_profile_arn    []
bound_iam_principal_arn           [arn:aws:iam::xxxxxx:role/auth_role]
bound_iam_principal_id            [...]
bound_iam_role_arn                []
bound_region                      []
bound_subnet_id                   []
bound_vpc_id                      []
disallow_reauthentication         false
inferred_aws_region               n/a
inferred_entity_type              n/a
resolve_aws_unique_ids            true
role_id                           ...
role_tag                          n/a
token_bound_cidrs                 []
token_explicit_max_ttl            0s
token_max_ttl                     1m
token_no_default_policy           false
token_num_uses                    0
token_period                      0s
token_policies                    [policies]
token_ttl                         1m
token_type                        service

database role details:

Key                      Value
---                      -----
creation_statements      [...]
credential_type          password
db_name                  ...
default_ttl              1m30s
max_ttl                  1m30s
renew_statements         []
revocation_statements    [...]
rollback_statements      []

What's important to note here is that the issue appears when the token type is set to "service" and max_ttl is applied (not a periodic token).

I see 2 possible solutions:

  • When auto_auth token expires and new one is obtained - make sure that all the cache related to the previous token is evicted.
  • When "403 Forbidden" is received, when trying to renew cached lease, treat it as it was no longer valid, and evict from cache.

If needed, I am willing to invest some time into helping to solve this issue (including writing some code). Please let me know if that would be welcome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions