mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-16 22:15:07 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ a `widevine` or `playready` sub-entry, or a profile or `default` sub-entry. A pe
|
||||
that selects only by quality, or only for a different profile, loads no device when the run
|
||||
starts. When `server_cdm` is unset, unshackle then shows a warning, and the server decides who
|
||||
licenses the remote session.
|
||||
On a server, an API key can replace the entry for a service with its own (see
|
||||
[`serve`](services.md#serve)).
|
||||
With only the top-level `default` entry, the server CDM licenses when the API key has it. Set
|
||||
`server_cdm: true` on the server entry to keep a per-service entry for local runs only. See
|
||||
[`remote_services`](services.md#remote_services).
|
||||
|
||||
@@ -240,6 +240,42 @@ hold goes back to the client's device. When the service runs the remote session
|
||||
own device (a service option, such as a server-identity flag), the client's own vaults, and the
|
||||
server vault with this grant, are the only source, and a missing content key stops the download.
|
||||
|
||||
`cdm` gives the API key its own CDM device for a service. It maps a service tag to a device
|
||||
name, or to `widevine`, `playready` and `default` sub-entries that name a device for each DRM
|
||||
system. Per-profile sub-entries and a `default` service tag are not available here: name each
|
||||
service tag. The entry replaces the whole top-level [`cdm`](drm.md#cdm) entry for that service,
|
||||
both for the device the service sees when it starts and for the device that licenses its tracks.
|
||||
A remote session keeps the API key's entry it started with until it ends, also after a reload. A
|
||||
device name that names no device the server has, or any other sub-entry, stops the server at
|
||||
startup or refuses the reload.
|
||||
|
||||
`service_config` gives the API key its own service config. It maps a service tag to config keys,
|
||||
which the server merges over the service's `config.yaml` and the top-level `services` entry. A
|
||||
section of the service config that sets one of the same plain (not mapping or list) keys, such as
|
||||
a profile section with its own device identity, takes the API key's value too, so a client cannot
|
||||
select another identity through its profile name. The values stay on the server: no response sends
|
||||
them to a client. The cache that the service builds from them stays on the server only for a
|
||||
service that lists its identity cache keys, and the server logs a warning for a service that lists
|
||||
none. The server deletes that cache when a reload removes the API key.
|
||||
|
||||
```yaml
|
||||
serve:
|
||||
users:
|
||||
"key-1":
|
||||
server_cdm: [EXAMPLE]
|
||||
cdm:
|
||||
EXAMPLE: example_device_1
|
||||
service_config:
|
||||
EXAMPLE:
|
||||
device_id: DEVICE-1
|
||||
device_key: KEY-1
|
||||
```
|
||||
|
||||
An API key with its own `cdm` or `service_config` entry for a service cannot submit
|
||||
`/api/download` jobs for that service, because a job runs on the top-level config. On a server
|
||||
account, it shares the account's login with the other API keys but keeps its own device identity
|
||||
cache.
|
||||
|
||||
`admin` is a boolean that lets the API key run the maintenance endpoints (clear-cache, clear-temp, refresh-services). It is `false` unless the entry sets it. Keys that have no `users` entry, such as `api_secret`, keep that access.
|
||||
|
||||
`shared` is a boolean for an API key that a gateway in front of the server gives to many people.
|
||||
|
||||
Reference in New Issue
Block a user