Skip to content

s3: Read AWS_EC2_METADATA_SERVICE_ENDPOINT for IAM credential resolution#6951

Open
jaisonerick wants to merge 1 commit intografana:mainfrom
jaisonerick:fix/iam-endpoint-env-var-upstream
Open

s3: Read AWS_EC2_METADATA_SERVICE_ENDPOINT for IAM credential resolution#6951
jaisonerick wants to merge 1 commit intografana:mainfrom
jaisonerick:fix/iam-endpoint-env-var-upstream

Conversation

@jaisonerick
Copy link
Copy Markdown

Summary

The S3 backend's IAM credential provider hardcodes TEST_IAM_ENDPOINT as the only way to override minio-go's default IMDS endpoint (169.254.169.254). This makes it impossible to use custom IMDS-compatible credential providers — such as AWS IAM Roles Anywhere credential helper in serve mode — without setting a test-only environment variable.

This adds AWS_EC2_METADATA_SERVICE_ENDPOINT as a standard fallback, matching the env var used by the AWS SDK for Go. Priority:

  1. TEST_IAM_ENDPOINT (backward compat, no behavior change for existing users)
  2. AWS_EC2_METADATA_SERVICE_ENDPOINT (standard AWS SDK env var)
  3. minio-go default (169.254.169.254)

Motivation

When running Tempo outside of EC2/ECS (e.g., on a Raspberry Pi with IAM Roles Anywhere), the credential helper provides an IMDS-compatible endpoint on a custom address (127.0.0.1:9911). The AWS SDK reads AWS_EC2_METADATA_SERVICE_ENDPOINT to find this endpoint, but Tempo's minio-go credential chain ignores it — causing a 90-second timeout against 169.254.169.254 followed by Access Denied on every S3 operation.

Test plan

  • Verified on Raspberry Pi 4 with IAM Roles Anywhere credential helper
  • TEST_IAM_ENDPOINT behavior is unchanged (checked first)
  • When neither env var is set, minio-go default behavior is preserved

The S3 backend's IAM credential provider only reads TEST_IAM_ENDPOINT
to override minio-go's default IMDS endpoint (169.254.169.254). This
makes it impossible to use custom IMDS-compatible credential providers
(e.g. AWS IAM Roles Anywhere credential helper) without setting a
test-only env var.

This adds AWS_EC2_METADATA_SERVICE_ENDPOINT as a fallback, matching
the standard env var used by the AWS SDK. Priority:

1. TEST_IAM_ENDPOINT (backward compat)
2. AWS_EC2_METADATA_SERVICE_ENDPOINT (standard)
3. minio-go default (169.254.169.254)
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 13, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db2faa8344

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tempodb/backend/s3/s3.go
Transport: http.DefaultTransport,
},
Endpoint: os.Getenv("TEST_IAM_ENDPOINT"),
Endpoint: iamEndpoint(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Limit endpoint override to IMDS-only credential retrieval

Passing iamEndpoint() into credentials.IAM.Endpoint here affects more than IMDS in minio-go: IAM.RetrieveWithCredContext reuses Endpoint for the AWS_WEB_IDENTITY_TOKEN_FILE branch as the STS endpoint (see vendor/github.com/minio/minio-go/v7/pkg/credentials/iam_aws.go, case identityFile != ""). If AWS_EC2_METADATA_SERVICE_ENDPOINT is set in an IRSA/web-identity environment, credential exchange is sent to the IMDS URL instead of STS and auth fails. This regression is introduced by setting the endpoint unconditionally for all IAM provider modes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch on the shared Endpoint field — but this is a pre-existing issue with TEST_IAM_ENDPOINT, not something introduced by this PR. The current code:

Endpoint: os.Getenv("TEST_IAM_ENDPOINT"),

has the exact same behavior: if TEST_IAM_ENDPOINT is set and AWS_WEB_IDENTITY_TOKEN_FILE is also set, the IMDS URL gets used as the STS endpoint. This PR just adds a standard env var as a fallback — it does not change how credentials.IAM.Endpoint is consumed.

The root issue is in minio-go: IAM.Endpoint is overloaded for both IMDS and STS paths. Fixing that belongs upstream in minio-go, not here.

In practice, AWS_EC2_METADATA_SERVICE_ENDPOINT is set in environments where IMDS is the credential source (custom IMDS proxies, IAM Roles Anywhere). It would not be set alongside AWS_WEB_IDENTITY_TOKEN_FILE in an IRSA environment.

@javiermolinar
Copy link
Copy Markdown
Contributor

Looks reasonable to me. @jaisonerick could you sign the license and add a line to the changelog?

@MukundaKatta

This comment was marked as spam.

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.

3 participants