Repository navigation
feat(api-keys): add monitoring and session control scopes - #3182
Conversation
admin:monitor:read admits read-only monitoring routes (sessions, history, activity stats, accounts, devices, downloads, host and node health) and never returns paths, storage keys, configuration or settings. Scoped keys read nodes through a new path- and config-free GET /api/v2/admin/nodes/summary, and host resources and download preparations withhold disk paths and failure text from scoped keys. admin:sessions:control admits the administrator playback commands. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Walk every response schema admin:monitor:read reaches in the committed OpenAPI document and fail on path, address or raw-error fields that no handler withholds, and on allowlist rows that match no operation. Share the scoped-key check through apimw.IsScopedAPIKey, report the nodes summary capability only when node reads are wired, and state the scope's promise precisely (paths, node addresses, storage keys, setting values, credentials). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 6 minutes. View limit details
Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ 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 Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 434d6f264f
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| {http.MethodGet, regexp.MustCompile(`^/api/v2/admin/sessions/summary$`)}, | ||
| {http.MethodGet, regexp.MustCompile(`^/api/v2/events/capabilities$`)}, | ||
| {http.MethodGet, regexp.MustCompile(`^/api/v2/admin/playback-history$`)}, | ||
| {http.MethodGet, regexp.MustCompile(`^/api/v2/admin/stats/(playback-activity|top-activity|downloads)$`)}, |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Block monitor keys from forcing aggregate refreshes
An attacker controlling an admin-owned admin:monitor:read key can call these newly allowed paths with ?refresh=true. Each endpoint accepts that flag, invalidates its shared cache, and runs aggregate queries over playback history or downloads. Repeated requests therefore bypass caching indefinitely and can degrade Postgres and API availability. The acting-admin check only requires an admin key owner, and the default limiter still allows 20 requests/s. Reject or ignore refresh for monitor keys, or separate refresh authority from these reads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4fa0215. Scoped API keys now ignore refresh on the stats reads (playback-activity, top-activity, downloads, and timeseries, which shares the handler file) and answer from the shared cached aggregate, so a monitor key cannot force the aggregate queries. Administrators keep refresh. TestMonitorScopeWithholdsDeploymentDetails covers both, and docs/api-keys-api.md plus the parameter docs say so.
|
Major change: #1190 C2 (Server, build 807) needs re-validation after merge. This PR expands the allowed-route matrix with monitoring and session-control scopes, so the prior scope validation no longer covers the changed authorization surface. The PR must explain why this validated behavior is changing; its monitoring-tool rationale is present in the description. C2 needs re-validation after merge. The existing Suggested fix: No diff — retain that task reference and record a post-merge C2 result against an identified build. Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
The playback-activity, top-activity, downloads and timeseries reads accept refresh=true, which invalidates the shared cache and reruns the aggregate queries. A monitor key could poll with it to keep Postgres busy. Scoped keys now read the cached aggregate and refresh is ignored for them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Brings in the admin:monitor:read scope (#3182) and adds the catalog listing and its capability document to that scope's allowlist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Related issue: N/A
Validation tasks: changes #1190 C2
A monitoring tool such as Tracearr can only watch a Silo server with an unscoped admin API key today. That key can also change settings, read API keys and file paths, impersonate accounts and delete users. The existing scopes don't help:
admin:sessions:summary:readexposes only playback summaries, with no session detail, history, account, device, download or node reads, and no scope allows session control.This adds two scopes for that case:
admin:monitor:read: read-only monitoring. Live sessions and their capabilities, playback history, activity stats, accounts and their profiles, devices, IPs, downloads and watch summary, the device and IP lists, download entries and preparations, host resources, node health and server status. Every route is aGET.admin:sessions:control: the administrator playback commands (pause,resume,stop,message,terminate) and their command capabilities.Every admin operation they admit requires a key owned by an admin account. (
/events/capabilitiesisn't an admin operation and answers any owner.)Approach
The scopes are rows in the existing method-and-path allowlist. A test asserts that every
admin:monitor:readrow is aGET, with one allowed exception: the events socket ticketPOSTthat the follow-up for key-minted socket tickets adds.The monitor scope never returns filesystem paths, node addresses, storage keys, setting values or credentials. Routes that carry them stay out: item files, download storage, settings, logs, API keys, audit, per-device setting values and
/admin/node-sessions. Some monitored reads carry such details or expensive options. They withhold them from scoped keys and leave the existing admin behavior unchanged:GET /admin/system/resourcesomits each disk'spath. The field is already optional, and node/healthalready omits it.GET /admin/downloads/preparationsomits each job'serror, because a failed attempt stores the raw preparer error, which can quote a source path.GET /admin/stats/playback-activity,top-activityanddownloadsignorerefresh=truefor scoped keys and answer from the shared cached aggregate, so a polling tool can't force the aggregate queries on every call. Administrators keeprefresh.urlbecause it is a required field. So nodes get a newGET /api/v2/admin/nodes/summary(listAdminNodeSummaries), with the listing's paging and cursor rules. It keeps health, load, caps, group and drain state. Instead of the opaquelast_statsit returns a typedresourcessample, shaped like/admin/system/resources. It decodes only the sample fields and strips mount paths, so a node's build identity, download-directory measurement and any extra field it sends never reach the summary./admin/nodes/capabilitiesadvertisessummary: truewhen node reads are available. The two node listings share one paging helper.A second test walks every response schema the monitor scope reaches in the committed OpenAPI document. It fails on a
path, address or rawerrorfield that no handler withholds, and on an allowlist row that matches no operation. A field added later to a monitored operation must be withheld from scoped keys, or the operation leaves the scope. The scoped-key check now lives inapimw.IsScopedAPIKey, shared by the v1 admin-boundary refusals and the v2 projections.Docs:
docs/api-keys-api.mddocuments both scopes. Its admin-boundary refusals now saypermission_denied, which is what v2 returns; v1 still returnsinsufficient_scope.docs/admin-api.mddocuments the summary and the scoped-key omissions. It also corrects the opening sentence: admin operations fall under the 1.0 additive-only lock, and only player and viewer apps can skip them.Contract: additive under
/api/v2(two scope catalog entries, one operation, one capability member, doc text on two optional fields). OpenAPI, fixtures, web types and the media route manifest are regenerated. No migration. These surfaces are admin-only, sosilo-appleandsilo-androidneed no follow-up. jellycompat has no API-key scope concept or equivalent admin surface, so it needs no change either.Validation
200to a monitor key. A matrix of excluded routes answers403 permission_denied:/admin/nodes,/admin/node-sessions, settings, download storage, user settings and API keys,/admin/stats,PUT /admin/users/{id}, session commands. A monitor key owned by a non-admin account gets403, and a revoked key gets401.200, stream URL then410), and the monitor key saw the session leave the live list and appear in history. With the monitor key, the same terminate returned403.pausereturned409because the scripted client had no realtime socket, after the scope admitted the call./admin/system/resourcesand/admin/nodes/summaryresponses from the sandbox carry no path, URL, build or download-directory values. An unscoped admin key still gets them.refresh=truenever reaches the stats service. The schema guard fails if/admin/nodesis added to the scope, if a redaction exception is removed, or if a row has a typo.make lint-changed,make lint-router-recovery,go vet ./...,gofmt,make verify-apiv2-openapi,make verify-apiv2-contractand the other verify targets pass.pnpm run lint,format:check,buildandbudget:checkpass.make test-web: 6767 of 6768 tests pass. The one failure is thepgs.test.ts16 MiB epoch test, which hit its 5 s timeout under load and fails the same way on main.make test-goagainst a fresh database: everything passes exceptTestLoginSessionActivityAndAdminRevocationDB(internal/auth) andTestPopulationSyncResumesAfterQuotaAcrossRuns(internal/markers). Both pass when rerun on their own, and neither reaches the changed code.Validation task #1190 C2 (API keys, Server; key scopes against allowed and forbidden operations) passed on build 807. Existing scopes keep their routes, but the allowed-route matrix that case tests now has two more scopes, so C2 needs re-validation after merge.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3182/
No visible UI change. The web admin does not render the scope catalog.
Risks
/admin/nodes/summaryuntil this projection lists them.Checklist
AI Disclosure
/admin/devices/{user_id}/{device_id}and/admin/node-sessionsstay out, and host resources and nodes are served to scoped keys only through path-free views. A medium-level code review of the branch found six things to fix, all fixed here: a capability flag that ignored node-read wiring, the duplicated scoped-key check, no guard against future path fields, an overstated docs claim about non-admin owners, imprecise "configuration" wording, and a misleading test comment. It also raised three points not taken. Thedocs/admin-api.mdwording follows a maintainer decision. A node sample whose fields fail to decode dropsresourcesrather than passing unknown data through. Disks from node builds that predate role labels have no role on the full listing either.🤖 Generated with Claude Code
Note
Add
admin:monitor:readandadmin:sessions:controlAPI key scopesadmin:monitor:readfor read-only admin monitoring routes andadmin:sessions:controlfor session pause/resume/stop/message/terminate commands, enforced via route allowlists in api_key_scopes.goGET /api/v2/admin/nodes/summary, a paginated node summary endpoint with identity, health, load, and last resource sample but no addresses, paths, or config overrides; paging logic is shared with the full node listing in admin_nodes_read.goerrortext is omitted, and dashboard cache-refresh requests are ignoredactorIsScopedAPIKeyhelper in admin.go with the shared middleware predicateIsScopedAPIKey, and documents the new scopes and omissions in admin-api.md and api-keys-api.md403 permission_deniedfor out-of-scope admin routes, and the monitoring-scope response schemas are covered by a new test that checks no deployment-detail fields leakMacroscope summarized 4fa0215.