feat(auth): add web identity token credential fallback for AWS WIF#4231
Draft
wynbennett wants to merge 1 commit into
Draft
feat(auth): add web identity token credential fallback for AWS WIF#4231wynbennett wants to merge 1 commit into
wynbennett wants to merge 1 commit into
Conversation
The provider's AWS credential reader only checked static env vars (AWS_ACCESS_KEY_ID / SECRET / SESSION_TOKEN). Environments like TFE dynamic provider credentials and IRSA inject credentials via AWS_WEB_IDENTITY_TOKEN_FILE + AWS_ROLE_ARN, which was silently ignored — causing "missing AWS credentials" before any network call was made. Add a fallback in GetCredentials that, when AWS_SESSION_TOKEN is absent, reads the token file and exchanges it for STS credentials via a direct AssumeRoleWithWebIdentity call. Uses only stdlib (net/http, encoding/xml) — no AWS SDK dependency added. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
GetCredentialsonly checked three static env vars (AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN). Environments that use web identity federation — Terraform Enterprise dynamic provider credentials, EKS IRSA, or any OIDC-based workload identity setup — inject credentials viaAWS_WEB_IDENTITY_TOKEN_FILE+AWS_ROLE_ARNinstead. These were silently ignored, resulting in a"missing AWS credentials"error before any network call was made.GetCredentials: whenAWS_SESSION_TOKENis absent, check forAWS_WEB_IDENTITY_TOKEN_FILE+AWS_ROLE_ARNand exchange the token for STS credentials viaAssumeRoleWithWebIdentity. The existing static env var path andContextAWSVariablesoverride are both unchanged.net/http,encoding/xml,os).Changes
api/datadog/aws.gostsEndpointOverridefield toAWSAuth(unexported, for test injection only)assumeRoleWithWebIdentitywhich reads the token file and calls STS directlyGetCredentialsto fall through to web identity when session token env var is absentAWS_WEB_IDENTITY_TOKEN_FILE,AWS_ROLE_ARN,AWS_ROLE_SESSION_NAMEapi/datadog/aws_test.go(new)TestGetCredentials_EnvVars— static env var path still worksTestGetCredentials_WebIdentity— web identity exchange against a mock STS serverTestGetCredentials_WebIdentityMissingEnvVars— graceful fallback when no credentials at allTestGetCredentials_ContextOverridesWebIdentity— explicit context takes precedence over env varsTest plan
go test ./api/datadog/ -run TestGetCredentialspasses (all 4 cases)ContextAWSVariablesand static env vars continue to work as before🤖 Generated with Claude Code