This directory contains resources for building and testing a Docker image of the AWS IAM Roles Anywhere Credential Helper. The Docker image provides a containerized version of the credential helper that can be used in container environments like Kubernetes.
Follow these steps to build and test the Docker image:
-
Set up environment variables:
# Copy the template file cp .env.template myEnvironmentVariables.env # Edit the .env file with your values vim myEnvironmentVariables.env # Load the environment variables source myEnvironmentVariables.env
-
Build the Docker image:
./build.sh
This script will install Docker if necessary and build the image for your platform.
-
Run the test suite (optional):
./tests/run-tests.sh
This will set up a Kind cluster, load the image, and run all tests.
-
Run individual tests (optional):
./tests/scripts/run-test.sh <test-case-name>
Available test cases:
serve,update,update-custom-credentials-file
The following environment variables can be configured in your .env file:
These have default values if not specified:
VERSION- Image version tag (default:latest)REGISTRY- Docker registry (default:local)REPOSITORY- Image name (default:iamra-credential-helper)
These must be specified and do not have defaults:
TRUST_ANCHOR_ARN- Format:arn:aws:rolesanywhere:region:account:trust-anchor/idPROFILE_ARN- Format:arn:aws:rolesanywhere:region:account:profile/idROLE_ARN- Format:arn:aws:iam::account:role/role-name
These have default values pointing to the test certificates:
CERTIFICATE_PATH- Path to your certificate (default:tests/certs/certificate.pem)PRIVATE_KEY_PATH- Path to your private key (default:tests/certs/private_key.pem)
Dockerfile- Multi-stage Dockerfile that builds the credential helper from source and creates a minimal runtime imagebuild.sh- Script to build the Docker image with configurable parameters and automatic Docker installation if not found.env.template- Template for environment variables needed for building and testingtests/- Directory containing test resourcesrun-tests.sh- Script to run all tests for the Docker imagesetup.sh- Sets up the test environment (Kind cluster) with automatic installation of required toolskind-config.yaml- Configuration for the Kind clustercerts/- Test certificates used for authenticationpod_configurations/- Kubernetes pod configurations for different test scenariosscripts/- Test scripts for validation and executionrun-test.sh- Script to run individual testsevaluate-caller-identity.sh- Script to validate credentials using AWS STS (used by test-client in test cases)
The build.sh script builds the Docker image with configurable parameters:
# Build for the current architecture (amd64 or arm64 auto-detected)
./build.shThe script will:
- Check if Docker is installed and install it if necessary
- Detect your platform architecture (amd64 or arm64)
- Build the Docker image using
docker buildx - Create two tags:
${REGISTRY}/${REPOSITORY}:${VERSION}-${PLATFORM}(platform-specific)${REGISTRY}/${REPOSITORY}:${VERSION}(default)
The run-tests.sh script runs all tests to verify the functionality of the Docker image:
./tests/run-tests.shThis script will:
- Set up the test environment using
setup.sh - Run all three test cases sequentially
- Provide a summary of test results
You can run individual tests using the run-test.sh script:
./tests/scripts/run-test.sh <test-case-name> [timeout]Where:
<test-case-name>is one of:serve,update, orupdate-custom-credentials-file[timeout]is an optional parameter specifying how long to wait for the pod to be ready (default: 30 seconds)
The setup.sh script prepares the test environment:
- Installs
kubectlandkindif not already installed - Creates a Kind cluster or uses an existing one
- Loads the Docker image into the Kind cluster
- Creates ConfigMaps for test certificates and test resources
The Docker image is tested in three different modes:
-
Serve Mode - Tests the credential helper in serve mode, which vends temporary credentials through a local endpoint
- Configuration:
tests/pod_configurations/serve.yaml - Test validates credentials using the AWS STS get-caller-identity API
- Configuration:
-
Update Mode - Tests the credential helper in update mode, which updates temporary credentials in the AWS credentials file
- Configuration:
tests/pod_configurations/update.yaml - Runs with root privileges to write to the default AWS credentials location
- Test validates credentials using the AWS STS get-caller-identity API
- Configuration:
-
Update Mode (using AWS_SHARED_CREDENTIALS_FILE) - Tests the credential helper in update mode without root privileges
- Configuration:
tests/pod_configurations/update-custom-credentials-file.yaml - Uses environment variables to specify a custom credentials file location
- Test validates credentials using the AWS STS get-caller-identity API
- Configuration:
The Docker image is built using a multi-stage build process:
-
Build Stage:
- Uses Amazon Linux 2023 as the base image
- Installs build dependencies (golang and make)
- Builds the credential helper from source
-
Runtime Stage:
- Uses a minimal base image (eks-distro-minimal-base-glibc)
- Copies only the built binary from the build stage
- Runs as a non-root user (UID 65532)
- Sets the entrypoint to the credential helper binary
containers:
- name: credential-helper
image: local/iamra-credential-helper:latest
args:
- "serve"
- "--certificate"
- "/certs/certificate.pem"
- "--private-key"
- "/certs/private_key.pem"
- "--trust-anchor-arn"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:trust-anchor/id"
- "--profile-arn"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:profile/id"
- "--role-arn"
- "arn:<partition>:iam::<accountId>:role/role-name"
volumeMounts:
- name: certs-volume
mountPath: /certs
readOnly: truecontainers:
- name: credential-helper
image: local/iamra-credential-helper:latest
securityContext:
runAsUser: 0 # Necessary for write to root directory
args:
- "update"
- "--certificate"
- "/certs/certificate.pem"
- "--private-key"
- "/certs/private_key.pem"
- "--trust-anchor-arn"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:trust-anchor/id"
- "--profile-arn"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:profile/id"
- "--role-arn"
- "arn:<partition>:iam::<accountId>:role/role-name"
- "--profile"
- "default"
volumeMounts:
- name: certs-volume
mountPath: /certs
readOnly: true
- name: aws-credentials
mountPath: /root/.awscontainers:
- name: credential-helper
image: local/iamra-credential-helper:latest
env:
- name: AWS_SHARED_CREDENTIALS_FILE
value: "/tmp/.aws/credentials"
args:
- "update"
- "--certificate"
- "/certs/certificate.pem"
- "--private-key"
- "/certs/private_key.pem"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:trust-anchor/id"
- "--profile-arn"
- "arn:<partition>:rolesanywhere:<region>:<accountId>:profile/id"
- "--role-arn"
- "arn:<partition>:iam::<accountId>:role/role-name"
- "--profile"
- "default"
volumeMounts:
- name: certs-volume
mountPath: /certs
readOnly: true
- name: aws-credentials
mountPath: /tmp/.awsThis project is licensed under the Apache-2.0 License. See the LICENSE file in the root directory for details.