Skip to content

feat: prefer X-Coder-Owner-Id header when present#244

Draft
dannykopping wants to merge 3 commits intomainfrom
dk/coder-agents-initiator-override
Draft

feat: prefer X-Coder-Owner-Id header when present#244
dannykopping wants to merge 3 commits intomainfrom
dk/coder-agents-initiator-override

Conversation

@dannykopping
Copy link
Copy Markdown
Collaborator

@dannykopping dannykopping commented Mar 31, 2026

Disclaimer: implemented using Claude Opus 4.6, reviewed by me.

When AI Bridge is used in conjunction with Coder Agents, it passes along a header (X-Coder-Owner-Id) which specifies the user which initiated the interaction with Coder Agents (and transitively with AI Bridge).

We should prefer this ID over the initiator passed through in the auth credential because Coder Agents can currently only provide a single token for all users when using an OpenAI-compatible provider. If a service account credential is used, we don't want the service account to show up as the initiator but rather the actual end-user.

This header was introduced in coder/coder#23578.

Manually tested and it works as expected.

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines +178 to +179
if client == ClientCoderAgents {
if ownerID := r.Header.Get("X-Coder-Owner-Id"); ownerID != "" {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We have to consider that it's possible that someone malicious could spoof the User-Agent and the X-Coder-Owner-Id header here. We're validating that it's at least a valid UUIDv4 value to prevent XSS, so the best they could do is make their interceptions masquerade as someone else's, but we still log this change.

@dannykopping dannykopping changed the base branch from dk/agents-session-id to graphite-base/244 March 31, 2026 15:49
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping force-pushed the dk/coder-agents-initiator-override branch from 29f644a to aa36659 Compare March 31, 2026 15:51
@graphite-app graphite-app bot changed the base branch from graphite-base/244 to main March 31, 2026 15:51
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping force-pushed the dk/coder-agents-initiator-override branch from aa36659 to 3f328ea Compare March 31, 2026 15:51
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.

1 participant