π‘οΈ AWS ECS Task Definition passes secrets as container environment variablesπ’
- Contextual name: π‘οΈ Task Definition passes secrets as container environment variablesπ’
- ID:
/ce/ca/aws/ecs/task-definition-secrets-as-environment-variables - Tags:
- π’ Policy with categories
- π’ Policy with type
- π’ Production policy
- Policy Type:
COMPLIANCE_POLICY - Policy Categories:
SECURITY
Logicβ
- π§ prod.logic.yamlπ’
Similar Policiesβ
- AWS Security Hub: [ECS.8] Secrets should not be passed as container environment variables
Descriptionβ
Descriptionβ
This policy identifies AWS ECS Task Definitions that contain environment variables potentially holding sensitive information. It inspects the
environmentparameters within container definitions for variable names that include keywords such asPASSWORD,SECRET,API_KEY,ACCESS_KEY, orTOKEN.Passing secrets as plaintext environment variables is insecure because these values are visible to anyone with access to the ECS Task Definition, via the AWS Console, CLI, or API, and may also appear in CloudFormation templates, logs, or audit records.
Rationaleβ
Sensitive data should never be hardcoded directly into application manifests or configuration files. Environment variables are frequently exposed in logs, dashboards, or version histories. Changes to task definitions create new immutable revisions, potentially preserving plaintext secrets indefinitely.
AWS offers secure alternatives for handling sensitive values, such as AWS Secrets Manager and AWS Systems Manager Parameter Store, both of which allow applications to retrieve secrets at runtime without embedding them directly in task definitions.
... see more
Remediationβ
Remediationβ
Move Sensitive Data to AWS Secrets Managerβ
Using the AWS CLIβ
Sensitive data should be stored securely and referenced in ECS Task Definitions via the
secretsparameter rather than embedding it inenvironmentvariables.
Store the secret in AWS Secrets Manager
aws secretsmanager create-secret \
--name "{{app/db_password}}" \
--secret-string "{{secret-password}}"Retrieve the existing task definition
aws ecs describe-task-definition \
--task-definition {{family-or-full-arn}} \
--query 'taskDefinition' > task-def.jsonUpdate
task-def.jsonMove the sensitive entry from
environmenttosecrets.Before:
"environment": [
{ "name": "{{DB_PASSWORD}}", "value": "{{secret-password}}" }
]After:
"environment": [],
"secrets": [
{ "name": "{{DB_PASSWORD}}", "valueFrom": "{{arn:aws:ssm:region:account:parameter/app/db_password}}" }
]Register the updated task definition
... see more