docs(#197): api-conventions §9 auth posture + decisions.md Bundle A entry
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 7s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m11s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 6m24s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 7s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m11s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 6m24s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -281,6 +281,11 @@ single-leading-cap names (`fFmpegPath`, `fFprobePath`, `zIndex`, `rFrameRate`) a
|
||||
explicit `[SkipApiKeyAuthorizationAttribute]` exemption; only `ScannerController` is exempt
|
||||
today). A minimum-count guard asserts the scan found a sane number of controllers, so a
|
||||
namespace rename can't silently make the scan match nothing and give this test a false pass.
|
||||
It also asserts the **sensitive-read tier** (`Troubleshoot`/`Logs`/`Settings`/`Maintenance`)
|
||||
carries `[RequiresApiKey]` and that `ScannerController` carries `[LocalhostOnly]` — reflectively,
|
||||
so the tier can't silently drop a gate. `ApiKeyAuthorizationFilterTests.cs` unit-tests the filter
|
||||
itself: writes are always fail-closed, reads are gated when `Api:RequireKeyForReads` (default true)
|
||||
or `[RequiresApiKey]`, `OPTIONS` preflight and non-`/api` paths are exempt.
|
||||
- **Handler tests** (business logic behind the controller) use the shared in-memory SQLite fixture:
|
||||
`ErsatzTV.Tests/Support/InMemoryTvContext.cs`. Pattern: `SqliteConnection("Data Source=:memory:;Foreign
|
||||
Keys=False")` kept open for the fixture's lifetime, `EnsureCreatedAsync()` (not full migration
|
||||
@@ -464,3 +469,29 @@ for items that have no group, so the SPA can render an "ungrouped" bucket
|
||||
(`Id = unusedGroup.Id * -1`, `Name = "(none)"`). See issue #172. If you add a similar "ungrouped"
|
||||
concept elsewhere, this is the established pattern to follow — but be aware it means `Id` is not a
|
||||
reliable real-entity id for those synthetic rows.
|
||||
|
||||
## 9. Authentication — API key posture (fail-closed)
|
||||
|
||||
The whole `/api` surface is gated by the `X-Api-Key` header via the global `ApiKeyAuthorizationFilter`
|
||||
(issue #197 Bundle A). When you add an endpoint:
|
||||
|
||||
- **Do nothing** for the common case. Writes (POST/PUT/PATCH/DELETE) always require the key
|
||||
(fail-closed — there is no "open" mode). Reads (GET/HEAD) require the key when
|
||||
`Api:RequireKeyForReads` is enabled, which is the **default** (`true`). `OPTIONS` preflight is exempt.
|
||||
- The effective key comes from `IApiKeyProvider` (`ErsatzTV/Services/ApiKeyProvider.cs`): `Api:WriteKey`
|
||||
if configured, else a key persisted at `FileSystemLayout.ApiKeyPath` (`/config/api.key`, `0600`), else
|
||||
a freshly generated 256-bit key. It is never empty.
|
||||
- **Sensitive-read GETs** that disclose secrets/paths or trigger work must carry `[RequiresApiKey]` so
|
||||
they stay gated even if an operator sets `Api:RequireKeyForReads=false`. Current tier:
|
||||
`Troubleshoot`/`Logs`/`Settings`/`Maintenance`. `ApiControllerSecurityTests` asserts this reflectively.
|
||||
- **Internal loopback callbacks** (the scanner's `/api/scan/*`) use `[SkipApiKeyAuthorization]` +
|
||||
`[LocalhostOnly]` — the API key is a poor fit for a co-located child process, so the gate is the
|
||||
loopback check (sound only because `ForwardedHeaders` trust is restricted via
|
||||
`ForwardedHeaders:KnownProxies`/`KnownNetworks`).
|
||||
- **CORS** is opt-in: no cross-origin access by default (the SPA is same-origin from `/app`); set
|
||||
`Api:CorsAllowedOrigins` (semicolon-separated exact origins) to allow specific browser origins — the
|
||||
policy already permits `X-Api-Key`/`If-Match` and exposes `ETag`.
|
||||
- The SPA sends the stored key (`ctv-api-key`) on **every** request; users enter it on the keyless
|
||||
**API Key** screen (`web/src/screens/ApiKeyScreen.tsx`, route `/app/api-key`). See spa-conventions §5e.
|
||||
|
||||
The declarative OpenAPI security scheme + global 401 documentation are Phase-2 (#286/#287), not this tier.
|
||||
|
||||
Reference in New Issue
Block a user