Update dependencies (#210)
Description
Why is this change being made?
- Dependencies were failing to auto-update due to new licenses being introduced in the dependency chain.
What is changing?
- Ran
cargo update- Manually bumped some of the pre 1.0.0 dependencies
- Disabled default features on
configand manually enabledtomlsince it is the only one we use. This saves about 1MB of binary size and prevents future feature additions (new config formats) from tripping cargo-deny if they do not have their license already allowlisted. https://docs.rs/crate/config/latest/featuresrandchanged their iterator syntax.reqwestdropped the rustls feature since it’s now the default.Related Links
- Issue #, if available:
Testing
How was this tested?
cargo testcargo benchcargo-deny check licensesWhen testing locally, provide testing artifact(s):
Reviewee Checklist
Update the checklist after submitting the PR
- I have reviewed, tested and understand all changes If not, why:
- I have filled out the Description and Testing sections above If not, why:
- Build and Unit tests are passing If not, why:
- Unit test coverage check is passing If not, why:
- Integration tests pass locally If not, why: Running in GH actions.
- I have updated integration tests (if needed) If not, why: N/A
- I have ensured no sensitive information is leaking (i.e., no logging of sensitive fields, or otherwise) If not, why:
- I have added explanatory comments for complex logic, new classes/methods and new tests If not, why: N/A
- I have updated README/documentation (if needed) If not, why: N/A
- I have clearly called out breaking changes (if any) If not, why: N/A
Reviewer Checklist
All reviewers please ensure the following are true before reviewing:
- Reviewee checklist has been accurately filled out
- Code changes align with stated purpose in description
- Test coverage adequately validates the changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
AWS Secrets Manager Agent
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. The Agent also uses the post-quantum ML-KEM key exchange as the highest-priority key exchange by default. 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
--configcommand 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 on GitHub.
Topics
refreshNowparameter behaviorStep 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.
NOTE: To ensure a stable experience, use a specific git tag when building from source code. You can find a list of version tags here. Tags are in the pattern
/v\d+\.\d+\.\d+/and follow SemVer 2.0.0.Example:
git clone --branch <git tag> https://github.com/aws/aws-secretsmanager-agent.gitNOTE: Building the agent with the
fipsfeature enabled on macOS currently requires the following workaround:SDKROOTwhich is set to the result of runningxcrun --show-sdk-path[ RPM-based systems ]
On RPM-based systems such as AL2023, you can install the development tools by using the Development Tools group.
Follow the instructions at Install Rust in the Rust documentation.
Build the agent using the cargo build command:
You will find the executable under
target/release/aws_secretsmanager_agent.[ Debian-based systems ]
On Debian-based systems such as Ubuntu, you can install the developer tools using the build-essential package.
Follow the instructions at Install Rust in the Rust documentation.
Build the agent using the cargo build command:
You will find the executable under
target/release/aws_secretsmanager_agent.[ Windows ]
To build on Windows, follow the instructions at Set up your dev environment on Windows for Rust in the Microsoft Windows documentation.
Build the agent using the cargo build command:
You will find the executable under
target/release/aws_secretsmanager_agent.exe.[ Cross-compile natively ]
On distributions where the mingw-w64 package is available such as Ubuntu, you can cross compile natively.
You will find the executable at
target/x86_64-pc-windows-gnu/release/aws_secretsmanager_agent.exe.[ Cross compile with Rust cross ]
If the cross compile tools are not available natively on the system, you can use the Rust cross project. For more information, see https://github.com/cross-rs/cross.
Important
We recommend 32GB disk space for the build environment.
Step 2: Install the Secrets Manager Agent
Based on the type of compute, you have several options for installing the Secrets Manager Agent.
[ Amazon EC2 ]
To install the Secrets Manager Agent
cd aws_secretsmanager_agent/configurationRun the
installscript 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 theawssmatokenreadergroup 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
awssmatokenreadergroup. 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.[ Running as a Container Sidecar ]
You can run the Secrets Manager Agent as a sidecar container alongside your application by using Docker. Then your application can retrieve secrets from the local HTTP server the Secrets Manager Agent provides. For information about Docker, see the Docker documentation.
To create a sidecar container for the Secrets Manager Agent with Docker
Create a Dockerfile for the Secrets Manager Agent sidecar container. The following example creates a Docker container with the Secrets Manager Agent binary.
Create a Dockerfile for your client application.
Create a Docker Compose file to run both containers, being sure that they use the same network interface. This is necessary because the Secrets Manager Agent does not accept requests from outside the localhost interface. The following example shows a Docker Compose file where the
network_modekey attaches thesecrets-manager-agentcontainer to the network namespace of theclient-applicationcontainer, which allows them to share the same network interface.Important
You must load AWS credentials and the SSRF token for the application to be able to use the Secrets Manager Agent. For EKS and ECS, see the following:
Copy the
secrets-manager-agentbinary to the same directory that contains your Dockerfiles and Docker Compose file.Build and run the containers based on the provided Dockerfiles by using the following https://docs.docker.com/reference/cli/docker/compose/ command.
In your client container, you can now use the Secrets Manager Agent to retrieve secrets. For more information, see Step 3: Retrieve secrets with the Secrets Manager Agent.
[ AWS Lambda ]
You can package the Secrets Manager Agent as an AWS Lambda extension. Then you can add it to your Lambda function as a layer and call the Secrets Manager Agent from your Lambda function to get secrets.
The following instructions show how to get a secret named MyTest by using the example script
secrets-manager-agent-extension.shin https://github.com/aws/aws-secretsmanager-agent to install the Secrets Manager Agent as a Lambda extension.To create a Lambda extension that packages the Secrets Manager Agent
Package the agent as a layer. From the root of the Secrets Manager Agent code package, run the following example commands:
The default configuration of the agent will automatically set the SSRF token to the value set in the pre-set
AWS_SESSION_TOKENorAWS_CONTAINER_AUTHORIZATION_TOKENenvironment variables (the latter variable for Lambda functions with SnapStart enabled). Alternatively, you can define theAWS_TOKENenvironment variable with an arbitrary value for your Lambda function instead as this variable takes precedence over the other two. If you choose to use theAWS_TOKENenvironment variable, you must set that environment variable with alambda:UpdateFunctionConfigurationcall.http://localhost:2773/secretsmanager/get?secretId=MyTestwith theX-Aws-Parameters-Secrets-Tokenheader value set to the value of the SSRF token sourced from one the environment variables mentioned above to retrieve the secret. Be sure to implement retry logic in your application code to accommodate delays in initialization and registration of the Lambda extension.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
AWSCURRENTversion of the secret. To retrieve a different version, you can setversionStageorversionId. To retrieve a secret using a different IAM role, you can setroleArn. For more information, see Role chaining (cross-account access).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 https://docs.aws.amazon.com/sdk-for-rust/latest/dg/credentials.html. The identity of these IAM credentials determines the permissions the Secrets Manager Agent has to retrieve secrets.
**Required permissions: **
secretsmanager:DescribeSecretsecretsmanager:GetSecretValueFor 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.
[ curl ]
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.
[ Python ]
The following Python 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.
Force-refresh secrets with
RefreshNowLearn how to use the refreshNow parameter to force the Secrets Manager Agent (SMA) to refresh secret values.
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
refreshNowin 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):Behavior with
refreshNow=true:By using the
refreshNowparameter, you can ensure that you’re always working with the most current secret values, even in scenarios where frequent secret rotation is necessary.refreshNowparameter behaviorrefreshNowset totrue:refreshNowset tofalseor not specified:Using the refreshNow parameter
To use the
refreshNowparameter, include it in the URL for the Secrets Manager Agent GET request.Example - Secrets Manager Agent GET request with refreshNow parameter
[ curl ]
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.
[ Python ]
The following Python 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.
Role chaining (cross-account access)
The Secrets Manager Agent supports retrieving secrets using IAM role assumption (role chaining). This allows you to access secrets in other AWS accounts or with different IAM permissions without running separate agent instances.
To retrieve a secret using a different IAM role, include the
roleArnquery parameter in your request. The Secrets Manager Agent uses STSAssumeRoleto obtain temporary credentials for the specified role and then retrieves the secret with those credentials.The Secrets Manager Agent creates and caches a separate caching client for each unique role ARN. Role clients are created lazily on first request and reused for subsequent requests with the same role ARN. Each role client maintains its own independent cache, so the same secret fetched with different roles will have separate cache entries.
**Required permissions: **
sts:AssumeRoleon the target role ARNsecretsmanager:GetSecretValueandsecretsmanager:DescribeSecretpermissions**Error responses: **
400– If theroleArnformat is invalid or the maximum number of assumed roles has been reached.403– If the STSAssumeRolecall fails (for example, the trust policy does not allow the agent’s identity to assume the role).You can configure the maximum number of simultaneous assumed roles with the
max_rolesoption in the Configuration file. The default is 20.Note: Assumed roles are not evicted from the agent’s role cache. Once the maximum number of roles has been reached, requests with new role ARNs will be rejected with a
400error until the agent is restarted.[ curl ]
The following curl example shows how to retrieve a secret using a different IAM role.
[ Python ]
The following Python example shows how to retrieve a secret using a different IAM role.
Pre-fetching
The Secrets Manager Agent supports pre-fetching secrets into the cache at startup. This allows your application to read secrets from the cache immediately without waiting for the first request to trigger a cache miss and network call.
To enable pre-fetching, add a
[prefetch]section to your Configuration file. You can specify secrets to pre-fetch in two ways:[[prefetch.secrets]]entries.[[prefetch.filter_tags]]entries. The agent callsBatchGetSecretValuewith tag key filters to find and cache all secrets that have the specified tag key, regardless of the tag’s value.You can use both methods together. Each entry optionally accepts a
role_arnfield for cross-account pre-fetching via role chaining.**Required permissions: **
secretsmanager:BatchGetSecretValue– Required for all pre-fetching operations.secretsmanager:ListSecrets– Required when using tag-based discovery (filter_tags).**Pre-fetch configuration options: **
Example - Pre-fetch with explicit secrets
Example - Pre-fetch with explicit secrets (inline syntax)
Example - Pre-fetch with tag-based discovery
Example - Full configuration with pre-fetching
Configure the Secrets Manager Agent
To change the configuration of the Secrets Manager Agent, create a TOML config file, and then call
./aws_secretsmanager_agent --config config.toml.The following list shows the options you can configure for the Secrets Manager Agent.
trueorfalse. The default istrue.AWS_TOKEN=file:///var/run/awssmatoken. The default is “AWS_TOKEN, AWS_SESSION_TOKEN, AWS_CONTAINER_AUTHORIZATION_TOKEN".Optional features
The Secrets Manager Agent can be built with optional features by passing the
--featuresflag tocargo build. The available features are:fips: restricts the cipher suites used by the agent to only FIPS-approved ciphersLogging
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.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.
Running Integration Tests Locally
The AWS Secrets Manager Agent includes a comprehensive integration test suite that validates functionality against real AWS Secrets Manager. These tests cover caching behavior, security features, configuration options, version management, and error handling scenarios.
Prerequisites
Required AWS Permissions
Your AWS credentials must have the following permissions:
secretsmanager:CreateSecretsecretsmanager:GetSecretValuesecretsmanager:DescribeSecretsecretsmanager:UpdateSecretsecretsmanager:UpdateSecretVersionStagesecretsmanager:PutSecretValuesecretsmanager:DeleteSecretsecretsmanager:BatchGetSecretValuesecretsmanager:ListSecretssts:AssumeRoleRequired IAM Roles (for role chaining tests)
The role chaining integration tests require two IAM roles in the same account:
secrets-manager-agent— Must be assumable by the test runner’s identity and havesecretsmanager:GetSecretValueandsecretsmanager:DescribeSecretpermissions.secrets-manager-agent-no-access— Must be assumable by the test runner’s identity but have no Secrets Manager permissions. Used to verify access-denied behavior.Both roles must have a trust policy that allows the identity running the tests to call
sts:AssumeRole. The account ID is discovered automatically viasts:GetCallerIdentity.Running Tests
Option 1: Using the test script
Configure your AWS credentials with appropriate permissions
Run the test script:
Option 2: Manual execution
Configure your AWS credentials with appropriate permissions
Build the agent binary:
Run the integration tests:
Test Organization
The integration tests are organized into the following modules:
secret_retrieval.rs- Tests core secret retrieval functionality including name/ARN lookup, binary secrets, large secrets, and error handlingcache_behavior.rs- Tests caching mechanisms including TTL expiration, refreshNow parameter, and cache bypass (TTL=0)security.rs- Tests security features including SSRF token validation and X-Forwarded-For header rejectionversion_management.rs- Tests secret version transitions and rotation scenariosconfiguration.rs- Tests configuration parameters including health checks and path-based requestsrole_chaining.rs- Tests cross-account secret retrieval via IAM role assumption, including invalid role ARN handling, access denied scenarios, refreshNow with role chaining, and separate per-role cache isolationprefetch.rs- Tests pre-fetching secrets into the cache at startup, including explicit secrets, tag-based discovery, inline TOML syntax, cross-account pre-fetching via role chaining, and resilience to nonexistent secrets