Skip to content

feat(api-keys): let a monitoring key read the stream timeseries - #3242

Merged
Quick104 merged 1 commit into
mainfrom
feat/monitor-scope-timeseries
Oct 29, 2026
Merged

Quick104 merged 1 commit into
mainfrom
feat/monitor-scope-timeseries

Conversation

@Quick104

@Quick104 Quick104 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none (#1190 C2 checked key scopes before admin:monitor:read existed)

A monitoring tool holding an admin:monitor:read key can read three of the dashboard stats routes but gets 403 from GET /api/v2/admin/stats/timeseries. That route is the history of concurrent streams and egress, which is what a monitoring tool charts. It was left out of #3182, which added the scope; that PR's description never discusses it. This change adds it to the scope.

Approach

timeseries joins playback-activity, top-activity and downloads in the monitor scope's allowlist pattern, and the scope table in docs/api-keys-api.md lists it.

The handler already passes refresh through the same check as the other three reads, so a scoped key that sends refresh=true gets the shared cached aggregate and cannot force the query on every poll. The response carries only stream counts, kbps, byte totals and timestamps, with no paths, addresses or error text.

/admin/stats stays outside the scope. It returns library totals and watch-provider counters, and its handler does not ignore refresh for scoped keys.

Validation

  • Allowlist table test: a new row admitting timeseries for a monitor key failed before the change and passes after; the existing row refusing /admin/stats still passes.
  • The OpenAPI guard that walks every response schema the monitor scope reaches passes with the timeseries schema included.
  • Focused Go tests for internal/api/middleware, internal/apiv2 and internal/auth: pass.
  • make lint-changed, gofmt, make verify-apiv2-openapi, make verify-apiv2-contract, make verify-local-paths: pass.
  • Not run against a live server.

Evidence

Evidence: none, no user-visible change

Risks

A monitor key can now read sampled stream counts and egress for up to 31 days. No route is removed and no response changes. The user manual does not list the routes this scope covers, so it needs no update.

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: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Allow admin:monitor:read API keys to access the stream timeseries stats endpoint

Adds the timeseries stats path to the GET routes in the apiKeyScopeRoutes scope-route table in api_key_scopes.go. A monitoring-scoped key can now read this endpoint with GET. Covered by a new case in TestAPIKeyScopesAllow and documented in api-keys-api.md.

Macroscope summarized 723e68f.

admin:monitor:read already admitted the playback-activity, top-activity
and downloads stats reads but not GET /api/v2/admin/stats/timeseries,
the concurrent-stream and egress history. The handler already ignores
refresh=true for scoped keys and returns only counts, rates, byte totals
and timestamps. /admin/stats stays outside the scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Oct 29, 2026
@silo-kody

silo-kody Bot commented Oct 29, 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 29, 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-29T13:57:04.003967Z 723e68f PR opened
🔒 Security Review ✅ Completed 2026-10-29T13:58:42.104833Z 723e68f PR opened
ℹ️ 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.

@macroscopeapp

macroscopeapp Bot commented Oct 29, 2026

Copy link
Copy Markdown

The new monitor-key access to /api/v2/admin/stats/timeseries lets monitoring clients retrieve sampled concurrent-stream and egress history, but the Evidence section says there is no user-visible change; add before-and-after API response excerpts for the same request (403 before, successful timeseries response after) and identify the API surface and capture build or commit.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The admin:monitor:read API key scope now permits GET /api/v2/admin/stats/timeseries. The API key documentation and scope allowlist test also include this route.

Changes: Monitor scope route access

Layer / File(s) Summary
Permit timeseries route
internal/api/middleware/api_key_scopes.go, internal/api/middleware/api_key_scopes_test.go, docs/api-keys-api.md
The monitor-read scope pattern now includes the timeseries route. The allowlist test checks access to it, and the API key documentation lists it.

Priority: Not assessed

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

Suggested labels: enhancement, api-v2, documentation, go, size/M

Suggested reviewers: rhainland

Merge Risk: Minimal · up to 723e6

The scoped access change is consistent across implementation, routing, tests, and documentation and is ready to merge.

Security architecture risk: Low · up to 723e6

Administrator-owned monitoring keys gain stream and bandwidth history, but not write access, cache-refresh authority, or broader administrator access. The expansion is narrow and retains existing authorization controls. Production polling and load behavior have not been validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A holder of an accepted monitoring key, acting through an authorized administrator owner, gains access to deployment-wide sampled stream and egress history rather than only that owner's activity. This is an intentional aggregate-data permission expansion; the inspected query does not provide filesystem, credential, or configuration access.

Trust Boundaries and Controls

  • observed — The bearer credential is validated and bound to its enabled owning user before scope evaluation and claim construction. Scope matching requires the exact GET method and anchored cleaned path. The typed operation then retains viewer-access and acting-admin checks, including an administrator-role requirement; granting this scope does not itself grant that role.

Resilience and Maintainability Implications

  • observed — Concurrent cache misses can issue duplicate database reads because lookup, query, and publication are not coalesced. That behavior predates this PR, but monitoring keys become additional callers. When configured and enabled, the existing authenticated limiter applies API-key, account, IP, and global budgets. Source evidence does not establish deployed limits or whether peak concurrent misses threaten database capacity.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P2 Limited scope, workaround exists, or polish labels Oct 29, 2026
@coderabbitai coderabbitai Bot added documentation Improvements or additions to documentation enhancement New feature or request size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Oct 29, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 29, 2026

Copy link
Copy Markdown

Major change: #1190 C2 (Server)

C2 is recorded as passed on build 807 · d4e35ba9 and checks allowed and forbidden API-key scope operations. This diff adds GET /api/v2/admin/stats/timeseries to the admin:monitor:read allowlist, changing that permission matrix. The PR description should explain this impact on previously validated behavior; C2 needs re-validation after merge.

Please replace the current line with:

Validation tasks: changes #1190 C2

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104
Quick104 merged commit 5a602b8 into main Oct 29, 2026
20 of 22 checks passed
@Quick104
Quick104 deleted the feat/monitor-scope-timeseries branch October 29, 2026 14:03
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 bug Something isn't working documentation Improvements or additions to documentation 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/M 50–199 added + deleted lines (all files); change volume, not priority. size/S 0–49 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant