ECS Secrets in Plaintext
ecs-secrets-plaintext
What this rule checks
Detects ECS task definitions with sensitive data in plaintext environment variables.
How to fix it
- 1Use secrets property with Secrets Manager ARN
- 2Use SSM Parameter Store SecureString
import { aws_ecs as ecs } from 'aws-cdk-lib';
const taskDef = new ecs.FargateTaskDefinition(this, 'TaskDef');
taskDef.addContainer('app', {
image: ecs.ContainerImage.fromRegistry('my-app'),
environment: {
DB_PASSWORD: 'S3cr3tP@ssw0rd!',
},
});import { aws_ecs as ecs, aws_secretsmanager as secretsmanager } from 'aws-cdk-lib';
const dbSecret = secretsmanager.Secret.fromSecretNameV2(this, 'DbSecret', 'prod/db');
const taskDef = new ecs.FargateTaskDefinition(this, 'TaskDef');
taskDef.addContainer('app', {
image: ecs.ContainerImage.fromRegistry('my-app'),
secrets: {
DB_PASSWORD: ecs.Secret.fromSecretsManager(dbSecret, 'password'),
},
});CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.
Affected resource types
AWS::ECS::TaskDefinitionIntentional? Suppress this finding
Sometimes a flag is deliberate โ a genuinely public endpoint, say. You can dismiss ecs-secrets-plaintext and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "ecs-secrets-plaintext", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::ecs-secrets-plaintext',
reason: 'Why this is intentional',
});Use the rule ID ecs-secrets-plaintext shown above โ not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs โ
Catch this in your stack
$ npx cdk-insights scanCDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ free, no account, your code never leaves your machine.