feat: add workload identity federation support for AWS ECS tasks (#496)#674
Open
cy-yun wants to merge 2 commits into
Open
feat: add workload identity federation support for AWS ECS tasks (#496)#674cy-yun wants to merge 2 commits into
cy-yun wants to merge 2 commits into
Conversation
cy-yun
force-pushed
the
ecs-wif-support
branch
3 times, most recently
from
July 7, 2026 07:18
54fe56d to
06f782a
Compare
bshaffer
reviewed
Jul 21, 2026
bshaffer
left a comment
Contributor
There was a problem hiding this comment.
This looks great!
I do have a few questions about the local ecs mock server. Is it testing anything that we aren't already testing with mocks in AwsNativeSourceTest? Or is it testing anything that we couldn't go ahead and test with mocks? Looking at the scenarios, they aren't really complex enough to justify a mock server.
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.
Add support for AWS ECS (Elastic Container Service) credentials in AwsNativeSource
Description
This PR introduces native support for retrieving AWS credentials from the ECS Container Metadata endpoint within
AwsNativeSource.Previously, when running applications inside an Amazon ECS or AWS Fargate container with IAM Roles for Tasks configured, the library could not automatically resolve the temporary container credentials, as it primarily supported EC2 IMDSv2 metadata endpoints, explicit credentials via URLs, or static environment variables (
AWS_ACCESS_KEY_ID, etc).With this change,
AwsNativeSourcenatively honors standard AWS ECS environment variables:AWS_CONTAINER_CREDENTIALS_RELATIVE_URIAWS_CONTAINER_CREDENTIALS_FULL_URIAWS_CONTAINER_AUTHORIZATION_TOKENAWS_CONTAINER_AUTHORIZATION_TOKEN_FILEWhen detected, the library fetches the temporary
AccessKeyId,SecretAccessKey, andTokenfrom the ECS metadata server, allowing seamless workload identity federation between AWS ECS/Fargate and Google Cloud.Changes Made
AwsNativeSource::getSigningVarsFromEcsto probe and execute HTTP requests to the ECS container metadata endpoint.AWS_CONTAINER_AUTHORIZATION_TOKENandAWS_CONTAINER_AUTHORIZATION_TOKEN_FILE).getSigningVarsFromEcsinto the credential resolution fallback chain (after Env variables, but before generic URLs).AwsNativeSourceTestfor both relative and full URI resolutions, as well as token/file variations.Additional End-to-End Testing
Because the ECS credential fetcher relies heavily on interacting with AWS's link-local Task Metadata Endpoint, I've also added a standalone end-to-end testing harness alongside our standard unit tests.
This includes:
local-ecs-mock-server.php) that explicitly simulates the behavior (and edge cases) of the actual AWS metadata server.tests.ymlwhich spins up the mock server in the background and runs the SDK against it across every supported version of PHP. This verifies that theGuzzleHttpclient handles real TCP socket negotiations, malformed JSON, missing fields, and HTTP 500 errors gracefully in a true runtime environment.How the Customer Uses It
Customers do not need to change any application code.
When a PHP application using
google/authis deployed on Amazon ECS or AWS Fargate with a Task IAM Role assigned, the flow works automatically:GOOGLE_APPLICATION_CREDENTIALSenvironment variable to point to this JSON file in their container.AWS_CONTAINER_CREDENTIALS_RELATIVE_URIenvironment variable into the running container implicitly.GetCallerIdentityrequest, and exchanges it securely for a Google Cloud token.End-to-End Testing Report: AWS ECS (Fargate) Workload Identity Federation
In addition to the automated local PHP mock server tests included in this PR, I have successfully conducted a manual end-to-end verification of this feature in a live AWS ECS environment.
Test Environment Setup:
roles/iam.workloadIdentityUser).php:8.1-cliimage running a standalone PHP script utilizing the compiled branch ofgoogle-auth-library-php.client_config.jsongenerated viagcloud iam workload-identity-pools create-cred-configinjected via theGOOGLE_APPLICATION_CREDENTIALSenvironment variable.Verification Steps & Results:
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIenvironment variable automatically injected by the ECS Fargate runtime.EcsCredentialsfetcher successfully communicated with the AWS link-local Task Metadata Endpoint (169.254.170.2) and retrieved the temporary AWS Role credentials (AccessKeyId,SecretAccessKey,Token).https://sts.googleapis.com/v1/tokenfor a federated identity token.generateAccessTokenon the target GCP Service Account.ApplicationDefaultCredentials::getCredentials()call successfully returned a valid, usable GCP access token scoped tohttps://www.googleapis.com/auth/cloud-platform.Conclusion:
The AWS ECS credential fetcher operates entirely seamlessly within the existing Application Default Credentials (ADC) pipeline. The container correctly authenticates to GCP purely via its attached AWS ECS Task Role without requiring any static keys.