Logbrook authenticates requests with bearer tokens. There are three roles, and each token belongs to exactly one.
The three roles
| Role | Configured in | Can do |
|---|---|---|
| Ingestion | [ingest_tokens] |
Send events. Create an index by writing to it or with PUT /indexes/{index}. |
| Read | [read_tokens] |
Search, count, facets, histograms, live tail and listing indexes. Scrape /metrics when unrestricted. |
| Admin (optional) | admin_tokens |
List, inspect, create and delete indexes. Cannot read or write events, and cannot scrape metrics. |
/health and /ready are public and reveal no log data.
Ingestion tokens set the source
Each ingestion token maps to a source name. Logbrook stamps that source on every event the token writes, and the payload can’t change it. Use one token per producer, deployment or team so you can filter and scope reads by origin.
Read tokens can be scoped
A read token lists the sources it may read; an empty list means every source. [read_index_scopes] can also restrict it to specific indexes. A request has to satisfy both limits.
- A request for a source or index outside the token’s scope gets
403. - A token scoped to sources gets only the index name from
GET /indexes/{index}, not size details. /metricsneeds a read token with no source scope and no index scope.
[ingest_index_scopes] limits ingestion tokens to indexes in the same way.
Admin tokens manage indexes, not events
An admin token can call the index management endpoints but can’t search, tail or ingest. Only an admin token can delete an index: read and ingestion tokens get 403.
Admin tokens are optional. Without one, you can’t delete indexes over the API. The default index and indexes declared in the configuration can’t be deleted even with one.
Configure tokens
admin_tokens = ["your-admin-token"]
[ingest_tokens]
"your-ingest-token" = "checkout-prod"
[read_tokens]
"your-read-token" = []
"your-checkout-reader" = ["checkout-prod"]
# Optional index limits.
[ingest_index_scopes]
"your-ingest-token" = ["payments"]
[read_index_scopes]
"your-checkout-reader" = ["payments"]export LOGBROOK_INGEST_TOKEN="$(openssl rand -hex 32)"
export LOGBROOK_SOURCE=checkout-prod
export LOGBROOK_READ_TOKEN="$(openssl rand -hex 32)"
export LOGBROOK_ADMIN_TOKEN="$(openssl rand -hex 32)"Rules every token follows
- 16 to 512 visible ASCII characters, with no whitespace.
- It can’t start with
replace-with-, the prefix of the example file’s placeholders. - No token can appear in more than one role.
- Source names have 1 to 128 ASCII letters, digits, hyphens, underscores or periods.
- The server needs at least one ingestion token and one read token to start.
- Index scope tables can name only tokens that exist in the matching token table.
How environment variables combine with the file
| Variable | Effect |
|---|---|
LOGBROOK_INGEST_TOKEN |
Replaces every ingestion token from the file. Its source is LOGBROOK_SOURCE, or default when unset. |
LOGBROOK_ADMIN_TOKEN |
Replaces the admin_tokens list with one token. |
LOGBROOK_READ_TOKEN |
Adds one read token and keeps the others. |
LOGBROOK_READ_SOURCES |
Comma-separated sources for the env read token. Empty grants all sources. |
If the file already defines read tokens, you must also set LOGBROOK_READ_SOURCES when you add LOGBROOK_READ_TOKEN, unless that exact token is already in the file. Otherwise startup fails. With no read tokens in the file, the env read token can read every source.
Send a token
Clients send the token in the Authorization header with the Bearer scheme.
curl -sS "$LOGBROOK_URL/indexes/payments/logs/ingest" \
-H "Authorization: Bearer $LOGBROOK_INGEST_TOKEN" \
-H "Content-Type: application/json" \
-d '[{ "time": 1767225600000, "level": 30, "msg": "hello" }]'A missing or malformed header returns 401 with Bearer token required. An unknown token, or a token of the wrong role, also returns 401. A valid token outside its source or index scope returns 403, and so does index deletion with a read or ingestion token.
The CLI reads the token from --token, then LOGBROOK_TOKEN, then a role-specific variable.
| Command | Variables tried, in order |
|---|---|
logbrook query, logbrook count |
LOGBROOK_READ_TOKEN |
logbrook indexes list, show |
LOGBROOK_ADMIN_TOKEN, LOGBROOK_READ_TOKEN |
logbrook indexes create |
LOGBROOK_ADMIN_TOKEN, LOGBROOK_INGEST_TOKEN |
logbrook indexes delete |
LOGBROOK_ADMIN_TOKEN |
Prefer environment variables over --token, which lands in shell history. See the CLI reference.
Generate strong tokens
Use a cryptographic random source. Thirty-two bytes as hex gives 64 characters:
openssl rand -hex 32Generate a different value for each role and each producer. Store them in a secret manager or an environment file with restricted permissions, not in Git. The repository ignores *.local.toml for this reason.
A configuration parse error reports only the line and column, so it never echoes credentials from the file.
Rotate a token
Tokens don’t expire, and a change takes effect only after a restart. To rotate without locking producers out, run both tokens side by side for a while:
Add the new token
Add a second entry next to the old one in the same table, with the same source or scope. Do this in the TOML file, because
LOGBROOK_INGEST_TOKENreplaces the whole ingestion table.Validate and restart
logbrook --config logbrook.toml check-configRestart the server so it loads both tokens.
Move clients to the new token
Update producers and readers and confirm they authenticate.
Remove the old token
Delete the old entry, validate again and restart. Remove the old token’s entries from the index scope tables too.
Each restart interrupts service briefly. See run in production.