Forward container credential variables to the AWS CLI - #2456
Open
AgustinRamiroDiaz wants to merge 1 commit into
Open
Forward container credential variables to the AWS CLI#2456AgustinRamiroDiaz wants to merge 1 commit into
AgustinRamiroDiaz wants to merge 1 commit into
Conversation
The AWS CLI block builds the child process environment from scratch and executeFile() replaces the environment rather than merging it, so the CLI only ever sees AWS_DEFAULT_REGION, PATH and HOME. Under implicit role that works on EC2, where the CLI reaches the instance role over IMDS at a fixed link-local address without needing anything from the environment. It cannot work on ECS/Fargate or EKS, where the role is discoverable only through AWS_CONTAINER_CREDENTIALS_* / AWS_WEB_IDENTITY_*: the variables are dropped and every AWS CLI block fails with 'Unable to locate credentials' (exit 253), even though SDK-based blocks using the same task role succeed. Forward those variables when falling back to the implicit role. Explicit credentials are unaffected.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #2455.
Under implicit role, the AWS CLI block runs
awswith an environment that contains onlyAWS_DEFAULT_REGION,PATHandHOME—aws-cli.tsbuildsenvVarsfrom scratch andexecuteFile()setsenvrather than merging it. The CLI therefore has no way to discover the role on any platform that exposes it through the environment, and fails withNoCredentials(exit 253).This forwards the variables the CLI needs for that discovery when, and only when, we fall back to the implicit role:
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI,AWS_CONTAINER_CREDENTIALS_FULL_URI,AWS_CONTAINER_AUTHORIZATION_TOKEN,AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE— ECS and Fargate task rolesAWS_ROLE_ARN,AWS_ROLE_SESSION_NAME,AWS_WEB_IDENTITY_TOKEN_FILE— EKS IRSA / Pod IdentityAdditional Notes
Why it has not surfaced before. On EC2 the CLI reaches the instance role over IMDS at a fixed link-local address and needs nothing from the environment, which is the deployment shape the feature is documented against. Fargate has no IMDS credential provider, so the scrub is fatal there. The asymmetry is confusing in practice: SDK-based AWS blocks work on the same task role, because they run in-process where the variables are intact — only the CLI blocks fail.
Scope. Deliberately narrow. Only the implicit-role branch is touched, only variables that are already in
process.envare forwarded, and nothing is forwarded when explicit credentials are supplied (they take precedence in the chain anyway, but keeping the environment minimal seemed better than relying on that). A variable absent fromprocess.envis not added, so non-container deployments are byte-for-byte unchanged.Possibly worth a follow-up, not done here:
azure-cli.tsand the Google Cloud CLI wrapper go through the sameexecuteFile()and so have the same blind spot for managed identity / workload identity. I have not tested either, so I have left them alone.Testing Checklist
Tested on a real ECS Fargate deployment of 0.6.25 (engine as its own service, task role attached,
OPS_AWS_ENABLE_IMPLICIT_ROLE=true). Inside the engine container, reproducing the environment the block builds:where
/tmp/bin/awsis a wrapper that re-exportsAWS_CONTAINER_CREDENTIALS_RELATIVE_URIand execs the real binary — the same variable this PR forwards.Unit tests: two added (forwarding under implicit role; no forwarding with explicit credentials), and the existing cases pin the unchanged behaviour. The suite clears these variables around each test so a developer machine that has them set cannot leak into the assertions.
packages/blocks/aws: 176 tests, all passing.