Repository navigation
refactor(auth): extract model access policy from key storage - #17959
diegosouzapw merged 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb55792432
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thanks @MumuTW, this is a very clean extraction and an unusually well-documented one. Pulling the allow/block/publication/group decision out of key storage into a domain function with lazy lookup ports makes the most security-sensitive code path in the key layer much easier to reason about. What we checked: we ran a differential fuzz of the original inline logic against evaluateModelAccess over 60k random policies (allow/block patterns including cc/, claude/, provider/*, wildcards, restricted plus an empty list, disableNonPublicModels, group ids, resolved targets and random lookup results). It gave identical decisions, identical lookup call order and the same cache/no-cache boundary every time, and the moved matchers are byte-identical to the originals. All the focused suites you listed pass on our side, and typecheck:core is clean. The commit metadata is also clean, so the automated "Codex author" comment looks stale for this head. One small suggestion, not a blocker: the "early block/publication denials stay uncached" invariant in your summary is not pinned by any test. When we flipped the wrapper to cache those denials, all the relevant tests still passed. A short wrapper-level test (deny by blockedModels, then by an unpublished model, and assert nothing is written to the permission cache) would lock it in. If you would rather not, we can add it ourselves in-place. The base branch is currently red from the inherited #17219 failures, so CI noise on unit shards or the README docs-sync check is not from this PR. |
d34081d
into
cheaper-inference:release/v3.8.53
Resolve against the release tip: src/lib/db/apiKeys/modelPermissions.ts keeps the release's re-export from @/domain/modelPermissions (cheaper-inference#17959), so the PR's browser copies src/shared/utils/modelPermissionPatterns.ts and modelPermissionCandidates.ts are removed and keyAccessAssignUtils.ts now imports the one domain matcher (client and server share the cheaper-inference#15415 nested-provider rule). Union the catalog page, bulk action bar and model/combo tables so the release's hide/show visibility controls (cheaper-inference#16749) and UI-kit cells sit next to this PR's key-assignment button, dialog and row access action. Tests now assert the server facade and the client share the domain helpers, and that a provider wildcard does not reach a nested provider in the client matcher. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Summary
Model authorization currently lives inside API-key persistence, mixing the allow/block, publication, and group decision flow with metadata loading and caching. Extract that decision flow into
src/domain/modelAccessPolicy.ts, with pure matching helpers insrc/domain/modelPermissions.ts.The existing
isModelAllowedForKey(): Promise<boolean>facade supplies lazy lookup ports and keeps metadata, runtime settings, and permission caching in the DB layer. Existing helper imports continue to work through compatibility exports.Preserved behavior
Validation
strictNullChecks: true: passed.npm run lint: passed.npm run check:migration-numbering: passed.npm run check:db-rules: passed.CHANGELOG_BASE_REF=upstream/release/v3.8.53 npm run check:changelog-integrity: passed.Focused test command:
Tests added and coverage
tests/unit/model-access-policy.test.ts: 16 cases covering decision precedence, lazy short-circuits, publication rules, group narrowing, and domain import/evaluation without SQLite initialization.tests/unit/model-access-policy-wrapper.test.ts: 6 DB-backed characterization cases covering requested/resolved identities, group restrictions, and resolved-target cache isolation.Reviewer notes
release/v3.8.53atdaca9902e859bc1aa95ba276e3ef200ba7f5d142.