Using the AWS Secrets Manager Agent
How the Secrets Manager Agent works
The AWS Secrets Manager Agent is a client-side HTTP service that helps you standardize how you consume secrets from Secrets Manager across your compute environments. You can use it with the following services:
-
AWS Lambda
-
Amazon Elastic Container Service
-
Amazon Elastic Kubernetes Service
-
Amazon Elastic Compute Cloud
The Secrets Manager Agent retrieves and caches secrets in memory, allowing your applications to get secrets from localhost instead of making direct calls to Secrets Manager. The Secrets Manager Agent can only read secrets—it can't modify them.
The Secrets Manager Agent is open source. The source code, installation instructions, and latest
release information are available on GitHub
Important
The Secrets Manager Agent uses the AWS credentials from your environment to call Secrets Manager. It includes protection against Server Side Request Forgery (SSRF) to help improve secret security. The Secrets Manager Agent uses the post-quantum ML-KEM key exchange as the highest-priority key exchange by default.
Understanding Secrets Manager Agent caching
The Secrets Manager Agent uses an in-memory cache that resets when the Secrets Manager Agent restarts. It periodically refreshes cached secret values based on the following:
-
The default refresh frequency (TTL) is 300 seconds
-
You can modify the TTL using a configuration file
-
The refresh occurs when you request a secret after the TTL expires
Note
The Secrets Manager Agent doesn't include cache invalidation. If a secret rotates before the cache entry expires, the Secrets Manager Agent might return a stale secret value.
The Secrets Manager Agent returns secret values in the same format as the response of
GetSecretValue. Secret values aren't encrypted in the cache.
Topics
Build the Secrets Manager Agent
Before you begin, ensure you have the standard development tools and Rust tools installed for your platform.
Note
Building the agent with the fips feature enabled on macOS currently
requires the following workaround:
-
Create an environment variable called
SDKROOTwhich is set to the result of runningxcrun --show-sdk-path
Install the Secrets Manager Agent
Choose your compute environment from the following installation options.
Retrieve secrets with the Secrets Manager Agent
To retrieve a secret, call the local Secrets Manager Agent endpoint with the secret name or ARN as a
query parameter. By default, the Secrets Manager Agent retrieves the AWSCURRENT version of the
secret. To retrieve a different version, use either the versionStage or versionId
parameter.
Important
To help protect the Secrets Manager Agent, you must include a SSRF token header as part of each
request: X-Aws-Parameters-Secrets-Token. The Secrets Manager Agent denies requests
that don't have this header or that have an invalid SSRF token. You can customize
the SSRF header name in the Configure the Secrets Manager Agent.
Required permissions
The Secrets Manager Agent uses the AWS SDK for Rust, which uses the AWS credential provider chain. The identity of these IAM credentials determines the permissions the Secrets Manager Agent has to retrieve secrets.
-
secretsmanager:DescribeSecret -
secretsmanager:GetSecretValue
For more information about permissions, see Permissions reference for AWS Secrets Manager.
Important
After the secret value is pulled into the Secrets Manager Agent, any user with access to the compute environment and SSRF token can access the secret from the Secrets Manager Agent cache. For more information, see Security considerations.
Example requests
Understanding the refreshNow parameter
The Secrets Manager Agent uses an in-memory cache to store secret values, which it refreshes periodically. By default, this refresh occurs when you request a secret after the Time to Live (TTL) has expired, typically every 300 seconds. However, this approach can sometimes result in stale secret values, especially if a secret rotates before the cache entry expires.
To address this limitation, the Secrets Manager Agent supports a parameter called
refreshNow in the URL. You can use this parameter to force an
immediate refresh of a secret's value, bypassing the cache and ensuring you have the
most up-to-date information.
- Default behavior (without
refreshNow) -
-
Uses cached values until TTL expires
-
Refreshes secrets only after TTL (default 300 seconds)
-
May return stale values if secrets rotate before the cache expires
-
- Behavior with
refreshNow=true -
-
Bypasses the cache entirely
-
Retrieves the latest secret value directly from Secrets Manager
-
Updates the cache with the fresh value and resets the TTL
-
Ensures you always get the most current secret value
-
Force-refresh a secret value
Important
The default value of refreshNow is false.
When set to true, it overrides the TTL specified in the Secrets Manager Agent
configuration file and makes an API call to Secrets Manager.
Retrieve secrets across accounts with role chaining
Role chaining enables the Secrets Manager Agent to retrieve secrets from other AWS accounts by
assuming IAM roles using AWS STS AssumeRole. The Secrets Manager Agent creates and caches
a separate caching client for each unique role ARN. Each role client maintains its own
independent cache, so the same secret fetched with different roles has separate cache
entries.
Required permissions
To use role chaining, you need the following:
-
The Secrets Manager Agent's environment credentials must have
sts:AssumeRolepermission on the target role ARN. -
The target role must have
secretsmanager:GetSecretValueandsecretsmanager:DescribeSecretpermissions for the secrets you want to access. -
The target role's trust policy must allow the Secrets Manager Agent's identity to assume it.
Retrieve cross-account secrets
Include the roleArn query parameter in your request to
the Secrets Manager Agent to specify which role to assume for the secret retrieval.
Role chaining configuration and limits
Configure role chaining with the max_roles option in your TOML
configuration file. This sets the maximum number of simultaneous assumed roles, in
the range 1 to 20. The default is 20.
Important
Assumed roles are not evicted from the Secrets Manager Agent's role cache. Once the maximum
number of roles has been reached, requests with new role ARNs are rejected with
a 400 error until the Secrets Manager Agent is restarted.
Error responses for role chaining
400-
The
roleArnformat is invalid or the maximum number of assumed roles has been reached. 403-
The AWS STS
AssumeRolecall failed. Verify that the target role's trust policy allows the Secrets Manager Agent's identity to assume it.
Pre-fetch secrets at startup
By default, the Secrets Manager Agent fetches secrets on demand when your application requests them. With pre-fetching, the Secrets Manager Agent loads specified secrets into the cache when it starts up, so your application can access them immediately without waiting for the first API call. Pre-fetching runs as a background task—the Secrets Manager Agent begins accepting requests immediately and does not block on pre-fetch completion.
You can specify secrets to pre-fetch in two ways:
-
Explicit secrets – List specific secret IDs or ARNs.
-
Tag-based discovery – Discover secrets by tag key. The Secrets Manager Agent fetches all secrets that have the specified tag.
Required permissions
In addition to the standard permissions for retrieving secrets, pre-fetching requires the following:
-
secretsmanager:BatchGetSecretValue– Required for all pre-fetch operations. -
secretsmanager:ListSecrets– Required only when using tag-based discovery.
Configure pre-fetching
Add a [prefetch] section to your TOML configuration file. The
following options are available:
cache_buffer_ratio-
The maximum fraction of the cache to fill per client during pre-fetch, in the range 0.1 to 1.0. The default is 0.8. When the buffer limit is reached, the Secrets Manager Agent stops pre-fetching remaining secrets—it does not evict existing cache entries. Secrets not loaded during pre-fetch are still available on demand.
max_jitter_seconds-
A random delay in seconds before pre-fetching begins, in the range 0 to 10. The default is 0. Use this to prevent synchronized fleet-wide API calls when multiple agents start at the same time.
Example Pre-fetch configuration with explicit secrets
[prefetch] cache_buffer_ratio = 0.6 max_jitter_seconds = 5 secrets = [ { secret_id = "arn:aws:secretsmanager:us-west-2:123456789012:secret:MySecret-AbCdEf" }, { secret_id = "MyOtherSecret" }, ]
Example Pre-fetch configuration with tag-based discovery
[prefetch] cache_buffer_ratio = 0.8 filter_tags = [ { key = "Environment" }, { key = "Team" }, ]
You can also combine explicit secrets and tag-based discovery in the same
configuration. For cross-account pre-fetching, add the role_arn
field. For more information, see Retrieve secrets across accounts with role chaining.
Example Pre-fetch configuration with cross-account access
[prefetch] cache_buffer_ratio = 0.6 max_jitter_seconds = 5 secrets = [ { secret_id = "arn:aws:secretsmanager:us-west-2:123456789012:secret:MySecret-AbCdEf" }, { secret_id = "cross-account-secret", role_arn = "arn:aws:iam::987654321098:role/SecretAccessRole" }, ] filter_tags = [ { key = "Environment" }, { key = "Team", role_arn = "arn:aws:iam::987654321098:role/SecretAccessRole" }, ]
Configure the Secrets Manager Agent
To change the configuration of the Secrets Manager Agent, create a TOML./aws_secretsmanager_agent --config
config.toml.
Configuration options
log_level-
The level of detail reported in logs for the Secrets Manager Agent: DEBUG, INFO, WARN, ERROR, or NONE. The default is INFO.
log_to_file-
Whether to log to a file or stdout/stderr:
trueorfalse. The default istrue. http_port-
The port for the local HTTP server, in the range 1024 to 65535. The default is 2773.
region-
The AWS Region to use for requests. If no Region is specified, the Secrets Manager Agent determines the Region from the SDK. For more information, see Specify your credentials and default Region in the AWS SDK for Rust Developer Guide.
ttl_seconds-
The TTL in seconds for the cached items, in the range 0 to 3600. The default is 300. 0 indicates that there is no caching.
cache_size-
The maximum number of secrets that can be stored in the cache, in the range 1 to 1000. The default is 1000.
ssrf_headers-
A list of header names the Secrets Manager Agent checks for the SSRF token. The default is "X-Aws-Parameters-Secrets-Token, X-Vault-Token".
ssrf_env_variables-
A list of environment variable names the Secrets Manager Agent checks in sequential order for the SSRF token. The environment variable can contain the token or a reference to the token file as in:
AWS_TOKEN=file:///var/run/awssmatoken. The default is "AWS_TOKEN, AWS_SESSION_TOKEN, AWS_CONTAINER_AUTHORIZATION_TOKEN". path_prefix-
The URI prefix used to determine if the request is a path based request. The default is "/v1/".
max_conn-
The maximum number of connections from HTTP clients that the Secrets Manager Agent allows, in the range 1 to 1000. The default is 800.
max_roles-
The maximum number of simultaneous IAM roles for cross-account access, in the range 1 to 20. The default is 20. For more information, see Retrieve secrets across accounts with role chaining.
Optional features
The Secrets Manager Agent can be built with optional features by passing the --features
flag to cargo build. The available features are:
Build features
prefer-post-quantum-
Makes
X25519MLKEM768the highest-priority key exchange algorithm. Otherwise, it is available but not highest-priority.X25519MLKEM768is a hybrid, post-quantum-secure key exchange algorithm. fips-
Restricts the cipher suites used by the agent to only FIPS-approved ciphers.
Logging
- Local logging
-
The Secrets Manager Agent logs errors locally to the file
logs/secrets_manager_agent.logor to stdout/stderr depending on thelog_to_fileconfig variable. When your application calls the Secrets Manager Agent to get a secret, those calls appear in the local log. They do not appear in the CloudTrail logs. - Log rotation
-
The Secrets Manager Agent creates a new log file when the file reaches 10 MB, and it stores up to five log files total.
- AWS service logging
-
The log does not go to Secrets Manager, CloudTrail, or CloudWatch. Requests to get secrets from the Secrets Manager Agent do not appear in those logs. When the Secrets Manager Agent makes a call to Secrets Manager to get a secret, that call is recorded in CloudTrail with a user agent string containing
aws-secrets-manager-agent.
You can configure logging options in the Configure the Secrets Manager Agent.
Security considerations
- Domain of trust
-
For an agent architecture, the domain of trust is where the agent endpoint and SSRF token are accessible, which is usually the entire host. The domain of trust for the Secrets Manager Agent should match the domain where the Secrets Manager credentials are available in order to maintain the same security posture. For example, on Amazon EC2 the domain of trust for the Secrets Manager Agent would be the same as the domain of the credentials when using roles for Amazon EC2.
Important
Security conscious applications that are not already using an agent solution with the Secrets Manager credentials locked down to the application should consider using the language-specific AWS SDKs or caching solutions. For more information, see Get secrets.