# Tokens and security ## Contents - [The API secret](#the-api-secret) - [Issuing tokens](#issuing-tokens) - [Keeping tokens off command lines](#keeping-tokens-off-command-lines) - [Behind a reverse proxy](#behind-a-reverse-proxy) - [Image URLs](#image-urls) - [What is never logged](#what-is-never-logged) ## The API secret `api.secret` signs every bearer token (HS256) and must be at least 32 bytes. `uberbringer secret` prints a new random one. `install.sh` writes it into a config that only root and the daemon's group can read, and `uberbringer config get` never prints it. A token stays valid until it expires, and a token issued without `--ttl` never does. Changing the secret invalidates every token signed with the old one, which is the only way to withdraw a token. ## Issuing tokens All `/api/v1` routes need an `Authorization: Bearer ` header; a token in a query string is refused, since it would leak into proxy logs. On a host set up by `install.sh`, issue a token as root, naming the client: ```sh sudo uberbringer token --config /etc/uberbringer/config.toml --subject my-script ``` What a token may do is set when it is issued ([token](cli.md#token)): - Without flags, it may use every route but cannot print jobs with `raw` elements. - `--raw` lets it print them. Give it only to clients that send ESC/POS bytes of their own, since those bytes reach the printer as they are. - `--modules ntfy,notify` limits it to those modules. Give integrations, such as the [ntfy client](api.md#printing-from-the-ntfy-client), one of these, so that they cannot send printer commands. [api.md](api.md#api) gives the routes each token may call and the `403` `token_scope` answer for the others. ## Keeping tokens off command lines Keep a token off command lines, where other users of the machine can read it, and out of shell history. The examples in [api.md](api.md) send the header from a file only you can read, which curl 7.55 and later take as `-H @file`. Make it like this: the token passes through a shell variable, never a command's arguments or the terminal, and the file is written only if the token command succeeded. For a client on another machine, copy the file there. ```sh token=$(sudo uberbringer token --config /etc/uberbringer/config.toml --subject my-script) && (umask 077; printf 'Authorization: Bearer %s\n' "$token" > ~/.uberbringer-auth) unset token ``` [Printing from the ntfy client](api.md#printing-from-the-ntfy-client) does the same for the ntfy client's user, and [docker.md](docker.md) keeps the secret in an env file for a container. ## Behind a reverse proxy The daemon serves no TLS and listens on `127.0.0.1` by default. A reverse proxy in front terminates HTTPS: Caddy, which `install.sh` sets up, or your own in front of the [Docker image](docker.md). The proxy sets `X-Real-IP` to the client's address, and the daemon reads it only from the addresses in `webserver.trusted_proxies`, so that each client has a rate limit of its own ([webserver](configuration.md#webserver)). ## Image URLs Images are fetched by the worker, when the job prints. URLs that resolve to loopback, private or link-local addresses, cloud metadata endpoints included, are refused unless `images.allow_private_networks` is true or the host is in `images.allowed_hosts` ([images](configuration.md#images)). The address is checked when the connection is made, so a redirect or a DNS answer that changes cannot get round it. ## What is never logged Print contents, tokens and the API secret never reach the logs or Sentry. Request bodies and the `Authorization` header are never sent to Sentry. An ntfy subscription never logs a message's text or its topic, and its `last_error` in `/healthz` leaves out the topics, since on a public server a topic's name can be all that keeps others from publishing to it. [Logs](configuration.md#logs) lists what is logged, and [ntfy.md](ntfy.md#securing-the-topics) how to keep strangers off your topics.