Key Vaults¶
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.
key_vaults¶
- Type:
list[dict]· Default:[]
A list of key-vault backends. The order in which unshackle asks them is in How lookups and caching work. Each entry has these fields, plus the fields of its backend:
| 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. |
type |
Purpose | Required fields | Load failure during dl |
|---|---|---|---|
SQLite |
A local SQLite database file | path |
Stops the run. |
MySQL |
A shared MySQL or MariaDB database | host, database, username |
Skipped with a warning. |
HTTP |
An HTTP vault in one of three protocols | host, password or api_key, username in query mode |
Skipped with a warning. |
API |
unshackle's own REST vault protocol | uri, token |
Skipped with a warning. |
key_vaults:
- type: SQLite
name: Local
path: ~/.unshackle/keys.db
- type: MySQL
name: Team
host: db.example.com
database: keys
username: unshackle
password: hunter2
no_push: false
SQLite¶
| 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¶
| 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, 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¶
| 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. |
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¶
| 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. |
An API vault whose name contains decrypt_labs and has no token takes the token from
decrypt_labs_api_key.
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.
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 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.
vault_timeout¶
- Type:
float· Default:10.0
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.
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.