How secrets injection works
- A workflow author declares a secret request in their
@taskdecorator - FlytePropeller intercepts the pod creation and calls the configured secrets manager backend
- The secret value is injected into the pod as an environment variable or a mounted file
- The task code retrieves the secret using
flytekit.current_context().get_secret()
Declaring secrets in task code
Backends
Kubernetes Secrets (default)
The default backend reads from KubernetesSecret objects. Create the secret before running the workflow:
flytesnacks-development).
Secret names in Flyte map to Kubernetes Secret names. The
group parameter in Secret(group=..., key=...) maps to the Kubernetes Secret metadata.name. The key maps to the Secret data key.AWS Secrets Manager
The AWS Secrets Manager backend fetches secrets from AWS at pod creation time. Enable it in FlytePropeller config:group:
FLYTE_SECRETS_ENV_PREFIX environment variable and retrieves secrets before the task container starts.
HashiCorp Vault
Flyte integrates with Vault via the pod webhook. Configure Vault Agent Injector in your cluster, then annotate the default PodTemplate to instruct the injector:/vault/secrets/my-db-credentials inside the task container. Use Secret.MountType.FILE to read it:
Secrets for the entire workflow
Secrets can also be declared at the workflow level and inherited by all tasks:Environment variable injection
Whenmount_requirement=Secret.MountType.ENV_VAR, the secret is injected as:
Secret(group="my-db-credentials", key="password") becomes:
File injection
Whenmount_requirement=Secret.MountType.FILE, the secret is written to:
/etc/flyte/secrets/my-db-credentials/password
Best practices
Never hardcode secrets in task code
Never hardcode secrets in task code
Always use the
secret_requests parameter and ctx.get_secret(). Hardcoded secrets end up in your workflow spec and are visible to anyone with FlyteAdmin access.Use separate secrets per environment
Use separate secrets per environment
Create secrets in each project-domain namespace separately (e.g.,
flytesnacks-development vs flytesnacks-production). This ensures tasks in different environments use different credentials.Rotate secrets without redeploying workflows
Rotate secrets without redeploying workflows
Because secrets are resolved at runtime by FlytePropeller, you can rotate a Kubernetes Secret or update an AWS Secrets Manager value and the next workflow execution will pick up the new value automatically.
Restrict RBAC to secrets
Restrict RBAC to secrets
Use Kubernetes RBAC to restrict which service accounts can read which secrets. FlytePropeller’s service account only needs
get access to secrets in the flyte namespace, not in task namespaces.