Commit Graph
2 Commits
Author SHA1 Message Date
yetone 08cca73114 gateway keys: an issuer's re: pattern never covers a glob it can't hold
bf4d8f3e5 let a key's model be a re: pattern, and covered() tried that
pattern on an issued key's glob as text. A regex's '.' or a class like
[^-] takes the glob's '*' too, so an issuer holding "re:^openai/[^-]*$"
(openai/o3, not openai/gpt-4o) could issue "openai/*", and at the
gateway foldModels kept "openai/*": the issued key used openai/gpt-4o,
which its issuer may not. "re:^gr" covered "gr*", which names group/…
ids a pattern never does. The other way, a child's glob "r*" matched
the text "re:^openai/" and so took the issuer's whole pattern.

Now a pattern covers a glob only when it matches the glob's text before
the first '*' and asserts nothing about what follows ($, \z, \b, \B),
which makes it a match in every id the glob names, and when the glob
can't name a group. A pattern is covered only by itself or by "*". The
same check runs at issue time (IssueKey) and at each request
(foldModels). It is stricter than needed in one way: "re:gpt" no longer
covers "*gpt*" (only the text before the first '*' is judged).

Run on mote at this tree:
- TestPatternCoversAGlobOnlyForAll: red on origin/main ce5e5964d (7 of
  its checks, the openai/gpt-4o fold among them), green here.
- go test -tags nogui ./internal/access: ok.
- go test -tags nogui -run "Key|Issue|Pattern|Alias" ./internal/gateway
  ./internal/gui . : ok.
- GOOS=linux and GOOS=windows go vet ./internal/access, gofmt -l: clean.
Not run: the full suite, and the GUI (no GUI change).
2026-11-11 06:40:08 +08:00
yetone bf4d8f3e5d gateway keys: a model may be a re: pattern, and a key may rename a model (tsingchao on X)
Access layer, CLI and gateway; GUI and docs follow. Tests: access pattern and alias tests; gateway TestGatewayKeyModelPatternHoldsEveryRoute and TestGatewayKeyAliasRenamesAModel, each red with the pattern match or aliasRequest switched off by hand.
2026-11-11 06:24:47 +08:00