Collector extension: an auth extension works over WebSocket too

Merged
ST
2mo ago
+189-25

Requested by Bill · project thread

Before: a config with server.ws.auth failed validation with "an auth extension is supported over http only, not ws". Upstream's extension accepts it.

After: an auth extension works over ws. The client asks it for its headers about every second, and each upgrade carries the latest ones. An open connection keeps the headers it opened with. An auth extension still can't be combined with accepts_opamp_connection_settings, because it would replace the headers the server issued.

How: go/opamp already has the hook that was thought missing, Config.AuthHeader. Over WebSocket, the extension builds the auth extension's round tripper once, so a token it renews is kept between calls. That round tripper wraps a transport that sends nothing and keeps the request's headers. AuthHeader runs a request to the endpoint, as http:// or https://, through it and returns those headers. If the auth extension fails, the client gets no headers, so the server turns the connection away instead of the client using stale ones. Plain HTTP is unchanged.

Tests:

  • TestAuthExtensionOverWebSocket: the first upgrade carries the auth extension's token in place of the configured header. An upgrade after the token is renewed carries the new token. Without the AuthHeader line, the test fails with Bearer configured.
  • The validation table now accepts ws with auth, and still refuses auth with connection settings over ws.
  • go test -race ./... passes in go/opampextension, and the Supervisor still builds.

https://claude.ai/code/session_01USrqXHB3e1U7YEBgsrJTw8


Generated by Claude Code