Hardening a production instance
What a client's server and deployment must have before it goes live. SHADE's image is built carefully (below), but a container only covers what runs inside it: the server, the network and the deployment's settings are set up per instance. Go through this list for every new instance, and again after changing its setup. How to set an instance up is Setting up an instance (Coolify); how to test it is Security testing.
What the image already does
apps/api/Dockerfile in the SHADE repository:
- the base image is pinned by its digest, so a release can't change it unseen;
- it runs as the unprivileged
nodeuser, not root; - a slim base with one added system package (CA certificates); compilers and build tools stay in the build stage;
- a health check, and a memory limit for Node;
- the admin is static files with no server code of its own; untrusted modules run in workerd's sandbox;
- modules call out only to the hosts they declare, over https, and never into the containers' own network
(
moduleFetchand the sandbox's egress). A trusted module's code could still call around that: an outbound firewall on the server that blocks the cloud's metadata address (169.254.169.254) adds a second wall; - the SMTP server for email is checked the same way: never an address inside the network, unless
SHADE_SMTP_ALLOW_INTERNAL=trueallows a relay of the instance's own; - a module's outside provider (the payments module's Mollie) is called at its own address unless the operator names
another in
SHADE_PROVIDER_URLS, which only the environment sets: then that module alone may call it, inside the network too.
A pinned image is safe on the day it's built and outdated months later: rebuild and scan it with every release, and update instances when a release fixes something.
The server
- Only ports 80 and 443 reach the server from the internet (a firewall at the host or the provider). SSH is limited to the operator's addresses, or reached through a VPN.
- SSH accepts keys only: no passwords, no root login.
- Automatic security updates for the operating system (
unattended-upgradeson Debian and Ubuntu). - Coolify's own dashboard is not on the open internet, or is behind its two-factor sign-in and an address allow-list. Coolify itself kept up to date.
- The proxy's dashboard and admin API are off or not reachable from outside (Traefik's dashboard, Caddy's admin API on port 2019).
- The Docker socket is never mounted into SHADE's containers.
The containers
Start from the SHADE repository's deploy/compose.yml, which has every one of these: a test fails
when one of them goes, and before a release the image is started with exactly these settings (pnpm deploy:smoke). Set
the same in Coolify's settings when the resources are made one by one:
- No published database port. Postgres and Redis are reached only on the containers' own network.
- Three database roles, none a superuser. SHADE runs every request as
shade_app, which owns nothing and has noBYPASSRLS, so row-level security applies to it. The ownershadealone changes the schema and is held by the admin container only;shade_backupreads everything, read-only, and is held by the worker only. SHADE refuses to start whenDATABASE_URLnames a role that is a superuser, hasBYPASSRLSor owns a table (The database's roles). - Redis with a password and
noeviction:REDIS_URLcarries the password, a full Redis refuses writes instead of evicting a lease, and it keeps nothing on disk (appendonly no,save ""). In the template it is Valkey (BSD-licensed; any server that speaks the Redis protocol works), running as its own user with a read-only filesystem and every capability dropped. - Redis watched like the database. Every rate limit counts in Redis and refuses its requests with 503 while
Redis does not answer, so a Redis outage stops sign-in, forms and modules' limited routes
until it is back (reading content goes on).
/healthis 503 and namesrediswhile Redis is away; alert on it, and on a run of 503s in the error log. - A read-only filesystem for the API container, with writable volumes only where SHADE writes:
the data volume at
/app/data(media inuploads/, with the local storage driver, and the installed module packages inmodule-packages/; thepublicrole, which never stores media, gets atmpfsthere; theworkerrole shares the media and unpacks its packages into atmpfsof its own at/app/packages), and atmpfsfor/tmp. The smoke test signs in and uploads with this setup; anything SHADE fails to write elsewhere is a bug to report. - No extra privileges: drop all Linux capabilities (
cap_drop: [ALL]) and setno-new-privileges. - Memory and CPU limits, so one container can't starve the others.
- Restart policy
unless-stopped, and the health check left on. - The
adminandpublicroles as separate containers when the instance takes visitor traffic, so the admin API is not on the public container (Public role). - A worker container (
SHADE_API_ROLE=worker), with no domain and no published port: it serves only/health. Without one, nothing scheduled runs and the admin says so on every screen. The small profile runs oneallcontainer instead, with the same hardening.
Secrets
-
APP_SECRET, the database and Redis passwords and the storage keys are never in the image or the repository, and are different for every client. The deployment template generatesAPP_SECRET, the backup key and the database and Redis passwords on the first start, into four volumes by who reads them, so the public container holds neither the backup key, nor the owner's or the backup role's password, nor the database's superuser password; the doctor'ssecretscheck says which were generated. A copy ofAPP_SECRETand the backup key is kept apart from the server, and an admin has confirmed it (the doctor'skept-copycheck). One you set in Coolify's environment wins:APP_SECRETlong and random (openssl rand -base64 48), the database and Redis passwords letters and digits only (openssl rand -hex 32), as they go into their addresses as they are. The storage keys are always set. - Payment and email keys are entered in the admin (they are stored encrypted with
APP_SECRET), not in the environment. -
APP_SECRETand the database backups are kept where the client and the operator can reach them for a handover, and nowhere else. - A site on a static host that forwards the account API:
SHADE_PROXY_SECRETis set on the public role and as a secret of the Cloudflare Worker (or as an environment variable of the Netlify site, Functions scope), the same random value of at least 32 characters, and nowhere else (never in the site's repository,netlify.tomlor build). Without it the site works, but sign-in and form limits count all its visitors as one (Hosting the site on a static host).
The edge: TLS and headers
- HTTPS on every domain, with HTTP redirected; certificates renew on their own (the proxy and Let's Encrypt).
- TLS 1.2 or newer only. Check with
testssl.shor SSL Labs. - HSTS on every domain once HTTPS works everywhere.
- The admin's Content Security Policy is SHADE's own (
apps/api/src/http/csp.ts); the proxy doesn't override or weaken it. The site sets its own headers in its Caddy config. - The proxy or CDN in front of the API keeps SHADE's
Cache-Control,Content-Security-PolicyandX-Content-Type-Optionson the API's answers, module routes' included: it never caches an answer markedno-store(user, session and token routes, answers that set a cookie), nor adds a longer cache of its own, and never strips the policy SHADE puts on a module's SVG. - A CAA record naming the certificate authority in use, and no DNS records left pointing at servers that no longer exist (dangling subdomains can be taken over).
Password reset and confirmation emails are how users and team members get into their accounts, so nobody else must be able to send convincing ones in the client's name, nor read them (the email settings take a signed-in admin, never a token):
- SPF and DKIM for the sending domain, matching the email service in use (SMTP or Brevo).
- DMARC, starting with
p=noneto watch reports, thenquarantineorreject. -
SHADE_SMTP_ALLOW_INTERNALleft off unless the mail goes through a relay on the instance's own network. -
SHADE_PROVIDER_URLSempty, unless a module's provider goes through a proxy of your own.
Backups
- The database is backed up daily, encrypted, and stored off the server.
- Uploaded media are backed up too when they are on the server's disk (not on S3).
- A restore has been tried once on a scratch instance, and the steps written down.
Watching
- At least one admin receives SHADE's security alerts, and someone reads them.
- The error log is looked at after every update.
- Coolify's or the provider's disk and uptime alerts go to the operator.
Details
- API security headers: every response from the API app (
/api,/uploads,/health) gets Hono'ssecureHeadersdefaults:Cross-Origin-Resource-Policy: same-origin,Cross-Origin-Opener-Policy: same-origin,Origin-Agent-Cluster,Referrer-Policy: no-referrer,Strict-Transport-Security(180 days, subdomains),X-Content-Type-Options: nosniff,X-DNS-Prefetch-Control: off,X-Download-Options: noopen,X-Frame-Options: SAMEORIGIN,X-Permitted-Cross-Domain-Policies: none,X-XSS-Protection: 0. Files under/uploads/useCross-Origin-Resource-Policy: cross-originso the site's/previewcan load them. API answers also getContent-Security-Policy: default-src 'none'; frame-ancestors 'none'; uploads set their own:default-src 'none'for images and fonts, none for PDFs, and for SVGdefault-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox, which the site's Caddy and its_headerson Cloudflare and Netlify send for/media/*.svgtoo. - The public site's Caddy (
site/Caddyfilefor the static image,site/Caddyfile.runnerfor the runner) sendsX-Content-Type-Options: nosniff,Referrer-Policy: strict-origin-when-cross-origin,X-Frame-Options: SAMEORIGINandStrict-Transport-Security: max-age=31536000; includeSubDomains(a year, subdomains included: once seen, the browser only uses HTTPS for the site's domain and every subdomain), and dropsServer. Serve every subdomain of the site's domain over HTTPS before going live. - Secrets and
.envfiles (APP_SECRET,DATABASE_URL, storage keys, the site's build token are environment variables): in development they live in.envfiles (.env.examplelists every variable without values): SHADE's at the repository root, the site's insite/or SHADE's next to it. In production Coolify passes them to the container and the API reads no.envfile, except the oneSHADE_ENV_FILEnames on a server without Coolify; SHADE refuses to start when other users of the server can read or change that file, or when it sits in a folder SHADE serves. Every repository ignores.envand.env.*(not.env.example): SHADE, the site, the docs, the workspace, the modules, and every moduleshade-module initcreates. The images' build contexts leave out every.envat any depth (SHADE's and the workspace's.dockerignore), and the API's image keeps only its built server. The build token is an Astro server secret: read while building and on the site's Node server, never written into pages, scripts or the server bundle; the admin's built files hold no environment values. The admin's file server and local uploads answer only files inside their own folder however a path is written (../, encoded, double-encoded, backslashes); uploads only media types; the site's Caddy serves only the built pages. An unexpected error answers500 Internal server errorand nothing more, details go to the log. Untrusted modules get no environment and no server files. Secrets entered in the admin (mail and payment keys, modules' secret settings) are encrypted with a key derived fromAPP_SECRET; API tokens are stored only as hashes; the build hook comes back masked. Each is checked by a test.