Skip to content

Security

Kinglet is built for a small, trusted team, not an open multi-tenant service. Most of the security work is deployment hygiene: terminate TLS, trust only your proxy, keep secrets out of logs, use least-privilege accounts and scoped keys, and keep the image and database healthy.

Kinglet uses the client IP for the sign-in rate limit (20 attempts per minute per IP) and the stored session IP.

  • Empty (the default): Kinglet uses the connecting socket’s address. Use this when clients reach Kinglet directly. Behind a proxy, every user then shares the proxy’s address and one rate-limit bucket.
  • Set: Kinglet reads X-Forwarded-For from right to left, skips every address inside the listed ranges, and uses the first address outside them as the client IP. If every address is listed, the request has no client IP and shares one bucket with all such requests.

The list is not checked against the connecting socket. Anyone who can reach Kinglet’s port directly can therefore choose the IP Kinglet records, so:

  • Keep port 3000 reachable only by the proxy, and have the proxy set or append to X-Forwarded-For rather than pass a client-supplied chain through.
  • List the proxy’s own address as a /32. For a Caddy container on a dedicated network, 172.30.0.10/32 is enough.
  • Never list 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16. Those ranges contain your users (LAN, Docker, many VPNs), so Kinglet skips their addresses: a private-range client ends up with no IP, and a forged public address in front of it becomes the recorded client IP.

Example Caddy network (direct Compose):

networks:
kinglet:
ipam:
config:
- subnet: 172.30.0.0/24
services:
caddy:
networks:
kinglet:
ipv4_address: 172.30.0.10
kinglet:
environment:
KINGLET_TRUSTED_PROXIES: 172.30.0.10/32

Dokploy and Coolify put Traefik in front of Kinglet on a network that other apps share. List the proxy container’s address as a /32, not that network: listing the subnet makes Kinglet skip every neighbouring app’s address. Neighbours on that network can also reach port 3000 directly, so only deploy apps you trust alongside Kinglet. Their deploy pages show how to find the address: Dokploy, Coolify.

For your own Traefik or another proxy container, find its address with:

Terminal window
docker ps --format '{{.Names}}' | grep -Ei 'traefik|caddy'
docker inspect <proxy-container> --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}'

A dedicated Docker network CIDR is acceptable only when that network contains nothing but the proxy and Kinglet. A host LAN/VPN range is never a proxy network.

Start with the last proxy directly in front of Kinglet. Add Cloudflare only when you need visitor IP attribution and your proxy preserves the incoming X-Forwarded-For chain.

Setup KINGLET_TRUSTED_PROXIES
Caddy in Docker Caddy container IP /32, e.g. 172.30.0.10/32
Traefik in Docker Traefik container IP /32, or the dedicated proxy network CIDR
nginx on the host, proxying to 127.0.0.1:3000 127.0.0.1/32
nginx in Docker nginx container IP /32, or its dedicated proxy network CIDR
Cloudflare → Caddy Caddy IP /32; add Cloudflare’s current ranges only if Caddy preserves the visitor XFF
Cloudflare → Traefik Traefik IP /32; add Cloudflare’s current ranges only if Traefik preserves the visitor XFF
Cloudflare Tunnel → Caddy/Traefik The cloudflared connector address /32; add Cloudflare ranges only if the visitor XFF survives
Vercel → public HTTPS → Caddy/Traefik The Caddy/Traefik address. Vercel is a client; never add Vercel to this list
No reverse proxy Leave empty; the socket address is used

Cloudflare’s ranges are published at cloudflare.com/ips and change over time. Do not paste a stale copied list. Adding them only helps if the XFF chain still contains the visitor: if your proxy overwrites X-Forwarded-For with the immediate peer, Kinglet sees Cloudflare’s address instead. That still works for rate limiting, but it is not visitor-level attribution. Kinglet reads only X-Forwarded-For, not Cloudflare’s CF-Connecting-IP.

  • Set KINGLET_BASE_URL to the exact public origin, including https://. Session cookies become Secure only when the base URL is HTTPS.
  • Terminate TLS at Caddy, nginx, or your platform proxy. Publish only 80/443 on the proxy and keep Kinglet’s 3000 port internal.
  • The Docker examples bind 127.0.0.1:8080. Drop the 127.0.0.1: prefix only behind TLS; the source build’s docker-compose.yml publishes 8080 on every interface.
  • Scripts should authenticate with a Bearer key. Cookie-authenticated /v1 requests other than GET/HEAD/OPTIONS must send X-Kinglet-Request: 1, and a cross-origin Origin is rejected (CSRF protection).
  • Do not expose Kinglet directly to the internet without TLS. If you use the Caddy sample in deploy/, keep the Kinglet service unpublished and route to it over the Compose network.
  • Kinglet sends X-Content-Type-Options: nosniff, Referrer-Policy: no-referrer, X-Frame-Options: DENY, and a strict Content-Security-Policy on responses, plus Cache-Control: no-store on /v1/* and /api/auth/*.
  • Generate BETTER_AUTH_SECRET with at least 32 random bytes. Set it explicitly with a remote database (required) or when you want sessions to survive container rebuilds without relying on /data/auth-secret.txt. Rotating it signs every session out.
  • Set KINGLET_SECRET_KEY (openssl rand -base64 32). It encrypts every stored notification channel secret and legacy monitor webhook URL with AES-256-GCM. Store a copy apart from /data and backups: a leaked database or snapshot doesn’t reveal channel secrets without it, and a restore needs it. Changing or losing it locks existing channels until their settings are re-entered.
  • Set a strong KINGLET_ADMIN_PASSWORD before the first boot, or read the generated password once and store it in a password manager.
  • Delete /data/admin-password.txt after the first successful sign-in. If the password was printed to shared logs, rotate it.
  • Keep .env files at mode 600, out of Git, and out of container images.
  • Restrict the /data volume to the container user. It holds the database, the auth secret, and the bootstrap password.

Use the smallest role that works:

Role Use it for
admin one or two operators who manage projects, users, and keys
member people who send logs, manage monitors, and manage project keys
viewer people who only read logs and dashboards
  • Remove project members when they leave the team. Project membership is the boundary for members and viewers; admins can see every project.
  • Disable an account before deleting it when you may need to restore access. Disabling blocks sign-in and revokes keys owned by that user; enabling the account does not restore them.
  • A role change deletes the user’s sessions; a demotion (to viewer, or admin to member) also revokes the keys they created. Account deletion removes both. Mutating requests bypass the session cookie cache; read-only requests can use a signed cache for up to 60 seconds. For immediate read revocation, sign the user out or delete the sessions.
  • A password reset revokes the user’s keys and sessions. Changing your own password signs out your other sessions and, unless you untick “also revoke my keys” (revokeApiKeys: false in the API), deletes the API and MCP keys you created. Treat account recovery as a full credential rotation.
  • Create one key per service, not one shared key for everything.
  • Grant only the scopes the service needs: ingest for producers, query for readers. A key never inherits a human role.
  • Store keys in a secret manager or the platform’s secret store. Do not paste them into chat, tickets, URLs, or source code.
  • Rotate a key when a service is replaced, a laptop is lost, or a team member leaves. Rerolling invalidates the old plaintext immediately.
  • The live tail accepts ?key= for clients that cannot send headers. That value can appear in reverse-proxy access logs. Disable or redact query strings in proxy logs, or use the Authorization header where the client supports it.
  • Use View usage in the key menu to review key:<id> events and spot a key that is sending more than expected.

MCP keys (km_...) are project-bound credentials for AI clients, separate from API keys. Their scopes are logs.read, monitors.read, and monitors.write; they never inherit a human role and cannot reach projects, users, keys, settings, backups, or admin routes. Revocation and scope changes apply on the next request.

  • MCP results leave your server for the client’s AI provider. Point the key at a project whose contents are appropriate for that provider.
  • Treat event text as untrusted input (prompt injection).
  • Each MCP key is rate-limited to 60 requests/minute (burst 10, in memory per process), returning 429 when exceeded.
  • Monitor writes need both the monitors.write scope and KINGLET_MCP_ALLOW_MONITOR_WRITES=1 on the server. Enable the variable only when the client requires explicit approval for tool calls.
  • Monitor and channel reads never return webhook URLs; writes accept channel ids only.

See MCP server for setup and details.

  • Treat event content as untrusted. Alert notifications can include event text, and Discord or Slack may render links and mentions. Restrict monitors.write to people you trust, and treat unexpected links in an alert channel as suspicious.
  • Prefer HTTPS webhook URLs and a receiver you control. Do not put secrets in event messages that may be forwarded to a chat channel.
  • Private, loopback, and metadata webhook targets are blocked by default, including after DNS resolution, and redirects are refused. KINGLET_ALLOW_PRIVATE_WEBHOOKS=1 lifts that block. Only admins can set channel URLs, so enable it only if every admin may reach internal hosts, and add egress rules at the container or host level. Self-hosted ntfy and Gotify servers follow the same rule; Telegram, Pushover, Resend, and Plunk channels can only reach their official API hosts.
  • Channel tokens and API keys (Telegram bot tokens, Pushover keys, Resend and Plunk keys, ntfy access tokens) are stored in the channel target and treated like webhook URLs: masked in lists and shown only in the admin edit dialog.
  • The SMTP server for email channels is configured only through KINGLET_SMTP_*; its password is never stored or returned. With a login set, Kinglet refuses to send without TLS unless KINGLET_SMTP_REQUIRE_TLS=0.
  • Notification-channel URLs, including legacy inline monitor URLs, are admin-only secrets. Member monitor responses mask them, members cannot create inline webhook channels, and deleting or rotating a channel removes the legacy copy.
  • Notification text is sanitized before delivery: Discord and Slack escape markdown and wrap sample messages in a sanitized code block (truncated to 900 characters); generic system-event webhooks sanitize text fields, and alert webhooks sanitize the text field while preserving the structured notice fields in JSON. Telegram messages are sent as plain text with no parse mode, and email HTML escapes all event text. Delivery errors are sanitized and shown as notifyError to administrators only; everyone else, including MCP keys, gets null.
  • Use a separate notification channel for production alerts, and review who can edit monitors and channels.
  • Set KINGLET_RETENTION_DAYS for your compliance and disk budget. The default is 14 days.
  • Set KINGLET_MAX_EVENTS_PER_PROJECT, KINGLET_MAX_PROJECT_DB_MB (default 1024 MiB), and KINGLET_MAX_DB_MB so one project cannot fill the shared database. A full database makes ingest fail for every project.
  • Back up with the built-in S3 snapshots, Litestream, or an atomic volume snapshot. A plain file copy of a running database can be inconsistent; stop Kinglet first if you copy files.
  • Test a restore before you need it. The auth secret and admin password live in the same volume.
  • S3 backup credentials and the optional backup passphrase are read from the environment only; they are never stored in the database. Keep them in your platform’s secret store.
  • Restore rejects unsigned or tampered manifests, rejects unencrypted snapshots when KINGLET_BACKUP_PASSPHRASE is set, caps download size, and clears sessions fail-closed. Details are in Backups & archive.

:latest is for a trial, not production. Pin a release tag, or better, a digest:

services:
kinglet:
image: ghcr.io/rushlightlab/kinglet@sha256:<digest>
  • Read the changelog before upgrading. Migrations run automatically on boot and can rewrite tables; back up /data first.
  • Pull and redeploy deliberately. A pinned digest will not change under you.
  • Watch the repository’s security advisories for release notes that affect your deployment.

The shipped image runs as the non-root node user. On a platform or Compose file you control, add:

security_opt:
- no-new-privileges:true
cap_drop:
- ALL

If your platform supports a read-only root filesystem, keep /data writable and mount /tmp as tmpfs. Set CPU, memory, and PID limits so one project cannot starve the host. Do not mount the Docker socket or run the container privileged.

Area Check
TLS KINGLET_BASE_URL is the public HTTPS origin; only the proxy publishes 80/443
Proxy trust KINGLET_TRUSTED_PROXIES names only the proxy address or subnet
Secrets strong BETTER_AUTH_SECRET and admin password; admin-password.txt removed
Accounts admins are few; members and viewers are scoped to projects
Keys one API or MCP key per service or client, least scopes, revoked on offboarding
Webhooks HTTPS receiver; private webhooks enabled only with egress controls
Storage retention and caps set; /data backed up and restore tested
Updates image pinned by tag or digest; changelog read before upgrading
Runtime non-root, cap_drop: ALL, no-new-privileges, resource limits

Please report suspected vulnerabilities privately through the repository’s GitHub Security Advisories. Do not open a public issue with exploit details. Include the version or image digest, the deployment shape (proxy, storage backend, platform), and a minimal reproduction with dummy data.