Accept token-exchange JWTs for AutoFlow on the agent listener

GitLab calls AutoFlow on a user's behalf with a token-exchange JWT for the audience gitlab-autoflow. The API listener accepts only the shared-secret JWT, so the agent listener now serves the AutoFlow service too, behind a wrapper that verifies the token-exchange JWT before delegating to the same implementation. The agent listener applies the agent-token RPC API and the connection limiter only to listed agent methods (!4687 (merged)); AutoFlow's are not listed, so the wrapper reads the bearer itself.

There is no configuration. The key set comes from gitlab.address + /-/cloud_connector/keys (the Cloud Connector set Rails signs with, not Doorkeeper's), and the expected issuer is gitlab.external_url, falling back to gitlab.address, which is what Rails puts in iss. Set external_url whenever address is not the URL GitLab publishes as its own. The mechanism is temporary until STS, and both URLs are GitLab's, not the operator's to choose.

The fetch starts with the module, retries 5 s after each failed attempt (30 s timeout), and does not gate readiness: CE serves no key set and an AutoFlow deployment is ready without Rails. Until the first fetch succeeds the agent listener answers UNAVAILABLE to token-exchange callers. The set is fetched once, so after a key rotation the pod answers UNAUTHENTICATED until it restarts (gitlab-org/gitlab#616174 (closed)). Verifications are counted in token_exchange_verifications_total by outcome.

Known gap: on the agent listener the request passes the validating interceptor before the wrapper checks the bearer, so an unauthenticated caller with a malformed request gets INVALID_ARGUMENT rather than UNAUTHENTICATED. The API listener authenticates first. Aligning them means an auth interceptor keyed on the method list in the agent server's chain; nothing sensitive leaks, so it is not done here.

The integration suite sweeps every method in the proto registry on the agent listener without a token (#1225): everything must answer UNAUTHENTICATED except health and the four AutoFlow methods, which may be served and today answer INVALID_ARGUMENT because of the gap above.

Follow-up (#1228 (closed)): the key fetch uses the default HTTP client and ignores gitlab.ca_certificate_file, and the retry is a flat 5 s. iam!909 adds the client option and a backoff on the userauth side; Relay wires the client and re-pins once it merges.

Related to #1200 (closed)

Edited by Romuald Atchadé

Merge request reports

Loading
Loading