Skip to content

About

The container and stack plane of a three-plane n8n reliability reference: hardened Compose topology, TLS termination, file-based secrets, capability drops, task-runner isolation. Workflow and host planes link from the README.

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

n8n-hardened-reference

Container and stack plane. The reference n8n deployment: network boundaries, TLS termination, file-based secrets, least-privilege database roles, dropped Linux capabilities, task-runner isolation, and images pinned to digests.

One service is reachable from outside. Count them yourself, here or in your own stack:

grep -c "ports:" docker-compose.yml

Every default has its reasoning written next to it in SECURITY.md, and the workflow and host planes link from the table below.

I work on production n8n infrastructure for teams who need their instance treated like a real system, not a docker-compose tutorial. This repo is the reference deployment I bring to that work: security-hardened, legible, and one command to stand up.

Status: hardened reference and template. Read the threat model and SECURITY.md, then adapt it to your host and your workflows. Do not run it blind.

The three planes

Self-hosting n8n means securing three different things, and they are not the same job. Most material treats them as one. This repository covers one of them, and says plainly which.

Plane What it covers Where it lives
Workflow The automations themselves: authenticated ingress, idempotency, bounded retries, dead-lettering, model-output validation, liveness n8n-workflow-hardening
Stack and container ← you are here Compose topology, reverse proxy and TLS termination, queue mode, secret delivery, capability drops, database privileges this repository
Host and OS CIS Ubuntu 24.04 Level 1, Server profile: SSH policy, kernel and sysctl parameters, host firewall, auditd, patch posture vps-hardening-reference — scope and status published, assertion suite in development

They compose without overlapping, and each is incomplete on its own. Hardened workflows on an unhardened host leave correct logic behind an open door. A locked-down host running unhardened workflows silently drops orders. A hardened stack on an unhardened host is still an unhardened host.

Scope and roadmap

What this repo covers today: the container and stack plane. The n8n services, their network boundaries, TLS termination, secret handling, database privileges, capability drops and task-runner isolation — everything inside the Compose file and the reverse proxy in front of it. Every claim in the threat model below is about that plane, and is readable in the shipped configuration.

What it does not cover: the host and OS plane. SSH policy, kernel and sysctl parameters, host firewall, package and patch posture, auditd, filesystem mount options, unattended upgrades. A hardened stack on an unhardened host is still an unhardened host. This repo makes no claim about the machine underneath it, and you should not read one into it.

What is being built, and where. A portable host-hardening assertion suite — CIS Level 1 Server for Ubuntu 24.04, with every exception publicly justified — that runs standalone against any fresh host, not only this fixture. It belongs to the host and OS plane, so it lives in a separate repository, vps-hardening-reference, rather than in this one. That repository carries its scope and status today — the suite is still in development and no assertions have shipped there yet. When it ships it will carry executable assertions and a red/green baseline runner, so the posture you end up relying on is one you measured, not one I described.

Why the split is what it is. The assertions will be public; the automation that remediates what they find will not. The suite tells you, precisely and in your own environment, what is wrong. Fixing it at scale — the roles, the client tailoring, the migration runbooks — is the engagement. That is a stated position, not an omission: where the value lives in the work rather than the artifact, I publish the artifact generously. Detection is not remediation.

How I approach a migration

Standing up a hardened stack is one skill. Moving a client's live automations onto it without breaking anything is a different one — and it's the part that actually matters to a business depending on those workflows.

That work is an engagement, not a script in this repo. None of the migration tooling described below ships here. What I hold to:

  • Inventory and node-equivalence first. Every existing workflow, trigger and credential is mapped before anything is touched.
  • Parallel run, never a cold cutover. The new stack runs alongside the existing automation and is validated against real inputs, with production side effects duplicated or disabled.
  • Ordered credential repoint. Integrations move one at a time, each verified, with the previous instance kept warm.
  • Rollback as a repoint, not a rebuild. The old instance stays warm until the new one has earned the traffic.

The repo gives you the target stack. The migration is the service.

Why the hardening matters

Self-hosting n8n places an automation engine — holding credentials to everything it touches — directly on the public internet. Many community compose files expose the editor on port 5678, run every service as root on one flat network, and skip the environment flags that actually change the security posture. This repo takes the opposite default: a small, legible stack where the hardened choice is the built-in one, and the reasoning is written down next to it.

Threat model

What an internet-facing n8n exposes, and how this deployment answers each item.

Exposure Mitigation
Editor and API reachable on the public internet Only Caddy publishes ports 80 and 443. n8n, PostgreSQL and Redis are reachable only on internal Docker networks.
Missing or self-signed TLS Caddy issues and renews Let's Encrypt certificates automatically, with HSTS and modern security headers.
Arbitrary command or code execution through nodes The executeCommand and ssh nodes are excluded. Code-node execution is isolated in dedicated task-runner containers (external-mode overlay).
Container breakout or privilege escalation Every service runs with cap_drop: ALL plus a minimal capability set, no-new-privileges, and a read-only root filesystem where the image allows it.
Database compromise blast radius n8n connects as a non-root PostgreSQL user, never the superuser.
Secret leakage The encryption key and both database passwords are Docker file-secrets, never baked into the image or the environment. .env and secrets/ are gitignored.
Credential theft via node file or env access Environment access from nodes is blocked; node file access is restricted to a dedicated sandbox directory.
Disk exhaustion from logs or execution history Bounded json-file logging and automatic execution-data pruning.
Lost encryption key means lost credentials Key handling and backup are called out explicitly, in the deploy flow and in SECURITY.md.

Full list: hardening-checklist.md. Rationale: SECURITY.md.

Architecture

                       Internet
                          |
                    :80 / :443   (the only published ports)
                          |
                  +---------------+
                  |     Caddy     |   automatic TLS, HSTS, security headers
                  +---------------+
                          |  proxy network
                  +---------------+
                  |   n8n (main)  |   UI / API / webhooks, task broker
                  +---------------+
                          |  backend network (internal only)
        +-----------------+----------+-------------------+
        |                 |          |                   |
  +-----------+   +--------------+   +--------+   (external-runners overlay)
  | PostgreSQL|   |    Redis     |   |  n8n   |   +---------------------+
  |  (data)   |   | (Bull queue) |   | worker |   | task-runner sidecar |
  +-----------+   +--------------+   +--------+   | JS / Python, per     |
                                                  | broker, isolated     |
                                                  +---------------------+

Queue mode splits the UI and webhook process (main) from execution (worker), coordinated through Redis. In the external-runners overlay, user Code-node execution runs in separate n8nio/runners sidecars, one per broker, isolated from n8n itself.

Quick start

  1. Point a DNS A record at the server. Ports 80 and 443 must be reachable for certificate issuance.
  2. Copy the environment file and set your values:
    cp .env.example .env
    # set N8N_HOST, ACME_EMAIL, REDIS_PASSWORD
    # (and N8N_RUNNERS_AUTH_TOKEN if you use the runners overlay)
  3. Deploy:
    make deploy            # base stack (internal task runners)
    # or
    make deploy-runners    # adds external task-runner isolation (recommended for production)
  4. Open https://<N8N_HOST> and create the owner account.

make deploy runs make init-secrets for you, which generates the encryption key and database passwords into secrets/. Back up secrets/n8n_encryption_key.txt immediately and keep it somewhere safe. If it is lost, every stored credential becomes undecryptable.

Every image is pinned to a sha256 digest in the shipped compose files, so a moved tag can't silently change what you deploy. Re-run make pin-digests if you bump a version and want to re-pin.

Hardening

The security posture is documented, not implied.

  • hardening-checklist.md: the official n8n production checklist, mapped to exactly where each item is applied in this repo.
  • SECURITY.md: the reasoning behind the container, network, secret and task-runner choices, and how to report an issue.

Prove it yourself, no host or DNS needed:

make mutation-check   # five deliberate regressions; verify must catch every one
make boot-caddy      # boots the full stack, Caddy signing with its internal CA, and serves n8n over HTTPS

Both run in CI on every push (the mutation check also carries a positive control: the clean stack stays green).

Backup and restore

make backup                          # pg_dump (custom format) + n8n data, with retention
make restore SRC=backups/<timestamp> # stop, pg_restore, start

Restores require the same encryption key that was in place when the backup was taken. The key is intentionally not bundled into the backup archives. Store it separately and securely.

What this is, and is not

  • It is a hardened, legible starting point that I work from, and that you're welcome to adapt to your own host and workflows.
  • It is not a managed service, a one-click appliance, or a reason to skip reading SECURITY.md.

License

MIT. See LICENSE.


What this proves

Count the published ports and you get one. The threat model pairs each risk with its control. NIST-800-190-APPLICABILITY.md maps those controls to the container-security tiers of NIST SP 800-190, and it names the host tier as not yet covered rather than implying otherwise.

CI runs make verify over the rendered compose JSON in both configurations, boots the full stack with Caddy on an internally-signed certificate and serves n8n over HTTPS, and re-applies five deliberate regressions that verify must catch. Every claim above is one command away from being re-run, on your machine or in the CI log.

This is the stack I deploy for clients who self-host n8n, and the baseline I check an existing instance against during a diagnosis. When the stack is down, every workflow it carries stops, including any that move inbound leads.

Who built this

Jarrod Wright, working as The Certainty Engineer. I step in when a production n8n workflow or AI agent breaks, working across three planes: the workflows, the container stack they run on, and the host underneath. These repositories are the reference implementations I work from.

Every engagement follows one sequence. Triage is free: what broke, and whether I'm the right person.

Then comes a paid, written diagnosis, where every root cause is backed by evidence and the report names causes, never people.

No repair starts before that. It's proven against a test that reproduces the failure, and handed back with a runbook so you can run it without me. The method follows Google SRE incident practice, ITIL 4 change control and NIST SP 800-61r3 for security incidents.

Away from break-fix work, I build inbound-aware GTM systems for SaaS teams whose inbound runs on automations. The work covers speed-to-lead with a system SLA, dormant-pipeline recycling from your own systems, and pipeline reporting. That work starts the same way, with a written diagnosis.

If that is close to what you need, email jarr.wright@gmail.com. Tell me what you are running and what is breaking. I reply within 24 hours, and I'll tell you straight whether I can help and what the first step costs.

If you would rather ask in public first, open an issue on this repository.

If you found me through a freelancing platform, please keep the conversation there until a contract is in place.

About

The container and stack plane of a three-plane n8n reliability reference: hardened Compose topology, TLS termination, file-based secrets, capability drops, task-runner isolation. Workflow and host planes link from the README.

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages