feat(serve): per-api-key cdm and service config with server-side identity cache

serve.users.<key>.cdm and service_config give each API key its own device and service config. Service.IDENTITY_CACHE keys route to a per-key directory that clients never receive
This commit is contained in:
imSp4rky
2026-11-16 13:31:17 -07:00
parent 08481d3a33
commit f1e4081313
16 changed files with 508 additions and 63 deletions
+1 -1
View File
@@ -362,4 +362,4 @@ The REST API authenticates with `X-Secret-Key`. The middleware advertises `Autho
### Where device access is read
The map of accepted API keys lives at `request.app["config"]["users"]`. For DRM operations, an API key's permitted Widevine devices come from its `devices` list, and PlayReady devices from `playready_devices`. The server uses the first configured device when a request does not (or may not) override it. A server-wide `config.cdm[<service>]` mapping, if present, takes precedence over the API key's device list when the server chooses which device to use.
The map of accepted API keys lives at `request.app["config"]["users"]`. For DRM operations, an API key's permitted Widevine devices come from its `devices` list, and PlayReady devices from `playready_devices`. The server uses the first configured device when a request does not (or may not) override it. A `cdm` entry for the service takes precedence over the API key's device list when the server chooses which device to use: the API key's own `serve.users.<key>.cdm` entry, else the server-wide `config.cdm[<service>]` mapping.
+9 -2
View File
@@ -414,7 +414,12 @@ serve:
cannot read each other's cached tokens. The server deletes the directory when the
remote session ends. A remote session that uses a server account (`serve.server_accounts`)
gets a persistent per-account cache instead, so the account's tokens outlive the
remote session. The server and the client both refuse a forwarded cache file that is not
remote session. A service can name cache files that hold its device identity in
`Service.IDENTITY_CACHE`. A remote session on the server's device, or of an API key with its
own device config, writes those files to a directory of the API key, outside the remote
session's directory, so the server never sends them to the client and never takes them from
the client, and the next remote session of that
API key reads them again. The server and the client both refuse a forwarded cache file that is not
JSON or that names a type other than a date or time, and the service then authenticates again.
- **A tunnel belongs to its API key.** The server accepts `tunnel:<id>` only from the API key
that opened the tunnel. Its SOCKS5 proxy listens on loopback only, and it needs a username and
@@ -603,7 +608,9 @@ The handler writes forwarded `cache` files into that directory before authentica
On `DELETE`, when the login belongs to the client (`client_auth`) and the remote
session does not run on the server's device, the handler harvests updated cache files from the whole directory tree (compressing each
with zlib and base64-encoding, **excluding** `titles_*` files) and returns them
under a `cache` field, so the client can keep refreshed tokens. Each cache key
under a `cache` field, so the client can keep refreshed tokens. A remote session on the
server's device keeps the files of the service's `IDENTITY_CACHE` in
`_identity/<namespace>/<service>` instead, so they are never in that tree. Each cache key
is the file path relative to that directory, with `/` separators and no `.json`
suffix, which is the `Cacher` cache key the service reads it with: