Lift the routable-token decoders out of Rule and add a non-throwing decoder
What does this MR do and why?
decodeRoutableTokenPayload and decodeRoutableJson are private methods on Rule, reachable only by declaring a transform in a JSON ruleset. !1381 (closed) routes GET /jwt/auth, where a Docker client authenticates with Authorization: Basic and no declarative rule can express the algorithm that endpoint needs, so it gets a hand-written handler that has to read the cell id out of the very same token from outside the rule engine. Two code paths deriving a cell from one token must not disagree, so this MR gives them one decoder to share.
Commit 1 moves the two decoders, parseKeyValuePair and the base36 helpers off Rule into a new src/routable_token.ts, taking ROUTING_KEYS with them. decodeBase64Match stays behind: it re-matches against a pattern supplied by the rule, which makes it engine machinery rather than token grammar. Import rewiring only, and green with no test edits, which is the gate on it.
Commit 2 adds decodeRoutableToken: one call, both encodings, { cellId, encoding } or null.
- It never throws, unlike the two decoders it wraps. A caller reaching for it is routing on a best-effort hint, so an undecodable token is not an error, it is a request this code did not decide, and undecided requests already have a home. The two wrapped decoders keep throwing, which is correct inside the rule engine where a malformed token is the
400the client has earned. - Recognition is by shape, never by prefix, because prefixes are instance-configurable (
PrefixHelper.prepend_instance_prefixturnsglpat-intoacme-glpat-). Both encodings split into three dot-separated segments; the middle one discriminates them. - An unrecognised version returns
nullwith no branch for it, which is the same answer an explicit branch would give. c, noto, matching every routable-token rule in the ruleset. Reading a different key on one path is the same two-paths-disagreeing problem one level down.
No shipping path changes. config/ruleset/ and src/rules/ behaviour are untouched and byte-identical including what they throw on, pinned by the existing transform.json fixtures. The grammar is still written down twice, once here and once per rule; unifying it and adding the test that keeps it unified is !1383 (merged), stacked directly on top.
npm test 35 files / 419 tests → 36 / 445. tsc --noEmit, eslint . and prettier --check clean at both commits.
References
- Related issue: gitlab-com/gl-infra/tenant-scale/cells-infrastructure/team#881 (closed)
- Epic: gitlab-com/gl-infra/tenant-scale/cells-infrastructure#54
- !1383 (merged) is stacked on top of this MR; it unifies the grammar and adds the drift check
- !1381 (closed) is stacked above that: the
/jwt/authrouting feature, whose credential path isdecodeRoutableToken's first caller
How to set up and validate locally
npm testcovers all of it; nothing here needs a running stack.npx vitest run test/routable_token.spec.tsfor thedecodeRoutableTokenunit tests: both encodings, an instance-prefixed token, the three-segment discrimination, the payload bounds at 27 and 321, and fourteen credentials that must come backnull.git show <commit 1> --stat, which has no test file in it, the gate on commit 1 being a pure move.
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.