Configuring AWS Secrets Manager
Flyte supports two primary methods for integrating with AWS Secrets Manager: Sidecar-based and Embedded. Sidecar-based integration uses an AWS-provided init-container to fetch secrets, while Embedded integration fetches secrets directly within the Flyte Pod Webhook and injects them into the task pod.
Sidecar-based Integration
The sidecar-based integration (SecretManagerTypeAWS) injects an AWS Secrets Manager sidecar as an init-container for every secret requested by a task. This method is robust but can increase pod startup time if many secrets are used, as each secret results in a separate init-container.
Configuration
To enable sidecar-based integration, update the webhook section of your Flyte configuration. The configuration is defined in flyteplugins/go/tasks/pluginmachinery/secret/config/config.go.
webhook:
secretManagerTypes:
- AWS
awsSecretManager:
# The sidecar image used to pull secrets
sidecarImage: "docker.io/amazon/aws-secrets-manager-secret-sidecar:v0.1.4"
resources:
requests:
cpu: 200m
memory: 500Mi
limits:
cpu: 200m
memory: 500Mi
Usage and Permissions
When using sidecar mode, secrets are mounted as files at /etc/flyte/secrets/<group>/<key>.
- IAM Permissions: The Task Pod's ServiceAccount must have the
secretsmanager:GetSecretValuepermission for the target secrets. - Secret Definition: Define the secret using the ARN as the
groupand the secret name as thekey. TheAWSSecretManagerInjectorjoins these to form the full identifier.
from flytekit import task, Secret
# The sidecar will use the group as the ARN and key as the filename
@task(secret_requests=[Secret(group="arn:aws:secretsmanager:region:account:secret:my-secret", key="my-key")])
def my_task():
# Secret will be available at /etc/flyte/secrets/arn:aws:secretsmanager:region:account:secret:my-secret/my-key
...
Embedded Integration
The embedded integration (SecretManagerTypeEmbedded) is more efficient as it avoids multiple sidecars. The Flyte Pod Webhook fetches the secret values during the pod mutation phase using the AWSSecretFetcher and injects them directly as environment variables or via a single shared init-container for file mounts.
Configuration
To enable embedded integration, configure the webhook to use the Embedded type and specify AWS as the provider:
webhook:
secretManagerTypes:
- Embedded
embeddedSecretManagerConfig:
type: AWS
awsConfig:
region: "us-west-2"
fileMountInitContainer:
image: "public.ecr.aws/docker/library/busybox:latest"
resources:
requests:
cpu: 100m
memory: 100Mi
Naming Convention and Scoping
Embedded mode uses a hierarchical naming convention to look up secrets in AWS Secrets Manager. It searches for secrets in the following order of specificity (defined in flyteplugins/go/tasks/pluginmachinery/secret/utils.go):
u__org__<org>__domain__<domain>__project__<project>__key__<key>u__org__<org>__domain__<domain>__key__<key>u__org__<org>__key__<key>
Usage and Permissions
- IAM Permissions: The Flyte Pod Webhook's ServiceAccount must have the
secretsmanager:GetSecretValuepermission for the secrets it needs to fetch. - Secret Definition: Define the secret in your task using the
key. Thegroupis ignored in embedded mode as the lookup is based on the pod's labels (org, domain, project).
from flytekit import task, Secret
@task(secret_requests=[Secret(key="my-api-key", mount_requirement=Secret.MountRequirement.ENV_VAR)])
def my_task():
# Secret will be available as an environment variable (default prefix _UNION_)
# e.g., _UNION_MY-API-KEY
...
Configuration Reference
The following configuration keys are available under the webhook section:
| Key | Default | Description |
|---|---|---|
awsSecretManager.sidecarImage | docker.io/amazon/aws-secrets-manager-secret-sidecar:v0.1.4 | Image for the AWS sidecar init-container. |
embeddedSecretManagerConfig.type | AWS | The provider for embedded secret management. |
embeddedSecretManagerConfig.awsConfig.region | "" | The AWS region for the embedded fetcher. |
embeddedSecretManagerConfig.fileMountInitContainer.image | public.ecr.aws/docker/library/busybox:latest | Image used to write secrets to files in embedded mode. |
secretEnvVarPrefix | _UNION_ | Prefix for secret environment variables. |
Troubleshooting
- Sidecar Failures: If the sidecar init-container fails, check the Task Pod's IAM permissions. The sidecar logs will typically indicate an
AccessDeniederror if permissions are missing. - Embedded Lookup Failures: If a secret is not found in embedded mode, ensure the secret name in AWS Secrets Manager exactly matches the
u__org__...format. The Flyte Pod Webhook logs will show the exact IDs it attempted to fetch. - File Mount Paths:
- In Sidecar mode, secrets are mounted under
/etc/flyte/secrets/<group>/<key>. - In Embedded mode, secrets are mounted under
/etc/flyte/secrets/<key>.
- In Sidecar mode, secrets are mounted under
- Binary Secrets: In embedded mode, if a secret is stored as binary data in AWS, it must be a valid UTF-8 string to be mounted as an environment variable; otherwise, it must be requested as a
FILEmount.