The AWS Secrets Manager Agent is a client-side HTTP service that you can use to standardize consumption of secrets from Secrets Manager across environments such as AWS Lambda, Amazon Elastic Container Service, Amazon Elastic Kubernetes Service, and Amazon Elastic Compute Cloud. The Secrets Manager Agent can retrieve and cache secrets in memory so that your applications can consume secrets directly from the cache. That means you can fetch the secrets your application needs from the localhost instead of making calls to Secrets Manager. The Secrets Manager Agent can only make read requests to Secrets Manager—it can't modify secrets.
The Secrets Manager Agent uses the AWS credentials you provide in your environment to make calls to Secrets Manager. The Secrets Manager Agent offers protection against Server Side Request Forgery (SSRF) to help improve secret security. You can configure the Secrets Manager Agent by setting the maximum number of connections, the time to live (TTL), the localhost HTTP port, and the cache size.
Because the Secrets Manager Agent uses an in-memory cache, it resets when the Secrets Manager Agent restarts. The Secrets Manager Agent periodically refreshes the cached secret value. The refresh happens when you try to read a secret from the Secrets Manager Agent after the TTL has expired. The default refresh frequency (TTL) is 300 seconds, and you can change it by using a Configuration file which you pass to the Secrets Manager Agent using the --config
command line argument. The Secrets Manager Agent does not include cache invalidation. For example, 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 are not encrypted in the cache.
To download the source code, see https://github.com/aws/aws-secretsmanager-agent
Topics
Step 1: Build the Secrets Manager Agent binary
To build the Secrets Manager Agent binary natively, you need the standard development tools and the Rust tools. Alternatively, you can cross-compile for systems that support it, or you can use Rust cross to cross-compile.
-
On RPM-based systems such as AL2023, you can install the development tools by using the Development Tools group.
sudo yum -y groupinstall "Development Tools"
-
Follow the instructions at Install Rust
in the Rust documentation. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh . "$HOME/.cargo/env"
-
Build the agent using the cargo build command:
cargo build --release
You will find the executable under
target/release/aws-secrets-manager-agent
.
Step 2: Install the Secrets Manager Agent
Based on the type of compute, you have several options for installing the Secrets Manager Agent.
To install the Secrets Manager Agent
-
Use the
install
script provided in the repository.The script generates a random SSRF token on startup and stores it in the file
/var/run/awssmatoken
. The token is readable by theawssmatokenreader
group that the install script creates. -
To allow your application to read the token file, you need to add the user account that your application runs under to the
awssmatokenreader
group. For example, you can grant permissions for your application to read the token file with the following usermod command, where<APP_USER>
is the user ID under which your application runs.sudo usermod -aG awssmatokenreader
<APP_USER>
Step 3: Retrieve secrets with the Secrets Manager Agent
To use the agent, you call the local Secrets Manager Agent endpoint and include the name or ARN of the secret as a query parameter. By default, the Secrets Manager Agent retrieves the AWSCURRENT
version of the secret. To retrieve a different version, you can set versionStage
or versionId
.
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 Configuration file.
The Secrets Manager Agent uses the AWS SDK for Rust, which uses the default credential provider chain. The identity of these IAM credentials determines the permissions the Secrets Manager Agent has to retrieve secrets.
Required permissions:
secretsmanager:DescribeSecret
secretsmanager:GetSecretValue
For more information, see Permissions reference.
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.
The following curl example shows how to get a secret from the Secrets Manager Agent. The example relies on the SSRF being present in a file, which is where it is stored by the install script.
curl -v -H \ "X-Aws-Parameters-Secrets-Token: $(</var/run/awssmatoken)" \ 'http://localhost:2773/secretsmanager/get?secretId=
<YOUR_SECRET_ID>
'; \ echo
Force-refresh secrets with
RefreshNow
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, 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
-
By using the refreshNow
parameter, you can ensure that you're
always working with the most current secret values, even in scenarios where frequent
secret rotation is necessary.
refreshNow parameter behavior
- refreshNow set to
true
-
If Secrets Manager Agent can't retrieve the secret from Secrets Manager, it returns an error and does not update the cache.
- refreshNow set to
false
or not specified -
Secrets Manager Agent follows its default behavior:
-
If the cached value is fresher than the TTL, Secrets Manager Agent returns the cached value.
-
If the cached value is older than the TTL, Secrets Manager Agent makes a call to Secrets Manager.
-
Using the refreshNow parameter
To use the refreshNow parameter, include it in the URL for the Secrets Manager Agent GET request.
Example – Secrets Manager Agent GET request with refreshNow parameter
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.
The following curl example shows how force Secrets Manager Agent to refresh the secret. The example relies on the SSRF being present in a file, which is where it is stored by the install script.
curl -v -H \ "X-Aws-Parameters-Secrets-Token: $(</var/run/awssmatoken)" \ 'http://localhost:2773/secretsmanager/get?secretId=
<YOUR_SECRET_ID>&refreshNow=true'
\ echo
Configure the Secrets Manager Agent
To change the configuration of the Secrets Manager Agent, create a TOML./aws-secrets-manager-agent --config config.toml
.
The following list shows the options you can configure for the Secrets Manager Agent.
log_level – The level of detail reported in logs for the Secrets Manager Agent: DEBUG, INFO, WARN, ERROR, or NONE. The default is INFO.
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 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".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.
Logging
The Secrets Manager Agent logs errors locally to the file logs/secrets_manager_agent.log
. 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.
The Secrets Manager Agent creates a new log file when the file reaches 10 MB, and it stores up to five log files total.
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 in the Configuration file.
Security considerations
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.
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 from AWS Secrets Manager.