Self-hosting is by agreement. The container images (
ghcr.io/trustivan/*)
and the source repository are private: they are provided to customers who run
TRUSTIVAN on their own infrastructure. To evaluate TRUSTIVAN, use the hosted
service from the quickstart, or contact
us about self-hosting.
This page is about the second. It runs the real images with the real
strictness on one host. That is a legitimate deployment for a single
organization or a pilot, and an honest staging environment. It is not highly
available: one host failing takes everything with it.
What it runs
The start order is enforced by the file.
postgres must be healthy before
migrate runs. migrate must exit successfully before db-roles runs.
db-roles must exit successfully before api and worker start. A failed
migration therefore stops the deploy instead of leaving an application running
against a schema it does not expect.
Every service is confined the same way: a read-only root filesystem, every
Linux capability dropped, no-new-privileges, and a non-root user (postgres
runs as its image’s postgres user, uid 70, and redis as redis). Each
writable path is a named volume or a small tmpfs the process was observed to
need. The worker, which unpacks untrusted images, is also bounded to a 2 GB
/tmp, 4 GB of memory, 2 CPUs and 512 processes. Every third-party image
is pinned by digest, so a moved tag cannot change what runs.
scripts/ci/check-deployment.sh fails the build on a service that lacks any of
this.
On a stop, the API stops accepting connections and waits at most 20 seconds
for open ones before it closes the database pools and exits. The api service
allows 30 seconds (stop_grace_period) so that wait fits before Docker kills
the process, and the worker allows 45.
Before you start
- A TLS-terminating reverse proxy. Nothing in the stack terminates TLS. The three published ports bind to loopback by default so that the proxy is the only way in.
-
Access to the images. The example file notes that the published packages
are private, so the host needs
docker login ghcr.iowith a token that can read them before Compose can pull. -
A dashboard image built for this stack. The dashboard proxies
/api/*to the backend, and that destination is fixed when the image is built. An image built with the default proxies to its own loopback and every API call fails. Build it with the API’s service name: -
A decision about vulnerability data.
VULN_DB_PROVIDERhas no default here. See Vulnerability database.
Install
1
Create the environment file
${...} references
in the compose file. For anything larger than one host, prefer a secret
manager that injects the same variables.2
Pin the images
3
Set the three database identities
Generate each password with You do not create the last two roles. See
the three roles below.
openssl rand -hex 32. Hex needs no escaping
inside a URL. Use a different one for each.4
Set the secrets
TOKEN_ENCRYPTION_KEY in a secret manager, separately from the
database. A database backup without it restores rows nobody can decrypt.5
Set the origins
DASHBOARD_URL is also the whole CORS allow-list. API_BASE_URL is
optional: it is the callback origin registered with customers’ identity
providers, and single sign-on is unavailable without it. When set it must
be https:// and must not be a loopback address.6
Choose the vulnerability data source
mirror with no repositories is a startup failure. upstream also
requires VULN_DB_ACKNOWLEDGE_UPSTREAM=true.7
Decide who may sign up
invite_only. If the variable is missing from your
file, the compose file passes open. See
Sign-up and sign-in.8
Start the stack
${VAR:?message} form, so an unset
one fails the whole command with a message naming it, before anything
starts.9
Check it
migrate and db-roles should show as exited with status 0. api,
worker and dashboard should be healthy.The three database roles
db-roles creates the two login roles on every deploy, sets their passwords
from the URLs you wrote, and grants them the group roles the migrations
created. It refuses to continue when a URL has no password, when either
application URL names the owner, or when both application URLs name the same
role.
The backend enforces the same separation from its side. Outside development
the API refuses to start as a superuser or a BYPASSRLS role, and the worker
refuses to start without a job-plane role, because on the application role it
would never see a queued scan.
Published ports
postgres and redis publish nothing. Point your reverse proxy at the three
loopback addresses.
The API sees your reverse proxy, and the dashboard’s own /api proxy, as its
network peer. The compose file therefore sets TRUSTED_PROXIES to the private
ranges 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 by default, so the API
believes their X-Forwarded-For. Without that, every client would share one
address and the per-address sign-in limiter would lock everyone out together.
Narrow it only if you move API_BIND off loopback.
What the file fixes for you
These are set in the compose file, not in your environment file:Which variables reach the containers
Compose gives a container only the variables its service names. The--env-file you pass fills in ${...} references in the compose file; it is
not handed to the containers. So the file names every setting the backend
reads, each passed through empty when you have not set it, and the backend
treats an empty value exactly as an unset one. A setting in
Environment variables therefore takes effect when
you write it into your environment file, with no edit to the compose file.
Settings that only the API uses are given to api alone: JWT_SECRET and
JWT_SECRET_PREVIOUS, the session lifetimes, TRUSTED_PROXIES,
STAFF_ALLOWED_CIDRS, the GitHub, GitLab and Google sign-in variables, the
GitHub App, and BILLING_PROVIDER with the STRIPE_ variables. The worker,
which unpacks untrusted images, holds none of them. Everything else (database
pool bounds, key rotation, scanning, feeds, tracing) goes to api, worker
and reencrypt alike.
One exception at this release: SECRETS_REQUIRE_BOUND is read by the
backend and not named in the compose file, so it does not reach a container
from the environment file. Add it with a second Compose file rather than by
editing the shipped one, so an upgrade does not overwrite your change:
Upgrading
Change the image references in the environment file and run the sameup -d
command. migrate and db-roles run again, in order, before the new api
and worker start. See Upgrades for what to check
first and how to roll back.
Related
- Deployment topology: what to run and where, beyond one host.
- Environment variables: every setting.
- Backup and recovery: the backup scripts that read this same environment file.