Skip to content
项目

heyvaldemar/outline-keycloak-traefik-letsencrypt-docker-compose

在 GitHub 查看

关于

Outline with Keycloak and Let's Encrypt Using Docker Compose

系统与基础设施

这些数字如何统计

可以做什么

  • Outline, the release pinned in the compose file's x-images block, which the daily freshness check keeps current: documents, collections, search, real-time collaboration.
  • Keycloak, pinned the same way, as the OIDC provider: users, groups, MFA, federation if you need it.
  • Garage S3-compatible storage for uploads. No console: mc or any S3 client is how you look inside the bucket.
  • Two PostgreSQL 16 instances (Keycloak and Outline isolated) and Redis 7.4.

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Outline + Keycloak + Traefik + Let's Encrypt on Docker Compose

Deployment Verification OpenSSF Best Practices License: MIT

Contents

This repository deploys Outline (team wiki) with Keycloak as its OIDC identity provider, Garage for file storage, PostgreSQL ×2 and Redis, all behind Traefik with automatic Let's Encrypt TLS: three compose files deployed in order, with scheduled backups and restore scripts. The full self-hosted knowledge-base experience with real SSO at https://your-domain.

📙 Full narrative installation guide on the blog: heyvaldemar.com/install-outline-and-keycloak-using-docker-compose/.

Why this stack?

Need This stack Outline's own compose Manual assembly
Real SSO out of the box ✅ Keycloak OIDC ❌ bring your own IdP Hours of wiring
TLS via Let's Encrypt, auto-renewed ✅ Traefik ACME ❌ Manual certbot
S3-compatible file storage included ✅ Garage ❌ external S3 Separate setup
Scheduled backups (2 DBs + files) + restore scripts ✅ ❌ Manual cron
All images pinned by sha256 digest ✅ 7 pins ❌ floating Rare
Weekly pin-freshness check in CI ✅ ❌ Rare
CI-verified deployment on every push ✅ 3 stacks booted ❌ Rare

Nine services across three compose files, deployed in strict order. Heavier than a single-app template. This is a complete platform.

Prerequisites

  • A Linux server with a public IP and ~4 GB free RAM for the full stack.
  • Docker Engine 24+ and Docker Compose 2.20+.
  • A domain you control, with four A records pointing at your server's public IP: Outline, Keycloak, the S3 endpoint, and the Traefik dashboard.
  • Ports 80 and 443 open on the server's firewall.

Getting started

# 1. Clone
git clone https://github.com/heyvaldemar/outline-keycloak-traefik-letsencrypt-docker-compose
cd outline-keycloak-traefik-letsencrypt-docker-compose

# 2. Create the three Docker networks the stacks expect
docker network create traefik-network
docker network create keycloak-network
docker network create outline-network

# 3. Copy the environment template and fill in required values
cp .env.example .env
$EDITOR .env
# ^ See .env.example, hostnames, passwords, Outline secrets, and the
#   OIDC endpoints (the client secret arrives in the realm step below).

# 4. Deploy in order
docker compose -f 01-traefik-outline-letsencrypt-docker-compose.yml -p outline up -d
docker compose -f 02-keycloak-outline-docker-compose.yml -p outline up -d
docker compose -f 03-outline-garage-redis-docker-compose.yml -p outline up -d

Keycloak, Garage, and Outline come up with fresh Let's Encrypt certificates. Outline's login page appears immediately; signing in works after the realm step below.

Configuring the Keycloak realm for Outline

  1. Log in to https://${KEYCLOAK_HOSTNAME} with KEYCLOAK_ADMIN_USERNAME / KEYCLOAK_ADMIN_PASSWORD.
  2. Create a realm named outline.
  3. In the realm, create a client outline: client type OpenID Connect, client authentication ON, valid redirect URI https://${OUTLINE_HOSTNAME}/auth/oidc.callback.
  4. Copy the client secret (client → Credentials) into OUTLINE_OIDC_CLIENT_SECRET in .env.
  5. Create your users in the realm (email required: Outline maps accounts by the email claim).
  6. Recreate Outline: docker compose -f 03-outline-garage-redis-docker-compose.yml -p outline up -d --force-recreate.

Sign in on Outline via the Keycloak button. First user in becomes the workspace admin.

What success looks like

# All nine services healthy / up:
docker ps --filter name=outline

# Keycloak health:
docker inspect -f '{{.State.Health.Status}}' "$(docker ps -qf name=keycloak | head -1)"

# Storage through Traefik — an unsigned request is refused, which is the
# right answer and proves the route and the certificate:
curl -sk -o /dev/null -w "%{http_code}\n" "https://${OUTLINE_S3_HOSTNAME}/data"

# Outline front page:
curl -fsSL "https://${OUTLINE_HOSTNAME}/" -o /dev/null -w "%{http_code}\n"

Common first-deploy issues

  • Cert issuance fails. One of the five DNS records hasn't propagated, or port 80 isn't reachable.
  • docker compose up fails with set in .env. A required variable is empty; the error names it.
  • Networks not found. Step 2 was skipped: all three networks are required.
  • OIDC error on login. Realm/client mismatch: verify the redirect URI, the client secret, and that the three OUTLINE_OIDC_*_URI values use your Keycloak hostname and the outline realm.

Features

  • Outline, the release pinned in the compose file's x-images block, which the daily freshness check keeps current: documents, collections, search, real-time collaboration.
  • Keycloak, pinned the same way, as the OIDC provider: users, groups, MFA, federation if you need it.
  • Garage S3-compatible storage for uploads. No console: mc or any S3 client is how you look inside the bucket.
  • Two PostgreSQL 16 instances (Keycloak and Outline isolated) and Redis 7.4.
  • Traefik v3 with automatic HTTPS for all five hostnames.
  • Scheduled backups: both databases (pg_dump | gzip) and Outline's attachments (Garage's data and metadata directories, tar.gz), with retention pruning and three restore scripts that CI runs.
  • Credentials required at deploy time: compose fails fast if .env is incomplete.

Supply chain trust

This repository is a deployment template. Seven images across three compose files, each pinned to tag@sha256:<digest> as interpolation defaults in that file's x-images block: git pull alone delivers the version combination this repository has tested; an *_IMAGE_TAG variable in .env overrides deliberately.

Two override levels exist per image. <PREFIX>_IMAGE_VERSION in .env swaps only the version of that image (Compose then pulls the tag, without a digest) and leaves every other pin as tested; <PREFIX>_IMAGE_TAG replaces the whole reference, digest included. The variable names are listed in .env.example. Nested defaults need Docker Compose v2.5 or newer (2022); v2.0 to v2.4 leave the inner ${...} unexpanded and docker compose up fails with an invalid reference instead of deploying something unexpected.

The daily check-pin-freshness CI job re-resolves all seven pins against their registries and compares the pinned Keycloak, Outline, and Traefik versions against the latest upstream releases. CI runs on every push, pull request, and every day at 06:00 UTC. GitHub Actions are pinned by commit SHA; Dependabot keeps those fresh.

Verify what you deploy

Every release from v2.1.0 on carries three files made on GitHub's runner with a short-lived identity and no stored key: outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.tar.gz, a git archive of exactly the tree the tag points at; outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.tar.gz.sigstore.json, a keyless Sigstore signature over it; and outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.intoto.jsonl, SLSA build provenance from the SLSA generator. To check them with nothing from this repository trusted:

cosign verify-blob outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.tar.gz \
  --bundle outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.tar.gz.sigstore.json \
  --certificate-identity https://github.com/heyvaldemar/outline-keycloak-traefik-letsencrypt-docker-compose/.github/workflows/release-assets.yml@refs/tags/<tag> \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

slsa-verifier verify-artifact outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.tar.gz \
  --provenance-path outline-keycloak-traefik-letsencrypt-docker-compose-<tag>.intoto.jsonl \
  --source-uri github.com/heyvaldemar/outline-keycloak-traefik-letsencrypt-docker-compose \
  --source-tag <tag>

The identity is exact: this repository's release-assets.yml, on the tag you deploy. A signature from any other workflow, or from this one on another ref, fails the check. A release published after 24 September 2026 is signed by the run that published it, so the commands above take it as they are. The five releases before that date were signed by a run started by hand on main: for those, end the identity in @refs/heads/main and give slsa-verifier --source-branch main instead of --source-tag <tag>. The archive is still the tag's tree. The workflow that makes them is release-assets.yml.

Production checklist

  • Strong secrets everywhere: six generated passwords/secrets in .env; regenerate the Traefik dashboard hash per deployment.
  • Complete the realm step and disable Keycloak's bootstrap admin after creating named admins.
  • Point the S3 hostname at this server. Presigned URLs are signed over it, so it has to be the address browsers use.
  • Host-mount the backup volumes for disaster recovery.
  • Verify Let's Encrypt certs for all five hostnames in the Traefik logs.
  • Back up before upgrades: Keycloak and Outline both migrate schemas forward only.
  • Know the restore procedure. Three scripts: Keycloak DB, Outline DB, Outline attachments.

Upgrading from 1.x: the storage changed

v2.0.0 replaces MinIO with Garage, and your existing attachments do not move by themselves. They are in the minio-data volume, which this stack no longer starts anything against.

MinIO's community server was archived on 25 April 2026: read-only repository, no further releases, and the last published container image is RELEASE.2025-09-07. Keeping a team's documents behind a storage server that will never be patched again is not a trade-off, it is a deadline. Garage is a single binary built for this shape of deployment, and every S3 operation Outline performs was exercised against it before the swap — tests/s3-contract.py is that check, and CI runs it on every build.

What you give up is the MinIO console. There is no web interface for Garage; mc or any S3 client is how you look inside a bucket now.

# 1. Update and start. Garage comes up empty; nothing is lost.
./update.sh --allow-major
# 2. See what would move, without moving it.
./outline-minio-to-garage.sh --dry-run
# 3. Move it.
./outline-minio-to-garage.sh

The migration starts a throwaway MinIO against the old volume, copies every object through the S3 API on both sides, and then has rclone compare the two. It writes nothing to the old volume and deletes nothing from it, so it is safe to re-run and safe to abandon half way. Expect rclone to report that some hashes could not be checked — MinIO and Garage compute ETags differently, so it falls back to comparing sizes. The line that matters is 0 differences found.

Keep the old volume until you have opened a few documents with attachments and watched the images load. Then docker volume rm <project>_minio-data.

Do it before anyone uploads anything new: the copy is one-way, so an attachment added to Garage in the meantime is fine, but one added to MinIO after the migration would be left behind.

CI proves this path rather than describing it. Every build creates the old volume, fills it through a real MinIO, runs the shipped script, and reads the objects back out of Garage.

Backups

Two backup sidecars run dump → prune → sleep loops: one for the Keycloak database, one for the Outline database and its attachments. All knobs configured via .env with compose-level defaults (30-minute warm-up, 24-hour interval, 7-day retention).

Each cycle logs Database backup OK: <file> (<bytes> bytes) or Database backup FAILED (the same for the data archive where there is one). A failed dump is kept as <file>.failed for diagnosis and never overwrites a good backup. Grep the log for FAILED from your monitoring.

Restore with the interactive scripts (chmod +x *.sh once): ./keycloak-restore-database.sh, ./outline-restore-database.sh, ./outline-restore-application-data.sh. Each lists the backups and asks, or takes a file name as its argument, and reads every path and credential from the running backups container.

Attachments are restored from Garage's own snapshot. The archive is taken while Garage runs, so the live db.sqlite in it can be caught mid-write. Garage writes a consistent copy of it every hour (metadata_auto_snapshot_interval in garage/garage.toml), and the restore script puts the newest one in the archive back, which is Garage's documented recovery. The price is the window: an attachment uploaded in the hour between the last snapshot and the backup comes back without its metadata. Shorten the interval if that hour matters to you.

Archives from before 2.1.0 do not hold your attachments. Until 2.1.0 the backup loop archived the minio-data volume, which nothing has written to since Garage replaced MinIO in 2.0.0. Those archives are named outline-minio-application-data-backup-*, the restore script does not offer them, and once your migration is verified they can be deleted. Take a fresh backup after upgrading: until the first 2.1.0 cycle runs, the attachments are in no backup.

Unattended updates

Releases are the update channel: a tag is cut only after CI has built the pinned images, booted the full stack, and passed the smoke tests. update.sh moves a deployment to the newest tag and nothing else:

./update.sh --dry-run   # show what would be applied
./update.sh             # update within the current major and redeploy

Put it on a timer for hands-off minor/patch updates:

# crontab -e
17 5 * * *  /opt/outline-keycloak-traefik-letsencrypt-docker-compose/update.sh >> /var/log/outline-keycloak-update.log 2>&1

The script refuses to cross a MAJOR template version on its own: majors are breaking by definition and their release notes exist to be read. After reading them, ./update.sh --allow-major performs the jump. It also refuses to touch a checkout with local modifications: your customization belongs in .env, which updates never overwrite.

This is deliberately a host-side script and not a container in the stack: an in-stack updater needs the Docker socket (root on the host) and turns "someone pushed to a repo" into "someone deployed to your machine" with no operator in the loop. A cron job under your own user updates only to tagged, CI-verified states and leaves the trust boundary where it was.

Resource limits

Every service carries memory and CPU limits plus reservations as compose-level defaults, the same values CI boots the stack under. Override any of them in .env (the knobs and their defaults are listed in .env.example, e.g. TRAEFIK_MEMORY_LIMIT=512m) and the override survives every git pull. If a service is OOM-killed under real load, docker inspect <container> --format '{{.State.OOMKilled}}' says so; raise its _MEMORY_LIMIT and recreate.

Container hardening

Every service runs with security_opt: no-new-privileges:true, so a process cannot gain privileges through setuid binaries even if it escapes its initial capability set. Infrastructure containers (the reverse proxy, databases, caches, backups) run with cap_drop: [ALL] and add back only what their entrypoints need: NET_BIND_SERVICE for Traefik to bind :80/:443, CHOWN/SETUID/SETGID (and friends) for database images to own their data directory and drop to their service user. Application containers keep the default capability set on purpose: upstream images assume it, and a wrong guess there is a boot loop in production rather than a hardening win. CI boots the stack under exactly these settings on every push, so what ships is what was tested.

Testing

The Deployment Verification workflow runs on every push, pull request, and every day at 06:00 UTC:

  1. Lint: shellcheck on all three restore scripts, actionlint on the workflow.
  2. Trivy scans of six unique pinned images (CRITICAL/HIGH, SARIF to the Security tab).
  3. Pin freshness (daily/manual): digest drift across all seven pins plus release-lag checks for Keycloak, Outline, and Traefik.
  4. Deploy-and-test: boots all three stacks in order with ephemeral credentials and requires: Keycloak healthy, the S3 contract Outline depends on proven through Traefik, the MinIO migration proven on real objects, Outline liveness through Traefik, and the Outline login page through Traefik.

A green run is the authoritative proof that the template deploys end-to-end and that its backups restore: tests/e2e-backup-restore.sh runs all three shipped restore scripts. For attachments it stores an object through S3, takes a backup, stores a second object, restores, and requires the first to read back and the second to be gone.

Security notes

  • Credentials are read from .env at deploy time; .env is gitignored and compose fails fast on missing required variables.
  • Pre-rotation advisory. Releases before v1.0.0 (2026-08-31) shipped a tracked .env with generated-looking passwords for Keycloak, Outline, and the object storage of the day (MinIO, until v2.0.0). Rotate all of them if your deployment reused them.
  • Databases and Redis listen only on internal networks.
  • Upstream image digests are pinned; the daily freshness job flags drift loudly.

About the maintainer

Maintained by Vladimir Mikhalev · Docker Captain · CNCF Ambassador · IBM Champion · AWS Community Builder

YouTube · Blog · LinkedIn

探索相关项目

加载中…