Bump aws-smithy-mocks from 0.1.3 to 0.2.6 (#186)
Bumps aws-smithy-mocks from 0.1.3 to 0.2.6.
Commits
- See full diff in compare view
Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
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.git[ 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 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.
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".File-based credentials
By default, the Secrets Manager Agent uses the AWS SDK default credential provider chain to authenticate with Secrets Manager. This works well on Amazon EC2 (via IMDS), Lambda, and ECS/EKS (via container credentials).
For environments where credentials are delivered to the filesystem — such as on-premises hosts using IAM Roles Anywhere or other credential management systems — you can configure the agent to read credentials from a file.
Credentials file format
The credentials file must use the standard AWS credentials file format:
Configuration
Set the
credentials_file_pathparameter in your configuration file:Credential refresh behavior
The agent automatically detects and re-reads updated credentials from the file:
Startup behavior
The agent is designed to start successfully regardless of the credentials file state:
validate_credentialssetting continues to apply for non-file-based credential sources.Security
On Unix systems, the agent logs a warning if the credentials file has permissions more permissive than owner-only (
0600). Consider restricting file permissions: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.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:DeleteSecretRunning 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 requestsfile_credentials.rs- Tests file-based credential loading including valid/invalid/missing credentials, self-healing (credentials appearing after startup), and credential rotation