fix(google-auth): add AWS Fargate metadata endpoint support#16129
fix(google-auth): add AWS Fargate metadata endpoint support#16129ggrossman wants to merge 2 commits intogoogleapis:mainfrom
Conversation
On AWS Fargate, the IMDS security credentials endpoint does not use role names in the URL structure (unlike EC2). The current implementation unconditionally fetches the role name and appends it to the credentials URL, which fails on Fargate. This change detects Fargate environments via ECS-specific environment variables (ECS_CONTAINER_METADATA_URI_V4, ECS_CONTAINER_METADATA_URI, or AWS_EXECUTION_ENV containing AWS_ECS_FARGATE) and skips the role name lookup, calling the security credentials URL directly. Fixes googleapis/google-auth-library-python#1099
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where Google Auth's AWS security credentials supplier failed on AWS Fargate due to an incorrect assumption about the metadata endpoint URL structure. It introduces logic to detect Fargate environments and adjust the credential retrieval process to bypass the role name lookup, aligning with Fargate's metadata service behavior. This change ensures seamless authentication for applications running on Fargate while maintaining compatibility with traditional EC2 environments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for AWS Fargate metadata endpoints by detecting the Fargate environment and skipping the IAM role name lookup, which is not used in Fargate's credential URL structure. The changes are well-implemented and include comprehensive tests for the new logic and for ensuring existing EC2 behavior is preserved. The suggestion to improve code conciseness is valid and has been retained.
| if os.environ.get("ECS_CONTAINER_METADATA_URI_V4"): | ||
| return True | ||
| if os.environ.get("ECS_CONTAINER_METADATA_URI"): | ||
| return True | ||
| if "AWS_ECS_FARGATE" in os.environ.get("AWS_EXECUTION_ENV", ""): | ||
| return True | ||
| return False |
There was a problem hiding this comment.
Summary
On AWS Fargate, the IMDS security credentials endpoint does not use role names in the URL structure (unlike EC2 instances). The current
_DefaultAwsSecurityCredentialsSupplierunconditionally fetches the IAM role name and appends it to the credentials URL, which fails on Fargate with aRefreshError.This PR:
_is_fargate_environment()to detect Fargate via ECS-specific environment variables (ECS_CONTAINER_METADATA_URI_V4,ECS_CONTAINER_METADATA_URI, orAWS_EXECUTION_ENVcontainingAWS_ECS_FARGATE)Behavior comparison
{url}/{role_name}{url}(no role suffix)Files changed
packages/google-auth/google/auth/aws.py— Fargate detection + conditional role name handlingpackages/google-auth/tests/test_aws.py— 5 new test cases covering all detection methods, EC2 regression, and unit tests for_is_fargate_environment()Fixes https://github.com/googleapis/google-auth-library-python/issues/1099