Repository navigation
feat: configure AI Gateway actor identity headers - #29929
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
62200b4 to
c012c90
Compare
Documentation CheckUpdates Needed
Automated review via Coder Agents |
c012c90 to
52abf02
Compare
ssncferreira
left a comment
There was a problem hiding this comment.
Overall LGTM, but I have some comments/suggestions
| for k, v := range actor.Metadata { | ||
| headers[ActorMetadataHeader(k)] = fmt.Sprintf("%v", v) | ||
| headers := make(map[string]string, len(names)) | ||
| if name := names["id"]; name != "" { |
There was a problem hiding this comment.
nit: should we have constant values for these keys id, username?
There was a problem hiding this comment.
In fact, each attribute needs to be hardcoded here 🤔 so every new field grows this function. Maybe we could loop over the configured names instead and look up each value (ID from actor.ID, the rest from actor.Metadata)?
There was a problem hiding this comment.
We need to be careful about casing (username vs Username). Let's stick to known attributes only.
| Group: &deploymentGroupAIGateway, | ||
| YAML: "api_dump_dir", | ||
| } | ||
| aiGatewayActorHeaderID := serpent.Option{ |
There was a problem hiding this comment.
Is it also a requirement to have different header names? This could get tricky with reserved header names 😕 This means that for every new actor header that we introduce we will need to add a new configuration value 😕
If it is really needed, maybe a map sort of option would be better?
There was a problem hiding this comment.
I initially decided to use a map[string]string but the upfront complexity did not seem worth it.
EDIT: To clarify, the map decoding behaviour of github.com/coder/serpent merges an entry that's omitted with the default. My original idea was to add special handling of - to mean "do not send", but that's more complex than just having separate config values.
| headers[name] = actor.ID | ||
| } | ||
| name := names["username"] | ||
| if name == "" { |
There was a problem hiding this comment.
if only "id" and "username" keys are checked maybe names param should be a struct not a map?
If I understand correctly names map just defines header name value for forwarding actor.ID and actor.Metadata["Username"] so struct with 2 strings should work. It would make code simpler to understand.
There was a problem hiding this comment.
nit: looks like this could be const
There was a problem hiding this comment.
Will refactor in a follow-up.
| continue | ||
| } | ||
| switch canonical { | ||
| case "Authorization", "X-Api-Key", "Proxy-Authorization", "Proxy-Authenticate", |
There was a problem hiding this comment.
This could be defined somewhere, eg, appending all elements from lists from aibridge/headers/headers.go
Would be hard to keep in sync otherwise.
There was a problem hiding this comment.
Worth a follow-up (EDIT: AIGOV-689)
| "(CODER_AI_GATEWAY_KEY_FILE). A user login or session token is " + | ||
| "not required.", | ||
| Handler: func(inv *serpent.Invocation) error { | ||
| if err := vals.AI.BridgeConfig.ValidateActorHeaderNames(); err != nil { |
Configure AI Gateway actor ID and username headers independently through
--ai-gateway-actor-header-idand--ai-gateway-actor-header-meta-username, with matching environment variables and YAML settings. Each defaults to its standard header name; an empty string disables that attribute. The existingsend_actor_headersgate remains off by default.Validate header names, case-insensitive collisions, and protected destinations for embedded and standalone gateways. Strip standard and configured identity destinations before injecting authenticated values. Includes configuration precedence tests, captured upstream request coverage, and generated help/API documentation.
First PR in the replacement stack, targeting
main. #29930 follows this PR and adds email as an explicit opt-in. This PR does not add email support. Replaces the configurability work from #29812 after reversing the stack. #30037 adds a standalone behavioural change to strip actor headers supplied by the client.Refs https://linear.app/codercom/issue/AIGOV-601
Implementation decisions and verification
-sentinel. Precedence is per attribute: flag, environment, YAML, default. Explicit empty values disable forwarding for that attribute.go test ./aibridge/..., standalone YAML configuration tests, upstream actor-header integration tests, and fullmake pre-commitgeneration, formatting, lint, and build checks.Generated with Coder Agents on behalf of @johnstcn.