Skip to content
Tobias L. Maier

How I over-engineered my private document management system

Paperless-ngx for six tenants on one NAS, reached over Tailscale. A talk from 2024, with what changed since.

Published
Updated
Reading time
9 min

I gave this talk at Accenture’s internal architecture meetup on 25 January 2024, and never published it. It shows a more advanced setup of Paperless-ngx, an open source document management system (DMS), and explains the key architecture choices along the way. Some of them matter beyond Paperless-ngx: multi-tenancy, and Zero Trust to reach the documents from anywhere.

The simple setup would have been one instance, left alone. I ended up with six of them, sharing some services, reached over Tailscale, and built a tool to print archive labels, all before I knew whether I would use it in the long term. Going paperless has proven itself over the years, and so have the infrastructure and the Zero Trust parts. The over-engineering was worth it: I added new technologies and architectural approaches to my tool belt and have used them ever since, Tailscale and Caddy for Librario among them. Here is the talk, with notes where my setup has changed since.

A shelf full of binders.
I had 35+ folders. They took up space, and finding something took time.

The folders held the papers of my family and of my companies, like BauCloud GmbH.

My vision was to go completely paperless:

  • Get rid of all non-essential paper. Keep just one folder in the flat, and keep only the relevant documents.
  • Access from everywhere. Have the documents at my fingertips.
  • Multi-tenancy. Six tenants: family, two private, three companies.

The setup

I chose to run Paperless-ngx on my Synology NAS. Paperless-ngx is open source, actively developed, has a simple architecture and an ecosystem of apps. My NAS has four bays, 31 TB of capacity and 20 GB of RAM.

The Paperless-ngx document list in dark mode: demo invoices, bank statements and receipts as cards, each with tags such as Paid, Utilities or Banking.
Paperless-ngx 3. Screenshot from the Paperless-ngx documentation.

Paperless-ngx picks up new documents from a folder on the NAS, runs text recognition (OCR) on them and classifies them automatically. I search them in the web UI, or on my iPhone with Less Paper, a native iOS client.

Architecture

What I like: for special tasks, Paperless-ngx uses off-the-shelf services built for them. Tika and Gotenberg are also stateless.

The catch: Paperless-ngx isn’t ready for multi-tenancy. It has users and permissions, but only a couple of users share it, and their access overlaps almost completely. Permissions also can’t answer questions like “which letters did company X get from vendor A?” What I want is data isolation: the ability to export or move one tenant without touching any other.

Multi-tenancy models, from isolated to shared everything.

For me, multi-tenancy always means weighing the isolation I need against what the software supports.

The strictest model is isolated: every tenant gets its own full set of infrastructure. That gives proper data isolation and lets you allocate costs, but it has the highest total cost of ownership. Users and permissions are a kind of shared everything, and I didn’t consider that viable at all. Paperless-ngx doesn’t support shared application, so I started from isolated. From there, I looked for parts of the infrastructure the tenants could still share, which makes it shared infra.

Each tenant has its own Paperless-ngx and database. Valkey, Tika and Gotenberg are shared.

All tenants share the server, the NAS, and one each of Valkey, Tika and Gotenberg instead of six. Memory is the NAS’s biggest constraint, so that mattered.

What holds data stays apart. Each tenant keeps its documents’ data in its own SQLite database, the Paperless-ngx default. Valkey, a fork of Redis, is the task queue; it has numbered databases that keep their data apart, and each tenant uses one of its own. Tika and Gotenberg are stateless, luckily, so sharing them is easy.

Networking

By default, each tenant runs on its own port, from my-nas.local:32121 up. To use the DMS from everywhere, I needed a proper look at networking. My requirements:

  • Proper, memorable domains.
  • Accessible from everywhere, but restricted to a couple of users.
  • HTTPS certificates, at least to avoid browser warnings.
  • Zero ops: no self-signed certificates, no manual certificate rotation.

The question is how to make the Paperless-ngx instances reachable, and how to enable single sign-on (SSO) in a pragmatic way.

The typical approaches:

  • Public internet. Publish the HTTP services, for example with dynamic DNS (DynDNS), which keeps a domain pointed at the changing IP address of a home connection.
  • Trusted network. Trust the home network itself, so you can only use the services at home.
  • Trusted network + VPN. Add a VPN, for example on the FritzBox router. That setup is tedious and doesn’t solve authentication.

I was looking for something better, and Google’s BeyondCorp pointed me to Zero Trust.

RequirementTrusted network + VPNZero Trust
Memorable domainsPossible, but manual work. A private DNS server?Automatic
Accessible from everywhere, restricted to a couple of usersWireGuard VPN on the FritzBox: manual onboarding of new devices, certificate managementCore feature
HTTPS certificatesPossible, but manual workAutomatic
Zero opsNoYes

The main idea of Zero Trust is to never trust, always verify. NIST SP 800-207 puts it like this:

Zero trust provides a collection of concepts and ideas designed to minimize uncertainty in enforcing accurate, least privilege per-request access decisions in information systems and services in the face of a network viewed as compromised.

Tailscale is a software-defined mesh VPN that makes such a Zero Trust network easy. A central control server, run by Tailscale in the cloud, handles keys and policy, and identity comes from an existing login such as Google Workspace. Tailscale calls such a network a tailnet. The building blocks I needed:

  • Mesh VPN based on WireGuard, a modern VPN protocol.
  • MagicDNS: automatic DNS names for all hosts.
  • Automatic HTTPS for all MagicDNS names.
  • Identity headers: HTTP request headers that say who the user is, for authentication.
  • Access control lists (ACLs) for authorisation: who may reach which device.
  • Sharing nodes with other tailnets.

In the talk I demoed a proof of concept with Caddy and Tailscale, and tailscale serve as the next step.

One Caddy served all tenants, with the caddy-tailscale plugin. Each site in the Caddyfile binds to its own tailnet node, so every tenant got its own name and certificate:

Caddyfile
:443 {
	bind tailscale+tls/dms-tenant-a
	reverse_proxy webserver-tenant-a:8000
}
The setup in 2026. Valkey, Tika and Gotenberg aren’t on the tailnet.

A Tailscale Service has its own name and address on the tailnet, independent of the device that serves it. Each tenant is one, and the NAS serves all of them:

tailscale serve --service=svc:dms-a --https=443 http://127.0.0.1:18001

The tenants’ URLs look like https://dms-a.example.ts.net, and grants in the tailnet policy say who may reach which service. Paperless-ngx takes the user from the identity header that Tailscale adds, so there’s no separate login:

paperless.env
PAPERLESS_ENABLE_HTTP_REMOTE_USER=true
PAPERLESS_ENABLE_HTTP_REMOTE_USER_API=true
PAPERLESS_HTTP_REMOTE_USER_HEADER_NAME=HTTP_TAILSCALE_USER_LOGIN

Paperless-ngx trusts that header without checking where it came from. So the grants allow only the services on port 443, never the NAS’s own ports. A peer that could reach port 18001 directly could send any user name it likes.

Document management process

The process.

I don’t keep every document, only the relevant ones: certificates (Urkunden) and tax-relevant documents such as invoices and account statements.

Archive serial numbers (ASN) let me find the paper originals I keep. I took the idea from margau’s post paperless-ngx with QR codes as ASN: a QR code sticker carries the ASN, Paperless-ngx reads it when it consumes the scan, and the paper goes into a binder in ASN order.

How to print such labels? I bet one doesn’t need to generate a PDF file in today’s world to get a perfectly aligned print-out on Avery L4731 label sheets.

And indeed, one doesn’t, if you use Google Chrome. The ASN QR code label generator is on this site, built with Tailwind CSS and Alpine.js, and its source is on GitHub.

In 2024, I scanned straight to a network folder on the NAS, and Paperless-ngx consumed the documents from there.

A “PATCH 1” separator sheet with barcodes.

To scan many documents in one go, I used patch sheets: separator pages with a barcode. Paperless-ngx splits a scan at each one.