Skip to content

Management API

The management API is an HTTP interface for observing and changing a running proxy. It reports statistics, destination health, live sessions and recent events, manages mappings, the lookup cache, sessions and login delays, and, when enabled, edits the configuration file and uploads certificates. The web interface is built on it, and scripts use the same endpoints. The API is available only when the configuration contains an [admin] table.

Every endpoint lives under /api/v1/ and exchanges JSON. The only other paths the management listener answers are the health check at /healthz and the files of the web interface under /ui/; any other path receives 404 Not Found.

The [admin] table configures the API’s listener and its authentication. proxy init writes a table like this one:

[admin]
bind = "127.0.0.1:9443"
bearer_token_file = "/etc/proxy/admin-token"
config_write = true
[admin.allow]
listener_ports = [24, 25, 80, 110, 143, 443, 465, 587, 993, 995, "1024-9442", "9444-65535"]
destination_ports = [24, 25, 110, 143, 443, 465, 587, 993, 995, 4190, 8080, 8443]
KeyDefaultDescription
bindrequiredAddress and port of the API’s listener. Changing it requires a restart.
tlsimplicitMust be implicit. Any other value is rejected with admin.tls: must be implicit (plaintext admin is rejected).
bearer_token_fileunsetFile holding the bearer token. Surrounding white space is removed.
bearer_tokenunsetBearer token given inline in the configuration file.
min_token_len32Minimum token length, in bytes.
lockout_threshold5Failed authentications from one address after which the address is locked out.
lockout_duration5mHow long a locked-out address is refused.
max_body_size1048576Largest accepted request body, in bytes.
config_writefalseAllows the API and the web interface to change the configuration file and upload certificates.
session_idle_timeout30mHow long a browser session stays valid without a request.
session_lifetime12hHow long a browser session stays valid at most, however active it is.
allowemptyThe operator allowlist: the addresses and ports listeners may bind, and the hosts and ports destinations may point at.

The [admin] table, including [admin.allow], can never be changed through the API, so that no mistake made through the API can lock administrators out or widen what they may configure. It is changed in the file on the host and applied with a reload; adding or removing the whole table, and changing bind, take effect at the next restart.

The token is taken from the PROXY_ADMIN_TOKEN environment variable, then from bearer_token_file, then from bearer_token. At least one must be present (admin requires bearer_token_file, bearer_token, or PROXY_ADMIN_TOKEN), and a token shorter than min_token_len stops the proxy from starting. Every reload and every configuration change reads the token again from the same sources, and is rejected when none yields a valid token. When the token changes, every browser session is signed out.

The API is always served over TLS. When a [tls.certificate.admin] entry exists, the listener presents it whatever name the client requests. Without one, it presents the default certificate, the only certificate when exactly one is declared, or else a self-signed certificate generated when the configuration is loaded, as described under Certificates. A reload or configuration change replaces the certificate for new connections.

Who can reach the API, its connection limits and its lockout are covered under Security.

The examples on this page read the token from the file that proxy init writes and call the API on the loopback address. They pass -k because the certificate created by proxy init is self-signed; with a certificate the client trusts, drop it:

Terminal window
TOKEN=$(sudo cat /etc/proxy/admin-token)
curl -sk -H "Authorization: Bearer $TOKEN" https://127.0.0.1:9443/api/v1/overview

Requests must use HTTP/1.1, with exactly one Host header and at most one Authorization header. A request body must be sent with Content-Length and stay within max_body_size: a chunked body receives 411 Length Required and a larger one 413 Content Too Large. A request head larger than 16 KiB receives 431 Request Header Fields Too Large. A trailing slash on the path is ignored. An unknown path receives 404 Not Found before authentication, and a known path with the wrong method receives 405 Method Not Allowed after it; HEAD and OPTIONS are not supported on any endpoint.

Request bodies are JSON objects, except where an endpoint takes TOML text. Every response is JSON, except the health check and the web interface’s files, and carries Cache-Control: no-store along with security headers such as Content-Security-Policy and Strict-Transport-Security. Times are UTC, in the form 2026-11-19T14:05:00Z. Durations are whole numbers, in seconds in fields whose names end in _s and in milliseconds in fields whose names end in _ms.

Identifiers and other names that appear in a path, as in /api/v1/mappings/<identifier>, must be percent-encoded; a / inside an identifier is sent as %2F. An identifier is treated like a login: a master user suffix is removed (see routing.master_user_separators) and the rest is normalised as configured in mapping.normalize. An identifier that contains control characters, spaces or quotes, is too long, or is empty once the suffix is removed, receives 400 Bad Request with invalid_identifier. The names lookup, import and reload are endpoints of their own, so an identifier with one of these names cannot be addressed under /api/v1/mappings/.

Lists that can grow large are paginated. They accept limit and cursor in the query string and return next_cursor, which is null on the last page. A cursor is opaque: pass it back unchanged to fetch the next page. A limit outside the accepted range is rejected with 400 Bad Request, not clamped.

An error is answered with a status code and a body of the form {"error": {"code": "...", "message": "..."}}. The code is a stable, machine-readable name, while the message is meant for people. The codes are:

CodeStatusCause
bad_request400, 405, 431, 505A malformed request, body or query parameter, or a CONNECT request (405)
unauthorized401No valid token or session
csrf403A browser request without a valid CSRF token
config_write_disabled403A configuration write while admin.config_write is off
not_found404An unknown path or history entry
unknown_destination404, 400An unknown destination in the path, a filter or a mapping
unknown_listener400An unknown listener in a filter
invalid_identifier400An identifier that cannot be a login
method_not_allowed405A known path with the wrong method
revision_mismatch409A change based on a revision that is no longer on disk
length_required411A body without Content-Length
payload_too_large413A body larger than max_body_size, or a certificate upload above 256 KiB
too_many_entries413An import of more than 5000 mappings
invalid_certificate, invalid_key, key_mismatch422A certificate upload that does not check out
precondition_required428A source replacement without If-Match
locked_out429A request from a locked-out address
io_error, internal500The configuration file or the certificate directory cannot be written
read_only501A write to a mapping store that is not writable
store_error, reload_failed502The mapping store failed to answer, or the mapping file failed to reload
not_applied503A configuration saved but not applied
config_unavailable503A configuration endpoint called while the proxy does not know the path of its configuration file (configuration file path unknown)

Validation failures of the configuration have a body of their own, described under Configuration editing.

A script authenticates with the bearer token in an Authorization: Bearer header; the scheme name is matched regardless of case. A wrong token receives 401 Unauthorized, counts towards the lockout of the client’s address and is logged as admin 401 unauthorized. A request with neither a token nor a session cookie receives 401 Unauthorized without counting, and so does a request whose Authorization header uses another scheme. When a bearer header is present, it is the only credential considered.

A browser uses a session instead, so that the token is entered once and never kept by the page.

POST /api/v1/session exchanges the token for a session. The body is {"token": "..."}. On success, the response sets the cookie __Host-proxy_session, which is HttpOnly, Secure, SameSite=Strict and bound to the whole host, and returns the session’s CSRF token:

{
"csrf": "q6lJ0Gm1x6l8yC4dG9iTt2bPZ0n1u3W5aB7cD9eF1gH",
"idle_timeout_s": 1800,
"expires_at": "2026-11-20T02:05:00Z"
}

A wrong token receives 401 Unauthorized and counts towards the lockout, like a wrong bearer token. GET /api/v1/session returns the same body for the session the cookie names, which lets a reloaded page recover its CSRF token, and 401 Unauthorized when there is no valid session. DELETE /api/v1/session ends the session and clears the cookie, and always answers 204 No Content.

A request that carries the cookie and no Authorization header is authenticated by the session. A session is bound to the client address that created it: the same cookie presented from another address is not accepted. A missing, expired, unknown or rebound session receives 401 Unauthorized, which does not count towards the lockout, since the cookie is not a guess at the token. Every request other than GET must also send the CSRF token in an X-CSRF-Token header, and, when the browser sends Sec-Fetch-Site, that header must be same-origin. A request that fails either check receives 403 Forbidden with csrf. Together with the cookie’s restrictions, these checks stop another site from making the browser change the proxy on the administrator’s behalf. Requests with the bearer token need no CSRF token.

A session ends after session_idle_timeout without a request, or session_lifetime after it was created, whichever comes first. Sessions are held in memory. At most 64 exist at a time, and creating another one ends the oldest. All sessions end when the proxy restarts, and when a reload or configuration change changes the token, so that rotating the token also signs out every browser.

GET /healthz answers 200 OK with the body ok and no authentication. It is exempt from the lockout, as described under Observability, and other methods receive 405 Method Not Allowed.

GET /api/v1/overview summarises the running proxy: its version, start time and uptime, the number of open connections (including those still before authentication), the configuration in effect, the active sessions per protocol, cumulative counters, the lookup cache, how many destinations are up, degraded or down, and the ten identifiers with the most sessions:

{
"version": "2.0.0",
"started_at": "2026-11-19T08:00:00Z",
"uptime_s": 21900,
"open_connections": 31,
"config": {
"path": "/etc/proxy/config.toml",
"revision": "3fa1c09b27de",
"loaded_at": "2026-11-19T12:30:00Z",
"writable": true,
"restart_required": []
},
"sessions": { "active": 27, "by_protocol": { "imap": 20, "pop3": 0, "...": 0 } },
"counters": {
"accepted": 9120, "rejected_limit": 0, "auth_ok": 8800,
"auth_rejected": 41, "backend_failures": 3
},
"cache": {
"entries": 380, "max_entries": 100000, "hits": 18234,
"misses": 412, "hit_rate_pct": 97.79
},
"destinations": { "total": 2, "up": 2, "degraded": 0, "down": 0 },
"top_identifiers": [ { "identifier": "[email protected]", "sessions": 4 } ]
}

by_protocol has a key for each of smtp, submission, lmtp, imap, pop3, managesieve and http. config.revision identifies the content of the configuration file the running configuration was built from, and writable tells whether the configuration endpoints may change the file. restart_required lists the settings that changed since startup but take effect only after a restart; the only settings that can appear there are server.threads, server.log_level, admin.bind and admin (the table was added or removed).

GET /api/v1/metrics/series returns the recent history the proxy samples every 10 seconds, for up to one hour. The optional window parameter limits the history to the given number of seconds, and defaults to 3600. To keep the response small it is columnar: fields names the values of each point, and points holds one array per sample, oldest first, starting at start:

{
"interval_s": 10,
"start": "2026-11-19T13:05:10Z",
"fields": ["active", "accepted", "auth_ok", "auth_rejected",
"backend_failures", "cache_hits", "cache_misses"],
"points": [[27, 4, 4, 0, 0, 3, 1], [28, 2, 1, 1, 0, 2, 0]]
}

active is the number of authenticated sessions at the time of the sample; the other values count what happened during the sample’s interval. The history survives configuration reloads but starts empty at every restart.

GET /api/v1/destinations lists every destination, and GET /api/v1/destinations/<name> returns one, or 404 Not Found with unknown_destination. Each entry describes the destination’s configuration, its health, its live sessions and, when the mapping store can count them, how many identifiers are mapped to it:

{
"id": "legacy",
"host": "192.0.2.10",
"tls_server_name": "mail.legacy.example.com",
"protocols": {
"imap": { "port": 993, "tls": "implicit", "forwarding": "proxy" },
"submission": { "port": 587, "tls": "starttls", "forwarding": "xclient" }
},
"forwarding": "proxy",
"forwarded": false,
"tls_verify": "platform",
"tls_client_cert": false,
"source_ips": [],
"hide_auth_errors": false,
"allow_plaintext_auth": false,
"roles": ["default"],
"health": {
"state": "degraded",
"consecutive_failures": 2,
"failure_sources": 1,
"host_level_failure": false,
"down_until": null,
"last_failure": {
"at": "2026-11-19T14:01:12Z", "stage": "greeting",
"class": "session", "error": "backend closed the connection"
}
},
"sessions": 14,
"mapped_identifiers": 1250
}

tls_verify is pinned when a certificate fingerprint is pinned, insecure when invalid certificates are allowed, and platform otherwise, following the destination’s certificate verification settings; certificates, keys and fingerprints themselves are never returned. roles contains default for the default destination and passthrough for the SMTP pass-through destination. The health state is up without failures, degraded while failures accumulate below the threshold, and down while the circuit breaker holds the destination out of service, until down_until. last_failure.stage names the step that failed, such as dns, connect, backend_tls, greeting, starttls, forwarding or auth, and last_failure.class is connect for a failure to reach the backend and session for a failure after the backend saw the client, the two kinds of evidence described under health and resilience. mapped_identifiers is null when the store cannot count its mappings.

POST /api/v1/destinations/<name>/reset clears the destination’s failures and down state, and returns the destination’s updated entry.

GET /api/v1/listeners lists the listeners with their protocol, bind addresses, TLS mode, PROXY protocol settings, connection limit, pre-authentication timeout, authentication attempts and forwarded mode, together with their live sessions and the cumulative accepted and rejected_limit counts.

GET /api/v1/connections lists the live sessions, newest first. Each item gives the session’s numeric id, the identifier once known, the protocol, listener, client address, destination and backend address, whether each leg uses TLS, the start time and the bytes relayed in each direction (bytes_up from the client, bytes_down to it). Connections still before authentication are not listed. The list can be narrowed with identifier (a prefix of the normalised identifier, compared as given), protocol, destination and listener. It is paginated with limit (from 1 to 1000, 100 by default) and cursor, and total gives the number of sessions that match the filters.

POST /api/v1/connections/kick closes sessions on both legs at once and returns {"kicked": <n>}. The body names either an account, which closes all its sessions, or up to 1000 sessions by their id, which suits closing a selection from the connection list:

Terminal window
curl -sk -X POST -H "Authorization: Bearer $TOKEN" \
-d '{"identifier":"[email protected]"}' \
https://127.0.0.1:9443/api/v1/connections/kick

A body with both identifier and ids, or neither, receives 400 Bad Request. Clients usually reconnect at once, and their new sessions are routed from the current mapping.

A login delay holds new logins of one account for a while, so that an account can be moved without its clients reconnecting to the old destination in between: delay the account, kick its sessions, change the mapping, and the waiting logins proceed to the new destination. A delayed login waits at most 2 minutes, and then proceeds. Changing the account’s mapping, invalidating its cache entry, clearing the cache and reloading the mapping file all end the delay early.

GET /api/v1/delays lists the delays in effect, each with the identifier, the time it ends, the seconds remaining and the number of logins waiting on it. PUT /api/v1/delays/<identifier> with {"seconds": 600} sets or replaces a delay, and returns the delay’s entry; seconds must be a whole number, and 0 releases the waiting logins at once and returns {"released": true}. DELETE /api/v1/delays/<identifier> ends a delay and returns {"released": true}, or {"released": false} when there was none.

GET /api/v1/mappings lists the stored mappings as items of {"identifier", "destination"}. The optional prefix parameter restricts the list to identifiers that start with it, and the list is paginated with limit (from 1 to 1000, 50 by default) and cursor. The response also describes the store: its source (file, redis, sql, or null without a [mapping] table), whether it is writable, whether it is listable, and the total number of mappings, null when the store cannot count them. The file and Redis stores can be listed, and a SQL store only when it has a list_query; a store that cannot be listed returns an empty list with listable false. A store that fails to answer receives 502 Bad Gateway with store_error.

GET /api/v1/mappings/lookup?identifier=<identifier> explains how an identifier resolves, step by step, without touching the cache:

{
"identifier": "[email protected]*admin",
"account": "[email protected]",
"store_value": "stalwart",
"store_error": false,
"destination": "stalwart",
"routed_to_default": false,
"cache": { "state": "positive", "ttl_remaining_s": 3412 }
}

account is the identifier with any master user suffix removed, and key is its normalised form, the key the store is asked for. store_value is what the store holds for that key right now, null when it holds nothing, and store_error is true when the store could not be asked. destination is where a new session would go: the cached route when there is one, otherwise the store’s answer. Comparing the two shows whether a cached route is stale. The cache state is miss, positive (a mapped route), negative (routed to the default destination) or transient (cached after a store error), with the seconds the entry has left.

PUT /api/v1/mappings/<identifier> creates or replaces a mapping. The body names the destination, and the response returns the identifier as given, its normalised form, the destination, and whether the mapping was created (false when an existing mapping was replaced):

Terminal window
curl -sk -X PUT -H "Authorization: Bearer $TOKEN" \
-d '{"destination":"stalwart"}' \
https://127.0.0.1:9443/api/v1/mappings/alice%40example.com
{ "identifier": "[email protected]", "normalized": "[email protected]", "destination": "stalwart", "created": true }

DELETE /api/v1/mappings/<identifier> removes a mapping and returns {"existed": true} or {"existed": false}. POST /api/v1/mappings/import writes up to 5000 mappings in one call, given as {"entries": [["[email protected]", "stalwart"], ...]}. It writes every valid entry and returns {"upserted": <n>, "errors": [...]}, where each error names the index of a rejected entry and why it was rejected (invalid_identifier or unknown_destination); a larger batch receives 413 Content Too Large with too_many_entries.

All three writes invalidate the cached routes of the identifiers they change and end their login delays. Open sessions are not moved; kick them to make their clients reconnect. A store that is not writable receives 501 Not Implemented with read_only, an undeclared destination 400 Bad Request with unknown_destination, and a failed write 502 Bad Gateway with store_error. Which stores are writable is described under Mappings.

POST /api/v1/mappings/reload reads the mapping file again and ends every login delay, and returns {"reloaded": true}. It does not clear the cache, so a reload after editing the file is followed by a cache invalidation. A file that cannot be read receives 502 Bad Gateway with reload_failed, and the previous mappings stay in effect. For the Redis and SQL stores, which have nothing to reload, the call only ends the delays.

GET /api/v1/cache returns the cache’s entries, hits, misses and hit rate, its capacity, and the time to live of each kind of entry in milliseconds (ttl.positive_ms, ttl.negative_ms and ttl.transient_ms). The capacity is max_entries or, when cache_max_bytes is set, max_bytes. The transient time to live is 5 seconds, or negative_ttl when that is shorter. The same cache object, without ttl, appears in the overview.

POST /api/v1/cache/invalidate with {"identifier": "[email protected]"} removes one cached route, and an empty body or {} clears the whole cache; the response is {"invalidated": "one"} or {"invalidated": "all"}. The identifier is read only from the body. Invalidating an entry ends that account’s login delay, and clearing the cache ends every delay. Cache invalidation describes when this is needed.

GET /api/v1/events returns the proxy’s recent events: management actions, destination health changes, configuration changes and mapping changes, up to the last 512 since the proxy started:

{
"last_seq": 42,
"items": [
{ "seq": 41, "at": "2026-11-19T14:02:00Z", "kind": "mapping", "actor": "session:3fa1",
"ip": "127.0.0.1", "message": "mapped to stalwart", "target": "[email protected]" },
{ "seq": 42, "at": "2026-11-19T14:02:05Z", "kind": "admin", "actor": "session:3fa1",
"ip": "127.0.0.1", "message": "kicked 2 sessions", "target": "[email protected]" }
]
}

Each event has a sequence number seq, a time, a kind (admin, health, config or mapping), the actor and client ip of a management action, a message and, when there is one, the identifier, destination or address it concerns. The actor is bearer for a request authenticated with the token, or session:<tag> for a browser session, where the tag is a short abbreviation of the session that does not reveal it. Health transitions and address lockouts have no actor. The optional kind parameter selects one kind, and after returns only events newer than the given sequence number, so that a poller can pass the last_seq of its previous response and receive only what is new. Every matching event in the buffer is returned; there is no further pagination.

The configuration endpoints read, validate and, when allowed, change the configuration file.

Each version of the file is identified by its revision, 12 hexadecimal characters derived from a hash of its content. Every change names the revision it was based on, and the proxy refuses a change based on a revision that is no longer on disk with 409 Conflict and revision_mismatch; the body carries the current revision next to the error. Two administrators editing at once, or an edit racing a change made with a text editor, therefore never overwrite each other silently.

Writes, including dry runs, are refused with 403 Forbidden and config_write_disabled unless admin.config_write is true. Reading, validating, reloading and listing the history always work. The [admin] table can never be changed through the API, even with writes enabled; a change that touches it receives 422 Unprocessable Content with the [admin] table is read-only through the API. A change may only point certificate, key and mapping file paths at files inside the confined directories, as described under Path confinement. Secrets are masked in everything the endpoints return: admin.bearer_token appears as ********, and in a Redis or SQL url the user name, password and credential query parameters are masked; a URL without a host, such as a SQLite one, is masked entirely.

GET /api/v1/config returns the file’s path, its revision on disk, the running_revision the running configuration was built from (the two differ when the file was edited and not reloaded), loaded_at, writable, restart_required, the masked TOML source, and the running configuration as JSON values, with defaults filled in. GET /api/v1/config/schema returns a JSON description of every configuration key, with its type, default and constraints, which the web interface uses to build its forms.

POST /api/v1/config/validate takes a TOML document as the body and parses and validates it, without saving or applying anything. Validation includes the operator allowlist and the path confinement, but not the revision or the [admin] rule. It does not build the runtime, so it does not load certificates, open mapping stores, read the mapping file or bind addresses; a document that validates can still be refused when it is saved, with a 422 Unprocessable Content whose path is empty. A masked secret left unchanged in the document stands for the value on disk, as for the writes described below, so a document fetched from GET /api/v1/config validates as it would be saved. A valid document returns {"valid": true}. An invalid one receives 422 Unprocessable Content with every problem found:

{
"valid": false,
"errors": [
{ "path": "listener.imaps.max_connections", "message": "must be between 1 and 1000000", "line": 14 }
]
}

PATCH /api/v1/config changes individual keys. The body names the base revision and a list of operations, each with a path given as an array of keys:

{
"revision": "3fa1c09b27de",
"ops": [
{ "op": "set", "path": ["destination", "stalwart", "hide_auth_errors"], "value": true },
{ "op": "remove", "path": ["destination", "legacy", "source_ips"] }
]
}

A set creates the key, and any missing tables on its path, or replaces its value; setting null removes the key. Removing a key that does not exist does nothing. A JSON object becomes a table, and an array of objects an array of tables. A path element that addresses an array or an array of tables is an index, and setting the index one past the end appends. A path holds at most 8 elements. The edit keeps the file’s comments and formatting.

PUT /api/v1/config/source replaces the whole file with the TOML document in the body instead, and takes the base revision in an If-Match header; a request without one receives 428 Precondition Required. A masked secret left unchanged in the submitted document keeps the value on disk, so a document fetched from GET /api/v1/config can be edited and sent back without retyping secrets.

Both writes go through the same steps, and so do history restores and certificate uploads:

  1. The result is validated in full, including the allowlist, the path confinement and the [admin] rule. An invalid result receives 422 Unprocessable Content with the same error list as validation.
  2. The complete new runtime is built, including certificates and the mapping store. A failure receives 422 Unprocessable Content with an error whose path is empty.
  3. With ?dry_run=true, the proxy stops here and returns the outcome without saving it.
  4. New listener addresses are bound. An address that cannot be bound receives 422 Unprocessable Content, and nothing is saved.
  5. The previous file is saved to the history, and the new one is written atomically.
  6. The new configuration is applied, exactly as a reload would apply it.

The response describes the result, with applied false for a dry run:

{
"revision": "8c02e1d5a4f7",
"source": "...",
"applied": true,
"restart_required": ["server.threads"]
}

restart_required lists the settings that take effect only at the next restart, as for the overview. When a change adds, removes or alters a listener or a destination, the proxy logs admin changed listeners or destinations with the actor, address, revision and a summary of the changes, and records the same summary as an event.

In the rare case that the file was saved but the new runtime could no longer be applied, because the running one changed while the write was being prepared, the response is 503 Service Unavailable with not_applied. The new revision is then on disk but not running; a reload applies it.

POST /api/v1/config/reload reads the file again and applies it, and returns {"revision", "restart_required"}. A file that fails validation, or a configuration that cannot be built or bound, receives 422 Unprocessable Content with the error, and the running configuration is kept. A reload is not a write: it works without config_write and does not add to the history.

Every write through the API keeps the file it replaces in the history, a directory named after the file with .history appended, such as /etc/proxy/config.toml.history. When the configuration path is a symbolic link, writes and the history follow it to the real file, so the link stays in place. The proxy’s user must be able to create files in the directory that holds the real file, since the new version is written beside it and renamed over it; otherwise every write receives 500 Internal Server Error with io_error.

The last 10 versions are kept, readable only by the proxy’s user. GET /api/v1/config/history lists them, newest first, each with an id (the time it was replaced, such as 20261119T140500Z, with a -01 suffix and up for several in the same second), its revision, size and time. GET /api/v1/config/history/<id> returns the masked source of one version, and POST /api/v1/config/history/<id>/restore with {"revision": "<current revision>"} makes it the current file again. A restore is a write like any other: it requires config_write, is validated and applied in the same way, and keeps the file it replaces in the history, so it can itself be undone. A version whose [admin] table differs from the current one cannot be restored.

PUT /api/v1/certificates/<name> uploads a TLS certificate and its private key, stores them next to the configuration and points [tls.certificate.<name>] at them, as one configuration write. The name holds 1 to 64 letters, digits, - or _; the name admin is the certificate of the management listener itself. The body names the base revision, the PEM certificate chain and the PEM private key, and optionally the subjects and the default flag:

{
"revision": "3fa1c09b27de",
"cert": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n",
"key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"subjects": ["mail.example.com", "*.example.com"],
"default": true
}

The upload is limited to 256 KiB. cert must hold only CERTIFICATE blocks, the leaf first, at most 16 of them. key must hold exactly one unencrypted private key, in PKCS#8 (PRIVATE KEY), PKCS#1 (RSA PRIVATE KEY) or SEC1 (EC PRIVATE KEY) form. A pair that does not check out receives 422 Unprocessable Content with one of these errors:

  • invalid_certificate: the certificate field must hold PEM CERTIFICATE blocks only, no certificate found, the certificate chain is too long or a certificate is not valid X.509 DER
  • invalid_key: the key field must hold exactly one unencrypted PEM private key, encrypted private keys are not supported or the private key is invalid or uses an unsupported algorithm
  • key_mismatch: the private key does not match the certificate

The proxy writes the pair into the certs/ directory next to the configuration file, creating it readable by the proxy’s user only when it is missing, as <name>.<hash>.crt and <name>.<hash>.key, where the hash identifies the certificate’s content. The files are readable by the proxy’s user only, and the private key is never returned or logged. The entry’s cert and key are set to the new files. subjects replaces the entry’s subjects when given; an empty list removes them, so the subjects are read from the certificate; and omitting it keeps the current ones. default: true makes the certificate the default and clears the flag, and the * subject, on every other entry. Any other entry whose only subject is *, whatever its own default flag, would be left serving nothing, so the upload is refused with an error at that entry’s subjects until the entry names its hosts or is removed:

tls.certificate.<id>.subjects: certificate <id> is the default through subjects = ["*"] and names no host; give it explicit subjects or remove it before making <name> the default

The rest of the upload is a configuration write, with the same revision check, validation, ?dry_run=true, history and application. The response is that of a write, with a certificate object giving the name and the expiry of the leaf certificate as not_after. After a successful upload, uploaded files that neither the new configuration nor any version in the history references are deleted; files in certs/ whose names do not follow the <name>.<hash>.crt and <name>.<hash>.key pattern, such as files placed there by hand, are never touched.