Skip to content

A task cannot read its secret

2 min read · main part only; folded sections are optional

After this you can answer: Which role needs permission when an ECS task cannot load a secret?

Diagnostic scenario: a stopped task reports ResourceInitializationError, with AccessDeniedException and secretsmanager:GetSecretValue in the detail. The application has not started. No historical MiniTickets outage is asserted here.

ECS asks Secrets Manager for startup values using the execution role. This denial is Allowed, not a database Password failure. A timeout contacting Secrets Manager is Reach. Read the full suffix: a missing identity-policy grant differs from an explicit deny, and ResourceNotFoundException points toward a secret/version reference.

flowchart TB
A[Secret initialization failed] --> B{Timeout?}
B -->|yes| C[Check task network]
B -->|no| D{Access denied?}
D -->|yes| E[Check execution-role policy and deny]
D -->|no| F[Check ARN, JSON key and current version]
E --> G[Check KMS only for a customer key]

Rank by the error, then recent changes:

  1. Denied after recreation: read-secrets still names an old secret ARN, or the task uses the wrong execution role.
  2. Not found/key error: wrong region, ARN, JSON key, or missing current secret version.
  3. Timeout: task cannot reach Secrets Manager’s HTTPS endpoint.
  4. Customer-managed KMS key only: missing decryption permission or restrictive key policy. MiniTickets uses the default Secrets Manager key for these secrets.

ECS → stopped task → Stopped reason → task definition → Task execution role and secret references. Compare IAM → read-secrets with Secrets Manager → secret ARN and Versions. Do not reveal the secret value.

Correct the reference or the smallest execution-role grant in infra/src/compute/iam.ts → createIamRoles. The API requests username and password JSON keys in infra/src/compute/task.ts → createApiTask. Use the web’s separate execution role for its revalidate secret.

Pass secret ARNs from their defining resources instead of copying strings. Start tasks only after a secret version exists. After rotation, arrange a reviewed rollout: existing environment variables do not refresh themselves.

Advanced: Startup success does not guarantee a current password

API startup reads the RDS-managed JSON secret, the Redis URL, and the revalidate secret when entry is enabled. Web startup reads only the revalidate secret. Its role is defined in infra/src/compute/web-iam.ts → createWebIamRole.

The API task’s password can become stale after RDS rotates it. A running container then gets a Postgres authentication error, not a startup IAM denial. See the scheduled-Lambda diagnosis. AWS documents startup injection and rotation. AWS lists initialization error branches.

Read this book online: https://book.theversehub.in/