Skip to main content
HIGHECSSecurity

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

  1. 1Use secrets property with Secrets Manager ARN
  2. 2Use SSM Parameter Store SecureString
FlaggedThe database password is injected as a plaintext environment variable, exposing it in the task definition.
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!',
  },
});
FixedUsing the secrets property with ecs.Secret.fromSecretsManager resolves the password from Secrets Manager at runtime instead of storing it in plaintext.
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::TaskDefinition

Compliance frameworks

SOC2HIPAAPCI-DSSNIST

AWS documentation

Read the AWS guidance

Intentional? 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 scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More ECS rules