docs(config): make the configuration reference the one owner of every option table

This commit is contained in:
imSp4rky
2026-12-04 18:02:28 -07:00
parent ec6a48f8c0
commit 2f8e2aba37
16 changed files with 555 additions and 659 deletions
+114 -33
View File
@@ -1,23 +1,30 @@
# Key vaults { #key-vaults }
The full guide is at [Vaults](../../guide/vaults.md). Two keys configure them.
Two config keys configure the key vaults. What a vault does during a download, the decode
check and the `kv` commands are in the [Vaults](../../guide/vaults.md) guide.
## `key_vaults`
- **Type:** `list[dict]`  ·  **Default:** `[]`
An ordered list of key-vault backends. unshackle queries them in order and reuses the
content keys instead of licensing them again. Each entry needs a `type` (the backend module
name) and a `name`, plus backend-specific keys.
A list of key-vault backends. The order in which unshackle asks them is in
[How lookups and caching work](../../guide/vaults.md#how-lookups-and-caching-work). Each entry
has these fields, plus the fields of its backend:
| `type` | Purpose | Required keys | Notes |
|--------|---------|--------------|-------|
| `SQLite` | Local SQLite database | `name`, `path` | Loaded **critically**; a failure aborts the run. |
| `MySQL` | Remote MySQL database | `name`, `host`, `database`, `username` | Extra keys (e.g. `password`, `port`) forwarded to pymysql. `connect_timeout`, `read_timeout` and `write_timeout` default to `vault_timeout`. `autocommit` is always on. |
| `API` | RESTful JSON API | `name`, `uri`, `token` | Optional `headers` map is sent with every request. Honours `vault_timeout`. |
| `HTTP` | HTTP API with modes | `name`, `host`, one of `password`/`api_key`, and `username` in query mode | `api_mode`: `query` (default), `json`, `decrypt_labs`. Honours `vault_timeout`. |
| Field | Required | Description |
|-------|----------|-------------|
| `type` | yes | The backend: `SQLite`, `MySQL`, `HTTP` or `API`. The value is the name of the backend module, and the match is case-sensitive: `sqlite` does not load. |
| `name` | yes | A label that you choose. The `kv` commands and the log name the vault by it. |
| `no_push` | no | `true` makes the vault read-only: unshackle reads content keys from it and never writes to it. Default `false`. |
```yaml
| `type` | Purpose | Required fields | Load failure during `dl` |
|--------|---------|-----------------|---------------------------|
| [`SQLite`](#sqlite) | A local SQLite database file | `path` | Stops the run. |
| [`MySQL`](#mysql) | A shared MySQL or MariaDB database | `host`, `database`, `username` | Skipped with a warning. |
| [`HTTP`](#http) | An HTTP vault in one of three protocols | `host`, `password` or `api_key`, `username` in `query` mode | Skipped with a warning. |
| [`API`](#api) | unshackle's own REST vault protocol | `uri`, `token` | Skipped with a warning. |
```yaml title="unshackle.yaml"
key_vaults:
- type: SQLite
name: Local
@@ -31,34 +38,108 @@ key_vaults:
no_push: false
```
!!! note "Per-entry options"
- `no_push: true` makes a vault read-only (unshackle fetches content keys from it but never writes to it).
- A vault of `type: API` whose `name` contains `decrypt_labs` auto-fills its `token` from
[`decrypt_labs_api_key`](misc.md#external-api-keys) when not set inline. Vault `type` values are
case-sensitive module names.
- unshackle treats an empty or all-zero content key, of any length, as "no key" everywhere
and never stores it.
### `SQLite` { #sqlite }
!!! note "Bad content keys"
A content key from a vault is proven by short FFmpeg decodes of the decrypted output,
with windows inside the fragments of each KID in a fragmented MP4. A content key that
fails the decode is written to the `bad_keys` table of every `SQLite` vault with the name
of the vault that supplied it, and every vault lookup skips a flagged pair from then on. A `SQLite` vault also refuses to
store a flagged pair again. Only the `SQLite` backend stores flags; an `API` vault that
supplied the pair gets a report. A `serve` instance with
`server_cdm` flags a pair the same way when a remote client reports it, so a server whose
`key_vaults` hold no `SQLite` entry cannot remember a bad content key.
| Field | Required | Description |
|-------|----------|-------------|
| `path` | yes | The database file. `~` expands. unshackle makes the file and its tables on first use. |
Each service gets its own table, named after the service tag, with `kid` and `key_` columns.
The connections use WAL journaling with a 30-second busy timeout, so threads can share one file.
A `bad_keys` table holds each KID:KEY that failed the decode check, with the service, the vault
that supplied it and the time of the flag. It is not a service table, and every command that
walks the service tables skips it. Only the `SQLite` backend stores these flags.
### `MySQL` { #mysql }
| Field | Required | Description |
|-------|----------|-------------|
| `host` | yes | The database server hostname or IP. |
| `database` | yes | The database (schema) name. |
| `username` | yes | The login user. |
| *(any other field)* | no | Goes to `pymysql.connect` as it is, for example `password`, `port` or `ssl`. `autocommit` is always on. |
`connect_timeout`, `read_timeout` and `write_timeout` default to
[`vault_timeout`](#vault_timeout), or to 10 seconds when `vault_timeout` is `0`.
The backend reads its own `SHOW GRANTS` when it connects. It needs `SELECT` to load,
`INSERT` to write content keys, and `CREATE` to make a service table. Each `MySQL` vault keeps
one connection for the whole run and shares it between threads. When the server is down,
unshackle skips the vault for the rest of the run.
### `HTTP` { #http }
| Field | Required | Description |
|-------|----------|-------------|
| `host` | yes | The base URL of the vault API. |
| `api_mode` | no | `query` (default), `json` or `decrypt_labs`. |
| `username` | in `query` mode | Ignored in the other modes. |
| `password` | `password` or `api_key` | The password in `query` mode, the token in `json` mode. |
| `api_key` | `password` or `api_key` | Used in `decrypt_labs` mode. When you give both, `api_key` wins. |
| `timeout` | no | The request timeout in seconds. Default [`vault_timeout`](#vault_timeout). |
A vault with neither `password` nor `api_key` does not load.
| `api_mode` | Transport | Authentication | Notes |
|------------|-----------|----------------|-------|
| `query` | `GET` with query parameters | `username` and `password` as query parameters | Read and write. |
| `json` | `POST` of `{"method": ..., "params": ..., "token": ...}` | `password` as the token | Read and write one content key at a time. Cannot list all content keys. |
| `decrypt_labs` | `POST` in the DecryptLabs format | `api_key` in a `decrypt-labs-api-key` header | Read-only: `no_push` is always on. |
In `json` mode the methods are `GetKey`, `InsertKey` and `GetServices`. A bulk write
(`kv copy`, `kv add`) first sends `InsertKeys` with
`params: {"keys": {kid: key, ...}, "service": ..., "title": ...}`, up to 500 content keys a call,
and expects `{"inserted": <count>}`. A server that answers HTTP 404 or
`Unknown JSON-RPC method` to `InsertKeys` gets one `InsertKey` call for each content key for
the rest of the run. Because `json` mode cannot list content keys, a `kv copy` from it relies
on the server to skip duplicates.
A host that answers with a body that is not a JSON object, for example a parked domain or a
login page, is unreachable: unshackle logs one warning and skips the vault for the rest of the
run, and the `serve` health check reports the vault as failed. In `json` mode, HTTP 404 to a
lookup means that the vault has no entry. In `decrypt_labs` mode, an error status other than
429 is a miss.
### `API` { #api }
| Field | Required | Description |
|-------|----------|-------------|
| `uri` | yes | The base URI of the vault API. unshackle removes a trailing slash. |
| `token` | yes | The bearer token, sent as `Authorization: Bearer <token>`. |
| `headers` | no | Extra HTTP headers for each request, for example the Cloudflare Access service-token headers `CF-Access-Client-Id` and `CF-Access-Client-Secret`. |
| `timeout` | no | The request timeout in seconds. Default [`vault_timeout`](#vault_timeout). |
An `API` vault whose `name` contains `decrypt_labs` and has no `token` takes the token from
[`decrypt_labs_api_key`](misc.md#external-api-keys).
The backend calls endpoints under `uri`, for example `GET {uri}/{service}/{kid}` for one
content key, and reads the numeric `code` field of each JSON answer to find errors such as a
bad token, a rate limit or an unknown service tag. A push of many content keys goes in batches.
When the server refuses a batch as too large, unshackle makes the batch smaller, and later pushes
to that vault start at the size that worked.
!!! warning "This is unshackle's own protocol"
The `API` backend expects unshackle's request and response shape. A vault API of another
project does not work with it. Put an adapter in front of such a vault, or use the
[`HTTP`](#http) backend if one of its protocols matches.
### Bad content keys
A content key that fails the decode check goes into the `bad_keys` table of each `SQLite`
vault. Which vault gets a report, and what a server does, is in
[Wrong keys from a poisoned vault](../../guide/vaults.md#wrong-keys-from-a-poisoned-vault).
## `vault_timeout`
- **Type:** `float` &nbsp;·&nbsp; **Default:** `10.0`
Timeout in seconds for vault operations. Injected automatically into any backend whose
constructor accepts a `timeout` parameter (a per-vault `timeout` still wins). The `MySQL` backend
uses it as the default `connect_timeout`, `read_timeout` and `write_timeout`.
The timeout in seconds of a vault operation. unshackle gives it to each backend that takes a
`timeout` field (`HTTP` and `API`), unless the vault sets its own `timeout`. The `MySQL`
backend uses it as the default `connect_timeout`, `read_timeout` and `write_timeout`.
The `API` and `HTTP` backends send a request again up to 3 times when the vault answers
`429 Too Many Requests`. They wait the `Retry-After` time, but never longer than this timeout.
A connection failure or a timeout is not tried again. The run does not use a vault again after a
connection failure, a timeout, or a `429` that continues after the retries, so a vault that is
down costs one timeout per run.
unshackle does not try again after a connection failure or a timeout. The run does not use a
vault again after a connection failure, a timeout, or a `429` that continues after the retries,
so a vault that is down costs one timeout per run. unshackle writes to all vaults at the same
time, so a slow vault does not delay the others.