Skip to content

chore(provisioner/terraform): preserve existing AWS_SDK_UA_APP_ID#24606

Merged
matifali merged 3 commits into
mainfrom
blink/fix-aws-sdk-ua-app-id-override
May 30, 2026
Merged

chore(provisioner/terraform): preserve existing AWS_SDK_UA_APP_ID#24606
matifali merged 3 commits into
mainfrom
blink/fix-aws-sdk-ua-app-id-override

Conversation

@blinkagent

@blinkagent blinkagent Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Problem

The Terraform provisioner hard-codes Coder's AWS Partner Revenue Measurement User-Agent string and appends it unconditionally to the subprocess environment:

"AWS_SDK_UA_APP_ID=APN_1.1/pc_cdfmjwn8i6u8l9fwz8h82e4w3$",

Because the safe environment inherits the operator's OS env (only CODER_ variables are stripped), any pre-existing AWS_SDK_UA_APP_ID is silently overridden when the AWS SDK reads the last occurrence of the duplicated key in the child process. Operators who are themselves AWS Partners (e.g. MSPs, platform teams with their own APN listing) lose attribution on every terraform apply, and there is no log signal.

Fix

Check the inherited environment for an existing AWS_SDK_UA_APP_ID value. If present, append Coder's User-Agent with a space delimiter so both attributions are preserved; otherwise use Coder's alone.

This follows AWS's documented guidance for co-existing Application IDs: https://docs.aws.amazon.com/PRM/latest/aws-prm-onboarding-guide/automated-user-agent.html

If an Application ID is already configured, you can append your Partner Revenue Measurement User Agent string using a space as a delimiter. For example: EXISTING_APP_ID APN_1.1/pc_5ugbbrmu7ud3u5hsipfzug61p$

A link to this AWS doc is also included in a code comment next to the product-code constant.

Changes

  • provisioner/terraform/safeenv.go: add safeEnvironValue helper, extract the product code into a named constant, and add awsSDKUserAgentEnv which returns the correct AWS_SDK_UA_APP_ID= line based on whether an existing value is present.
  • provisioner/terraform/provision.go: use the new helper in place of the hard-coded line.
  • provisioner/terraform/safeenv_test.go: unit tests for both helpers and both branches (no existing value + append-with-space).

Existing behavior is preserved when the operator has not set AWS_SDK_UA_APP_ID, so the TestProvision_SafeEnv assertion continues to hold unchanged.

Created on behalf of @matifali

The Terraform provisioner hard-coded Coders AWS Partner Revenue
Measurement User-Agent string and appended it unconditionally, which
silently overrode any AWS_SDK_UA_APP_ID already present in the
provisioner process environment. Operators who are themselves AWS
Partners (and who set their own Application ID for their own revenue
attribution) would lose attribution on every terraform apply.

This change checks the inherited environment and, if an Application ID
is already configured, appends Coders with a space delimiter so both
attributions are preserved, as documented by AWS:
https://docs.aws.amazon.com/PRM/latest/aws-prm-onboarding-guide/automated-user-agent.html
@github-actions github-actions Bot added the community Pull Requests and issues created by the community. label Apr 22, 2026
@blinkagent blinkagent Bot removed the community Pull Requests and issues created by the community. label Apr 22, 2026
@github-actions github-actions Bot added the stale This issue is like stale bread. label May 6, 2026
@github-actions github-actions Bot closed this May 10, 2026
@matifali matifali removed the stale This issue is like stale bread. label May 10, 2026
@matifali matifali reopened this May 10, 2026
@matifali matifali changed the title fix(provisioner/terraform): preserve existing AWS_SDK_UA_APP_ID chore(provisioner/terraform): preserve existing AWS_SDK_UA_APP_ID May 10, 2026
@matifali

Copy link
Copy Markdown
Member

@DevelopmentCats can you review this? Thanks

@DevelopmentCats DevelopmentCats left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Im going to verify this through cloudtrail and my instance and we should be good.

@github-actions github-actions Bot added the stale This issue is like stale bread. label May 21, 2026
@github-actions github-actions Bot closed this May 28, 2026
@matifali matifali removed the stale This issue is like stale bread. label May 28, 2026
@matifali matifali reopened this May 28, 2026
@matifali

Copy link
Copy Markdown
Member

@DevelopmentCats Can you help verify this?

DevelopmentCats added a commit that referenced this pull request May 28, 2026
…#25221)

Adds middleware in `withAWSBedrockOptions` that appends the AWS Partner
Revenue Measurement (PRM) attribution string to the User-Agent header on
every Bedrock API call made through AI Bridge.

This is the AI Bridge counterpart to the Terraform provisioner change
merged in #23138. Together, they ensure all AWS API calls made by Coder
(both workspace infrastructure via Terraform and LLM inference via
Bedrock) include PRM attribution.

## How it works

- A middleware is added before `bedrock.WithConfig(awsCfg)` that reads
the existing `User-Agent` header and appends
`sdk-ua-app-id/APN_1.1%2Fpc_cdfmjwn8i6u8l9fwz8h82e4w3%24`
- Only affects Bedrock calls; OpenAI and direct Anthropic API calls are
unaffected
- Uses `option.WithMiddleware` rather than `option.WithHeader` because
the existing User-Agent (set by the Anthropic SDK) must be preserved and
appended to, not replaced

## Tests

- **Positive**: `TestAWSBedrockIntegration` verifies PRM attribution is
present in the User-Agent on Bedrock requests
- **Negative**: `TestAnthropicMessages` verifies PRM attribution is
absent on non-Bedrock requests

## References

- Companion Terraform provisioner PR: #23138 (merged)
- Backport: #24052 (merged)
- Preserve existing `AWS_SDK_UA_APP_ID`: #24606 (open)
- Original `coder/aibridge` PR:
coder/aibridge#224 (superseded by this PR since
aibridge was moved into coder/coder via #24190)
- [AWS SDK Application ID
docs](https://docs.aws.amazon.com/sdkref/latest/guide/feature-appid.html)
- [AWS PRM Automated User
Agent](https://prm.partner.aws.dev/automated-user-agent.html) (partner
login required)

> Generated with [Coder Agents](https://coder.com/agents)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@DevelopmentCats

Copy link
Copy Markdown
Contributor

@DevelopmentCats Can you help verify this?

Sorry about the delay. I was able to test with this and it still comes through in cloud trail, and it gets passed the same way safely.

@matifali matifali merged commit 9d28489 into main May 30, 2026
61 checks passed
@matifali matifali deleted the blink/fix-aws-sdk-ua-app-id-override branch May 30, 2026 08:05
@github-actions github-actions Bot locked and limited conversation to collaborators May 30, 2026
@DevelopmentCats

DevelopmentCats commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Applied the backport label per (also tracking backports to ESR 2.29 manually since the auto-workflow only covers the latest three release branches).

@DevelopmentCats

Copy link
Copy Markdown
Contributor

All five backport PRs are open:

Target PR Mechanism
release/2.34 #26468 auto (backport label workflow)
release/2.33 #26470 auto (backport label workflow)
release/2.32 #26471 auto (backport label workflow)
release/2.29 #26474 manual, stacked on #26473

For #23138 to 2.29, see #26473. #23138 is already present on 2.32/2.33/2.34.

Done by Coder Agents on behalf of @DevelopmentCats.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants