Skip to content

feat(api-keys): add monitoring and session control scopes - #3182

Merged
Quick104 merged 3 commits into
mainfrom
feat/admin-monitor-scopes
Oct 28, 2026
Merged

Quick104 merged 3 commits into
mainfrom
feat/admin-monitor-scopes

Conversation

@Quick104

@Quick104 Quick104 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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:read exposes 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 a GET.
  • 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/capabilities isn'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:read row is a GET, with one allowed exception: the events socket ticket POST that 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/resources omits each disk's path. The field is already optional, and node /health already omits it.
  • GET /admin/downloads/preparations omits each job's error, because a failed attempt stores the raw preparer error, which can quote a source path.
  • GET /admin/stats/playback-activity, top-activity and downloads ignore refresh=true for scoped keys and answer from the shared cached aggregate, so a polling tool can't force the aggregate queries on every call. Administrators keep refresh.
  • Node rows can't drop url because it is a required field. So nodes get a new GET /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 opaque last_stats it returns a typed resources sample, 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/capabilities advertises summary: true when 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 raw error field 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 in apimw.IsScopedAPIKey, shared by the v1 admin-boundary refusals and the v2 projections.

Docs: docs/api-keys-api.md documents both scopes. Its admin-boundary refusals now say permission_denied, which is what v2 returns; v1 still returns insufficient_scope. docs/admin-api.md documents 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, so silo-apple and silo-android need no follow-up. jellycompat has no API-key scope concept or equivalent admin surface, so it needs no change either.

Validation

  • Ran against an isolated sandbox built from this branch, with a proxy and a transcode node. Every listed monitor route answers 200 to a monitor key. A matrix of excluded routes answers 403 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 gets 403, and a revoked key gets 401.
  • Live session: a control key terminated a real direct-play session (200, stream URL then 410), and the monitor key saw the session leave the live list and appear in history. With the monitor key, the same terminate returned 403. pause returned 409 because the scripted client had no realtime socket, after the scope admitted the call.
  • The scoped /admin/system/resources and /admin/nodes/summary responses from the sandbox carry no path, URL, build or download-directory values. An unscoped admin key still gets them.
  • New tests: the allowlist table rows and refusals, the GET-only guard, and an apiv2 test that a scoped key gets no paths, preparation error text or node addresses, overrides, build or download-directory values; a non-admin owner is refused; and an unscoped key keeps the full documents. The projection test fails against a build without the redaction, and it also checks that a monitor key's refresh=true never reaches the stats service. The schema guard fails if /admin/nodes is 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-contract and the other verify targets pass. pnpm run lint, format:check, build and budget:check pass.
  • make test-web: 6767 of 6768 tests pass. The one failure is the pgs.test.ts 16 MiB epoch test, which hit its 5 s timeout under load and fails the same way on main.
  • make test-go against a fresh database: everything passes except TestLoginSessionActivityAndAdminRevocationDB (internal/auth) and TestPopulationSyncResumesAfterQuotaAcrossRuns (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

  • A monitor key reads the per-account and live-session data an admin sees, including client IPs, user agents, account emails and download history. That is the point of the scope, but an operator should treat the key as admin-sensitive.
  • Newer node builds that add fields to their health sample won't show those fields in /admin/nodes/summary until this projection lists them.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: T3 Code running Claude Code
  • Tool(s): Claude Code; Codex (plan review); Claude Code review subagent
  • Model(s): claude-opus-5-5 (implementation and code review); gpt-6.1-sol (plan review)
  • Involvement: Fully AI-generated from a maintainer-approved plan; awaiting human review
  • Adversarial review: gpt-6.1-sol reviewed the plan and narrowed the monitor scope. /admin/devices/{user_id}/{device_id} and /admin/node-sessions stay 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. The docs/admin-api.md wording follows a maintainer decision. A node sample whose fields fail to decode drops resources rather 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:read and admin:sessions:control API key scopes

  • Adds two new scoped API key scopes: admin:monitor:read for read-only admin monitoring routes and admin:sessions:control for session pause/resume/stop/message/terminate commands, enforced via route allowlists in api_key_scopes.go
  • Adds GET /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.go
  • Withholds deployment details from scoped-key responses: disk mount paths are redacted in system resources, download preparation error text is omitted, and dashboard cache-refresh requests are ignored
  • Replaces the local actorIsScopedAPIKey helper in admin.go with the shared middleware predicate IsScopedAPIKey, and documents the new scopes and omissions in admin-api.md and api-keys-api.md
  • Behavioral Change: scoped keys now get 403 permission_denied for out-of-scope admin routes, and the monitoring-scope response schemas are covered by a new test that checks no deployment-detail fields leak

Macroscope summarized 4fa0215.

Quick104 and others added 2 commits October 27, 2026 19:04
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]>
@silo-triage silo-triage Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa80fb05-79f0-4fac-9f28-2cc5a78ea841
Commits

Reviewing files that changed from the base of the PR and between 62b1a6e and 4fa0215.

Files selected for processing: 22
  • contracts/api/v2/fixtures/admin_api_key_capabilities.json
  • contracts/api/v2/openapi.json
  • docs/admin-api.md
  • docs/api-keys-api.md
  • internal/api/handlers/admin.go
  • internal/api/handlers/admin_users_service.go
  • internal/api/handlers/external_sign_in.go
  • internal/api/handlers/password_resets.go
  • internal/api/middleware/api_key_scopes.go
  • internal/api/middleware/api_key_scopes_test.go
  • internal/api/middleware/auth.go
  • internal/api/testdata/media_routes.txt
  • internal/apiv2/admin_dashboard_insights.go
  • internal/apiv2/admin_discovery_scopes_test.go
  • internal/apiv2/admin_download_preparations.go
  • internal/apiv2/admin_node_drain.go
  • internal/apiv2/admin_nodes_read.go
  • internal/apiv2/admin_system.go
  • internal/apiv2/context.go
  • internal/auth/api_key_scopes.go
  • web/src/api/v2/operations.ts
  • web/src/api/v2/schema.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@silo-kody

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:46:38.555829Z 4fa0215 New commits
🔒 Security Review ✅ Completed 2026-10-27T19:49:08.247077Z 4fa0215 New commits

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P2 Limited scope, workaround exists, or polish labels Oct 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ 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)$`)},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

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 Validation tasks: changes #1190 C2 line matches this impact.

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

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 01875a8 into main Oct 28, 2026
28 checks passed
@Quick104
Quick104 deleted the feat/admin-monitor-scopes branch October 28, 2026 13:07
Quick104 added a commit that referenced this pull request Oct 28, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant