Skip to content

feat(ecs): task role credentials + secrets injection#728

Merged
vieiralucas merged 1 commit intomainfrom
worktree-ecr-ecs-tighten-batch3
Apr 24, 2026
Merged

feat(ecs): task role credentials + secrets injection#728
vieiralucas merged 1 commit intomainfrom
worktree-ecr-ecs-tighten-batch3

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 24, 2026

Summary

Batch 3 of the ECR+ECS tightening pass. Closes the last two deferred ECS runtime integrations:

  • Task role credentials — tasks with taskRoleArn get AWS_CONTAINER_CREDENTIALS_FULL_URI injected and a new /_fakecloud/ecs/creds/:task_id endpoint vends IMDS-format creds. AWS SDKs discover it via the default provider chain, so aws sts get-caller-identity works from inside the container with zero container-side setup.
  • Secrets injectionsecrets[] entries with SecretsManager or SSM parameter ARNs resolve synchronously before docker run and land as env vars. Missing refs -> TaskFailedToStart.
  • Builder methods: EcsRuntime::with_secretsmanager / with_ssm. Unwired runtime behaviour is unchanged (test ergonomics).

Test plan

  • cargo test -p fakecloud-e2e --test ecs_task_role_secrets — all four E2E tests pass
  • cargo test -p fakecloud-ecs -p fakecloud-core -p fakecloud-lambda -p fakecloud-ecr — unit tests green
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • CI + Cubic

Summary by cubic

Add ECS task-role credentials and secrets injection so containers can use AWS SDKs out of the box and get env vars from Secrets Manager and SSM. Tasks without required secrets now fail fast with TaskFailedToStart.

  • New Features
    • Task-role creds: inject AWS_CONTAINER_CREDENTIALS_FULL_URI for tasks with taskRoleArn; /_fakecloud/ecs/creds/{task_id} serves IMDS-format creds so aws sts get-caller-identity works inside the container.
    • Secrets injection: resolve containerDefinitions[].secrets[] from Secrets Manager and SSM before docker run; missing refs -> stopCode=TaskFailedToStart.
    • Builder methods in EcsRuntime: with_secretsmanager and with_ssm; server wires them alongside logs and EventBridge.
    • Docs updated with the credential JSON shape and a secrets[] example; 4 new E2E tests cover creds, Secrets Manager, SSM, and missing-secret failure.

Written for commit ad2683b. Summary will update on new commits.

Batch 3 of the ECR+ECS tightening pass. Closes the last two deferred
ECS runtime integrations so containers running under fakecloud behave
exactly like they would against real AWS — credential vending via
`AWS_CONTAINER_CREDENTIALS_FULL_URI`, and `secrets[]` resolution from
SecretsManager + SSM Parameter Store.

- `EcsRuntime` gains `with_secretsmanager` / `with_ssm` builder
  methods. Wired via the server alongside the Batch 2 EventBridge +
  CloudWatch-Logs plumbing.

- Before `docker run`, the runtime walks the container's `secrets[]`
  field and resolves each `valueFrom` ARN against the corresponding
  in-process state:
  - `arn:aws:secretsmanager:...:secret:<name>-<6>` -> current-version
    `secret_string` on the matching `Secret`. The AWS-generated 6-char
    suffix is stripped during the lookup.
  - `arn:aws:ssm:...:parameter/<name>` -> `value` on the matching
    `SsmParameter`.
  Resolved values go in as env vars. A missing secret/parameter fails
  the task with `stopCode=TaskFailedToStart`, matching real ECS.

- When the task registers a `taskRoleArn`, the runtime injects
  `AWS_CONTAINER_CREDENTIALS_FULL_URI=http://host.docker.internal:<port>
  /_fakecloud/ecs/creds/<task-id>`. The server exposes that new route
  returning IMDS-format JSON
  (`{AccessKeyId, SecretAccessKey, Token, Expiration, RoleArn}`). AWS
  SDKs discover it via the default provider chain, so
  `aws sts get-caller-identity` etc. work out of the box from inside
  the container.

- Four new E2E tests under `ecs_task_role_secrets.rs`:
  1. `task_role_credentials_are_served` — asserts env-var injection
     + probes the credential endpoint directly for IMDS shape.
  2. `resolves_secretsmanager_secret` — runs a task, asserts the
     captured stdout contains the secret value.
  3. `resolves_ssm_parameter` — same, via SSM.
  4. `missing_secret_fails_fast` — missing secret -> TaskFailedToStart.

- ECS docs updated with the credential-endpoint JSON shape and the
  secrets[] example.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 0% with 102 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-ecs/src/runtime.rs 0.00% 72 Missing ⚠️
crates/fakecloud-server/src/main.rs 0.00% 30 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

@vieiralucas vieiralucas merged commit b8350c6 into main Apr 24, 2026
38 checks passed
@vieiralucas vieiralucas deleted the worktree-ecr-ecs-tighten-batch3 branch April 24, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant