Docker deployment
Docs for PKI Manager 3.17.0 (released 2026-11-24), from main 4d59c30 (30 commits after the release). Page changed after 3.17.0, not in a release yet.
Source:
docs/operations/deployment.md
Reference for running the published images in production. For a first install, follow Install PKI Manager and log in: it is shorter and every step was run. To build the images from source, see CI and releases.
Overview
Section titled “Overview”PKI Manager uses Docker for containerized deployment with the following components:
- Backend: Fastify + tRPC API server (Node.js 22 Alpine)
- Frontend: React SPA served by Nginx (Alpine)
- KMS: Cosmian Key Management System (official image)
All images are published exclusively to GitHub Container Registry (ghcr.io).
Deploying the SSH Certificate Manager to real servers? See the SSH guides: concept · host & client setup · Ansible role. Hosts need NTP and outbound access to the public trust/KRL endpoints (
/ssh/...,/krl/<caId>.bin).
Prerequisites
Section titled “Prerequisites”- Docker 20.10+ and Docker Compose 2.0+
- (Optional)
.envfile for custom configuration
Production Deployment
Section titled “Production Deployment”Step 1: Prepare Environment
Section titled “Step 1: Prepare Environment”Create a .env file with production values:
# Image: a release tag (tags have no leading "v"). "latest" changes under you.IMAGE_TAG=3.17.0
# Host portsBACKEND_EXTERNAL_PORT=3000FRONTEND_EXTERNAL_PORT=80
# BackendNODE_ENV=production# Written into every certificate you issue: set it before the first CA.CRL_DISTRIBUTION_URL=https://your-domain.com/crl
# KMSKMS_URL=http://kms:9998KMS_API_KEY=your-secure-api-key # OptionalThe browser needs the URL of the API. Set it in docker/config.json, which the Compose file
mounts into the frontend container:
{ "apiUrl": "https://your-domain.com/trpc"}VITE_API_URL in .env is a build argument: it takes effect only when you build the frontend
image yourself. With the published images, use apiUrl in docker/config.json.
Step 2: Pull Images from GHCR
Section titled “Step 2: Pull Images from GHCR”The images are public: no login is needed.
docker compose pullStep 3: Deploy
Section titled “Step 3: Deploy”# Start services from the published imagesdocker compose up -d --no-build --wait
# Verify healthdocker compose psdocker compose logsStep 4: Database Migrations
Section titled “Step 4: Database Migrations”The backend container entrypoint (docker/docker-entrypoint.sh) runs the database
migrations automatically on every start, so no manual step is needed. To run them
by hand (for example to inspect the output):
docker exec pki-backend node /app/backend/dist/db/migrate.jsExpected output:
Running migrations...Migrations folder: /app/backend/dist/db/migrationsMigrations completed successfully!Note: The production container only includes compiled JavaScript. The standard
pnpm db:migratecommand won’t work. Always use the directnodecommand above.
Step 5: Configure Reverse Proxy (Optional)
Section titled “Step 5: Configure Reverse Proxy (Optional)”Example Nginx configuration for production:
server { listen 443 ssl http2; server_name your-domain.com;
ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem;
# Frontend location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
# Backend API location /trpc { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}Client IPs behind a reverse proxy (TRUST_PROXY)
Section titled “Client IPs behind a reverse proxy (TRUST_PROXY)”Behind a proxy, the backend sees the proxy as the client, so every audit row
(audit_log.ip_address) and every per-IP limit (KRL fetches, the anonymous
external-API rejection budget) uses the proxy’s address. Set TRUST_PROXY on
the backend to the addresses of the proxies that forward to it, so it takes
the client IP from X-Forwarded-For:
| Value | Meaning |
|---|---|
unset / false |
Ignore proxy headers (default; correct when clients connect directly) |
10.222.35.0/24,172.18.0.5 |
Trust only these peers (IPs/CIDRs; also loopback, linklocal, uniquelocal). Recommended |
1..10 |
Trust that many hops whatever the peer: only safe if the backend is unreachable except through them |
true (trust anyone) is rejected and so are malformed entries, so the backend
fails at startup instead of silently ignoring a typo. List every proxy hop
that can reach the backend: e.g. the edge proxy’s network and the frontend
nginx, which also forwards /cas/*, /krl/* and /ssh/zones/*. Each proxy
must send X-Forwarded-For $proxy_add_x_forwarded_for (the example above and
docker/nginx.conf do). Never list networks whose other containers are untrusted:
any listed peer can choose the recorded client IP.
Check it: make a request that will be rejected, such as
curl https://your-domain.com/api/v1/external/health without a token, then look
at the newest external.reject row in the audit log. Its IP must be your
public address, not a Docker network address.
Single-Origin Edge Proxy & the /ssh/* Namespace Collision
Section titled “Single-Origin Edge Proxy & the /ssh/* Namespace Collision”Read this if you serve the SPA and the backend on ONE origin (one host/port behind a single reverse proxy or ingress — e.g.
https://pki.example.com), rather than the two-port model (:8080frontend,:3000backend) used by the default compose file.
The collision
Section titled “The collision”/ssh/* is claimed by both layers:
- The frontend SPA owns
/ssh/*as a UI URL namespace — TanStack Router pages such as/ssh/cas,/ssh/hosts,/ssh/krl,/ssh/users,/ssh/principals. - The backend serves public, unauthenticated trust material at the server
ROOT under
/ssh/...(plus/krl/...,/crl/...,/cas/....pem) — the files that hosts, the Ansible role, andkrl-clientfetch.
With a naive single-origin edge (SPA fallback catching everything, or the frontend
container serving / with no backend proxy), GET /ssh/host-ca-keys returns the
SPA’s index.html instead of the CA key material. Symptom observed in production:
/health and /crl/* reach the backend, but /ssh/host-ca-keys returns
<!doctype html>. The two-port compose model hides this because the backend and
frontend are different origins.
The fix (already applied to docker/nginx.conf)
Section titled “The fix (already applied to docker/nginx.conf)”The frontend container’s nginx is now a single-origin edge proxy: it proxies the
specific backend-owned paths to http://backend:3000 and lets everything else
(including the SPA’s own /ssh/cas, /ssh/hosts, … UI routes) fall through to
the SPA. The proxy location blocks are placed before the location / SPA
fallback; nginx evaluates regex locations (in order) ahead of the prefix fallback,
so the specific backend /ssh/... paths win while the SPA keeps the rest. This is
purely a proxy/routing change — the backend routes are unchanged, so external
consumers (Ansible role, krl-client) keep working against the same paths.
Backend-owned paths that MUST be routed to the backend:
| Path pattern | What it serves |
|---|---|
/api/ (prefix) |
REST + OpenAPI/Swagger API |
/trpc (prefix) |
tRPC endpoint (frontend RPC) |
^/crl/ |
Public CRL downloads (/crl/<caId>.crl|.der) |
^/cas/[^/]+\.(pem|crt|cer|der)$ |
Public CA-certificate downloads |
^/krl/ |
Public SSH KRL (/krl/<caId>.bin|.json, /krl/hosts/<id>.bin|.json) |
^/ssh/zones/[^/]+/(host-ca-keys|trusted-user-ca-keys|cert-authority)$ |
Zone-scoped SSH trust anchors |
^/ssh/(host-ca-keys|trusted-user-ca-keys|cert-authority)$ |
SSH trust anchors + known_hosts lines (default zone) |
^/ssh/cas/[^/]+/ca\.pub$ |
A single SSH CA’s public key |
^/ssh/hosts/[^/]+/(cert\.pub|sshd-config)$ |
A host’s cert + sshd drop-in |
Everything not matched above (/, /assets/*, /ssh/cas, /ssh/hosts,
/ssh/krl, /ssh/users, …) is served by the SPA. The container’s local
/health (used by the frontend healthcheck) stays local.
The exact nginx rules (standard proxy_set_header Host/X-Real-IP/X-Forwarded-For/X-Forwarded-Proto
headers included) live in docker/nginx.conf. For a
single-origin deployment, point the SPA at the same origin by setting
"apiUrl": "/trpc" in docker/config.json (so the browser hits the edge, not :3000 directly).
Verify
Section titled “Verify”docker compose -f docker/docker-compose.yml up -d# Backend trust material through the single origin (NOT HTML):curl -s http://localhost:8080/ssh/host-ca-keys | head # -> ssh-...-ca key line(s)curl -s http://localhost:8080/krl/<caId>.bin -o /dev/null -w '%{content_type}\n' # -> application/octet-streamcurl -s http://localhost:8080/crl/<caId>.crl | head -1 # -> -----BEGIN X509 CRL-----# SPA still owns its UI routes (IS HTML):curl -s http://localhost:8080/ssh/cas | head -1 # -> <!doctype html>Using a different edge proxy (Traefik / Caddy / Kubernetes ingress)
Section titled “Using a different edge proxy (Traefik / Caddy / Kubernetes ingress)”If you terminate on something other than this nginx (Traefik, Caddy, HAProxy, an
ingress controller, a cloud LB), you must replicate the same path routing to
the backend, or the /ssh/* trust-material routes will be shadowed by the SPA
again. Route the nine path patterns in the table above to the backend service
(backend:3000) and send everything else to the frontend. Sketches:
Caddy
pki.example.com { @backend { path /api/* /trpc* path /crl/* /krl/* path_regexp cas ^/cas/[^/]+\.(pem|crt|cer|der)$ path /ssh/host-ca-keys /ssh/trusted-user-ca-keys /ssh/cert-authority path_regexp sshzone ^/ssh/zones/[^/]+/(host-ca-keys|trusted-user-ca-keys|cert-authority)$ path_regexp sshpub ^/ssh/cas/[^/]+/ca\.pub$ path_regexp sshhost ^/ssh/hosts/[^/]+/(cert\.pub|sshd-config)$ } reverse_proxy @backend backend:3000 reverse_proxy frontend:8080}Traefik / ingress — create a higher-priority router/rule matching those exact
paths/regexes to the backend service, and a default (lower priority) router to the
frontend. In Kubernetes, use Exact/ImplementationSpecific path types (or a
regex-capable ingress) for the /ssh/..., /krl/, /crl/, /cas/....pem, /api/,
and /trpc routes to the backend Service, with a catch-all / to the frontend.
Environment Configuration
Section titled “Environment Configuration”Required Variables
Section titled “Required Variables”None! The stack runs with sensible defaults. However, you should customize for production.
Available Variables
Section titled “Available Variables”See docker/.env.example for full list. Key variables:
| Variable | Default | Description |
|---|---|---|
IMAGE_TAG |
latest |
Docker image tag to use |
BACKEND_EXTERNAL_PORT |
3000 |
Host port for backend API |
FRONTEND_EXTERNAL_PORT |
8080 |
Host port for frontend |
KMS_EXTERNAL_PORT |
9998 |
Listed in docker/.env.example, but docker/docker-compose.yml does not publish the KMS port |
NODE_ENV |
production |
Node environment |
FRONTEND_URL |
http://localhost:8080 |
Set by the Compose file, but the backend does not read it |
DATABASE_PATH |
/app/backend/data/pki.db |
Database file path (in container) |
KMS_URL |
http://kms:9998 |
KMS service URL |
KMS_API_KEY |
(empty) | Optional KMS authentication |
CRL_DISTRIBUTION_URL |
http://localhost:3000/crl |
Public URL for CRL distribution points |
TRUST_PROXY |
(empty) | Reverse proxies allowed to set the client IP (details) |
ALLOW_CA_KEY_EXPORT |
false |
When true, an admin may download a CA as a PKCS#12/JKS keystore (contains the CA private key); each export is audited as ca.export_private_key. When false, GET /api/v1/cas/{id}/download?format=p12-keystore|jks-keystore returns 403 CA_KEY_EXPORT_DISABLED and the UI hides those formats. A CA key also leaves the KMS, in memory only, to sign CRLs (decision-010). |
VITE_API_URL |
http://localhost:3000/trpc |
Build argument of the frontend image. With the published images, set apiUrl in docker/config.json instead |
The Compose file passes only the variables that it lists. A backend variable that is not in
docker/docker-compose.yml (for example OIDC_DISCOVERY_BASE_URL, or the SSH_* switches of the
SSH API contract) needs an override file:
services: backend: environment: - SSH_ECIES_ENABLED=trueLogin (OIDC)
Section titled “Login (OIDC)”Login is optional and uses OIDC. The backend reads the OIDC_* variables from .env. The web UI
reads its part from docker/config.json. Both are described in one place:
- OIDC login: variables, providers, roles, roles from UserInfo, and how to run without login.
- Keycloak setup: step by step, with screenshots.
- Install and log in: the minimum to start.
Secrets Management
Section titled “Secrets Management”For production, use Docker secrets or environment variable injection:
The backend reads KMS_API_KEY from its environment only (*_FILE variables are
not supported), so inject it from your secret store into the environment:
services: backend: environment: - KMS_API_KEY=${KMS_API_KEY}Published images
Section titled “Published images”Each release publishes these images to GitHub Container Registry (ghcr.io), and nowhere else:
| Image | What it is |
|---|---|
ghcr.io/oriolrius/pki-manager-web/backend |
API server |
ghcr.io/oriolrius/pki-manager-web/frontend |
Web UI (nginx) |
ghcr.io/oriolrius/pki-manager-web/scep |
Optional SCEP gateway |
ghcr.io/oriolrius/pki-manager-issuer |
cert-manager issuer for Kubernetes |
Tags of the backend and frontend images:
latest- Latest main branch build1.0.0,1.0,1- Semantic version tags (fromv1.0.0tags, without thev)main- Latest build of a branchsha-abc1234- Commit SHA (short)pr-123- Pull request builds
Troubleshooting
Section titled “Troubleshooting”Image Pull Failures
Section titled “Image Pull Failures”Problem: Cannot pull from ghcr.io
Solution:
# Create personal access token with packages:read scope# Then login:echo $GITHUB_TOKEN | docker login ghcr.io -u YOUR_USERNAME --password-stdinService Health Issues
Section titled “Service Health Issues”Check service health:
docker compose psdocker inspect pki-backend --format='{{.State.Health.Status}}'View detailed logs:
docker compose logs backenddocker compose logs frontenddocker compose logs kmsDatabase Issues
Section titled “Database Issues”Problem: Database locked or corrupted
Solution:
# Stop servicesdocker compose down
# Remove the bind-mounted data directory (⚠️ deletes data)rm -rf ../pki
# Restartdocker compose up -dKMS Connection Issues
Section titled “KMS Connection Issues”Problem: Backend cannot connect to KMS
Check network:
docker compose exec backend ping kmsdocker compose exec backend wget -qO- http://kms:9998/healthVerify KMS is healthy:
docker compose ps kmsPort Conflicts
Section titled “Port Conflicts”Problem: Port already in use
Solution: Change ports in .env:
BACKEND_EXTERNAL_PORT=3001FRONTEND_EXTERNAL_PORT=8081Production checklist
Section titled “Production checklist”- Check the migrations ran (the backend entrypoint runs them):
docker compose logs backend - Set
NODE_ENV=production - Set
CRL_DISTRIBUTION_URLto a URL that clients can reach, before the first CA - Set
apiUrlindocker/config.jsonto the public API URL - Set strong
KMS_API_KEY - Configure OIDC authentication (see OIDC login)
- Use HTTPS with reverse proxy
- Configure firewall rules
- Set up backup strategy for volumes
- Enable Docker restart policies (already configured)
- Monitor resource limits
- Review security scan results
Resource limits
Section titled “Resource limits”Not set in docker/docker-compose.yml; add them in an override file if needed:
services: backend: deploy: resources: limits: cpus: '2' memory: 2G reservations: cpus: '0.5' memory: 512MOptional SCEP gateway (separate deployment)
Section titled “Optional SCEP gateway (separate deployment)”The SCEP gateway is a separate device-facing service. Deploy
the integration foundation (migration 0010) first; the gateway needs its integration token and external enrollment-state
endpoints. It adds no second backend. Use scep/compose.yml for an existing
installation or the docker/docker-compose.scep.yml overlay for the full stack.
Upgrades
Section titled “Upgrades”- Read the release notes before each upgrade. A release that needs a manual step says so.
- The backend applies the database migrations when it starts. Make a backup first.
- Runbooks for the upgrades that need care: migration 0009 (SSH zones), migration 0010 (integrations) and the KMS upgrade below.
KMS upgrade: backup before recreating the container
Section titled “KMS upgrade: backup before recreating the container”Do not pull/recreate the KMS before locating and backing up its database.
The historical /root/cosmian-kms mount may not contain the actual SQLite files.
The 5.12 container may have stored them only in its writable layer. Recover them
from that still-existing container; a new empty volume does not recover CA keys.
-
Stop gateways/controllers and backend writers. Record the deployed KMS image digest, container name, complete configuration, and mounts. Read the startup log’s actual
main_db_paramsSQLite path. Depending on image/configuration, paths can be/cosmian-kms/sqlite-data,/var/lib/cosmian-kms/sqlite-data, or another configured path. Do not assume the historical mount was effective. -
Stop the KMS without removing its container. Make a protected, offline copy of the entire database directory, including WAL/SHM and all database files:
Terminal window # Substitute the real container name and data path found above.set -eukms_old_container=pki-kmskms_old_data_path=/actual/path/from/kms-startup-logkms_backup_dir=/secure/backups/kms-before-524test ! -e "$kms_backup_dir"mkdir -m 700 "$kms_backup_dir"docker stop "$kms_old_container"docker cp "$kms_old_container:$kms_old_data_path/." "$kms_backup_dir/"Keep the old container and original data untouched until the upgrade passes. Verify the backup contains the existing DB, not an empty directory. Retain the matching PKI backend database backup as well.
-
Copy the backup into a new staging data directory/volume, preserving file ownership and permissions. Test 5.28 against that copy first. Do not point it at the only copy of your 5.12 DB. The full-stack Compose now maps
../kms/datato/cosmian-kms/sqlite-data, mounts../kms/kms.tomlat/etc/cosmian/kms.toml, and setsCOSMIAN_KMS_CONFto that file, matching the configuration-file approach ofkms/docker-compose.yml. For another data volume, adjust only the source side of the mount. -
kms.tomluses the 5.28[db] database_type/sqlite_pathfields with absolute paths,[http], and[workspace]. The old[database] type/pathfields are ignored by the tested image. In config-file mode the TOML takes precedence over server/database environment settings; edit the TOML for another port. -
Confirm the new startup log names the mounted directory, verify existing CA certificate retrieval and issuance, and check RA Activate/Sign/Decrypt before resuming writers. Test that data survives container recreation against the staging volume. Live Intune/device acceptance remains separate.
-
If checks fail, stop the new KMS and return to the recorded old image and untouched old data, not the staging copy. Coordinate backend rollback with its pre-upgrade DB backup. Never delete the old CA keys as a repair step.
Backup and Restore
Section titled “Backup and Restore”All state is in two folders next to docker/:
| Folder | Content |
|---|---|
pki/ |
The SQLite database: CAs, certificates, audit log, and the ids of the KMS keys |
kms/data/ |
The KMS database: the private keys |
Back up both together. The database holds the ids of keys that exist only in the KMS, so one folder without the other is not a complete backup.
Backup
Section titled “Backup”Stop the stack first. The database uses write-ahead logging (WAL): a copy of pki.db taken
while the backend runs can be incomplete.
cd dockerdocker compose stop# use sudo when your user cannot read the folders (pki/ belongs to uid 1001)sudo tar czf pki-backup-$(date +%Y%m%d).tar.gz -C .. pki kms/datadocker compose startThe archive contains the CA private keys. Keep it as safe as the KMS itself.
Restore
Section titled “Restore”Restore both folders from the same archive, with the stack stopped:
cd dockerdocker compose down# keep the current folders until the restore is checkedsudo mv ../pki ../pki.before-restore && sudo mv ../kms/data ../kms/data.before-restoresudo tar xzf pki-backup-YYYYMMDD.tar.gz -C ..docker compose up -d --no-build --waitMonitoring
Section titled “Monitoring”Health Checks
Section titled “Health Checks”The backend and frontend containers have health checks. The KMS container has none in this Compose file.
# Check overall healthdocker compose ps
# Test endpointscurl http://localhost:3000/health # Backendcurl http://localhost:8080/health # Frontenddocker compose exec backend wget -qO- http://kms:9998/health # KMS (not published to the host)# Follow all logsdocker compose logs -f
# Follow specific servicedocker compose logs -f backend
# Last 100 linesdocker compose logs --tail=100
# Export logsdocker compose logs > logs-$(date +%Y%m%d).txtSupport
Section titled “Support”PKI Manager is a personal project. There is no commercial support and no guaranteed response time: see About this project.
- Problems and questions: GitHub Issues.
- What changed in each version: release notes.
PKI Manager is a personal project of Oriol Rius, built for his own use. It is not a commercial product. About this project