Route /jwt/auth by container registry scopes

What does this MR do and why?

Stacked on !1410 (merged) (the Authorization: Basic rules this MR falls back to), which is itself stacked on !1412 (merged). Merge bottom up; each then retargets to main.

Implements the scope half of the routing algorithm for /jwt/auth and the un-routable response from the Container Registry Routing Service design document, for GET /jwt/auth?service=container_registry.

Every container registry token request reaches the Legacy Cell today. This MR routes one by its scope parameters: write scopes decide when the request has any, otherwise the pull scopes do. They are deduplicated to distinct top-level namespaces, capped (GITLAB_JWT_AUTH_MAX_DISTINCT_ROUTES, default 10, checked before any RPC) and resolved concurrently, one single-claim Classify each, with the same [{route}, {redirectRoute}] expansion the path-based handlers use. One cell means proxy to it. Two or more different cells, or over the cap, means 400 UNSUPPORTED, answered here without contacting a cell.

Everything else falls back to the JSON rule engine: no repository scope (docker login), a deciding scope that belongs to no cell, and any Classify failure or timeout. A failure is never read as "no cell": were the failing route one of two deciding write scopes, that would route a mixed-cell token confidently to the surviving cell.

The Basic credential is the rule engine's job, not this handler's. The design document's Basic-credential branch is served by !1410 (merged), which adds Authorization: Basic routable-token rules to the session_token ruleset, so docker login -u gitlab-ci-token -p $CI_JOB_TOKEN routes by the token's cell through this MR's fallback. Every fallback reaches it, including a deciding scope that belongs to no cell, an edge into the Basic branch that the design document's flowchart does not draw. This replaces the handler-side credential path in !1381 (closed), which is superseded by this MR plus !1410 (merged).

src/jwt_auth/decision.ts owns the algorithm as one pure injectable function returning the decision and its telemetry as separate values. src/handlers/jwt_auth_handler.ts owns only the HTTP. service=dependency_proxy and any other service are untouched.

Rollout. Gated on GITLAB_JWT_AUTH_ROUTING_ENABLED, a Flagship boolean of its own that defaults to off and is read per request. Merging changes nothing until the flag is turned on, and dark launch, rollout and rollback need no deploy. Order: merge and deploy, create the flag, enable in gstg, roll out in gprd, as written up in docs/path-based-routing.md. The decision log line carries outcome, decidingScopeKind, scopeCount and distinctRouteCount. When the engine decides, its own ruleApplied line names the rule.

Each commit is green on its own. The scope commits of !1381 (closed) are cherry-picked unchanged, and a later commit updates comments that promised a handler-side credential branch. npm test passes; tsc --noEmit, eslint . and prettier --check clean.

References

How to set up and validate locally

npm test covers every outcome without a running stack. On a GDK:

# <gdk>/gdk.yml
gitlab_http_router:
  path_based_routing_mode: full
# <gdk>/gitlab-http-router/.dev.vars  (gitignored)
GITLAB_JWT_AUTH_ROUTING_ENABLED=true
LOGGING_LEVEL=debug
gdk reconfigure && gdk restart gitlab-http-router && gdk tail gitlab-http-router

GDK passes the mode as a CLI --var, which beats .dev.vars, so it has to come from gdk.yml. Without either flag, /jwt/auth falls through to the ruleset unchanged.

No scope, so the rule engine answers.

curl 'http://127.0.0.1:3000/jwt/auth?service=container_registry&offline_token=true'
{ msg: '/jwt/auth routing decision', decidingScopeKind: 'none', scopeCount: 0, distinctRouteCount: 0, outcome: 'rule_engine_fallback' }

Write scopes decide, pull scopes are context.

curl 'http://127.0.0.1:3000/jwt/auth?service=container_registry&scope=repository:aaa/p/i:pull&scope=repository:bbb/p/i:push'
{ msg: '/jwt/auth routing decision', decidingScopeKind: 'write', scopeCount: 2, distinctRouteCount: 1, outcome: 'rule_engine_fallback' }

Over the cap: a real 400, answered without contacting a cell.

curl -i 'http://127.0.0.1:3000/jwt/auth?service=container_registry&scope=repository:ns1/p/i:pull&scope=repository:ns2/p/i:pull&scope=repository:ns3/p/i:pull&scope=repository:ns4/p/i:pull&scope=repository:ns5/p/i:pull&scope=repository:ns6/p/i:pull&scope=repository:ns7/p/i:pull&scope=repository:ns8/p/i:pull&scope=repository:ns9/p/i:pull&scope=repository:ns10/p/i:pull&scope=repository:ns11/p/i:pull'
HTTP/1.1 400 Bad Request
{"errors":[{"code":"UNSUPPORTED","message":"a single token cannot cover more than 10 top-level namespaces","detail":{"distinctRouteCount":11,"cap":10}}]}

Not a container registry request: untouched.

curl 'http://127.0.0.1:3000/jwt/auth?service=dependency_proxy&scope=repository:aaa/p/i:pull'

No /jwt/auth routing decision line is logged at all.

Proxying by scope, a redirectRoute match and unsupported_mixed_cell need claim data GDK does not have (empty claim store, one cell), and are covered by npm test.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sangwoo Han

Merge request reports

Loading
Loading