Standalone Setup: Running InfraOrcinus on Your Own PostgreSQL
By Chirag Panchal · Founder & Lead Architect · · 6 min read
How the first-run setup wizard connects InfraOrcinus to a PostgreSQL database you already run, applies the schema, and creates the first administrator, protected by a one-time setup token, loopback-only access and DNS-rebinding defence, on Linux, Windows and macOS. Where the generated secrets are stored, and why they must be backed up.
Development Status & Architectural Evolution: InfraOrcinus is in active development. Architecture specifications, internal interfaces, and operational protocols described herein reflect our current engineering design and are continuously refined to make InfraOrcinus robust, resilient, and enterprise-grade.
A first run is a security event. The moment a new service starts with no password set and a web page that will accept a database address, it is a service that anyone who can reach it could point at their own database, or at yours.
InfraOrcinus can run as a single binary on your own PostgreSQL, with no containers or environment files required, and a setup wizard does the first-run work. This article covers when the wizard appears, what it does, and why each step is built the way it is.
1. When the Wizard Runs, and When It Does Not
At start-up the server decides how it is configured, in this order:
- The environment names a database (
DATABASE_URI,DATABASE_HOSTorDATABASE_TYPEis set). The wizard never runs. This is the container and server path, and it behaves exactly as before. - A saved configuration exists. It is loaded, the database is logged with the password redacted, and the server starts.
- Neither exists. The wizard starts and blocks until it completes.
For unattended installs, set INFRAORCINUS_SETUP=off. A missing configuration then becomes a clear start-up error ("no database configured") instead of a wizard waiting for a person. INFRAORCINUS_NO_BROWSER=1 stops it opening a browser window, which suits a headless machine.
Environment variables always win over the saved file. The file only fills in what is unset, so an operator can still override any single value.
2. Protecting a Page That Takes a Database Address
The wizard is a web page that accepts credentials and configures the server, so it is built as if someone hostile were watching the network.
- Loopback only. The wizard listens on
127.0.0.1, not on all interfaces. Until setup finishes, nobody else on the network can reach it, so nobody else can point the installation at a database of their choosing. - A one-time token. A random token is generated at start-up and printed as a link:
http://localhost:<port>/setup#token=.... Every wizard request must present it in a header, compared in constant time. - The token travels in the URL fragment. The part after
#is never sent to a server and never appears in logs or referrer headers. The page reads it and sends it as a header. - DNS-rebinding defence. A web page on another origin can trick a browser into sending requests to
localhostby controlling DNS. The wizard rejects any request whoseHostheader is not this machine's own loopback name, which stops that. - One completion only. The wizard finishes once, then shuts down its listener after the browser has received the final response.
You open the printed link on the same computer. That is the point: possession of the machine is the credential.
3. What It Does
You give it the PostgreSQL host, port, database, user, password and SSL mode, and choose the first administrator's password. It then:
- Tests the connection without changing anything, and explains a failure in plain language: wrong credentials, a database that does not exist, a user without the privilege to create objects, a missing
pgcryptoextension, or an unsupported PostgreSQL version. - Applies the schema. Migrations are applied in order, each in its own transaction, recorded once and guarded by a database lock so a restart racing a crash cannot apply one twice.
- Creates the first administrator with the password you chose. The password must be at least 12 characters and not a well-known default. It is held in memory only to create the account and is never written to disk, so no file ever contains it.
- Generates the secrets the server needs and saves the configuration.
The result is a working installation, with the server continuing to start normally in the same process.
4. Where the Secrets Live
The wizard generates three secrets: the key that encrypts stored credentials, the secret that signs sessions, and the secret shared with runners. They are saved with the database password in a per-user configuration file:
- Windows: protected with DPAPI, so only the same Windows user can decrypt them.
- macOS and Linux: protected by file permissions:
0600in a0700directory, under the user's configuration directory.
You can move the file with INFRAORCINUS_CONFIG.
The encryption key must never change afterwards. Changing it makes every stored credential unreadable. Back it up on its own, away from database dumps, as the article on high availability describes. Treat the configuration file as you would any file holding a master key.
Once the server is running, an administrator can view and update the saved database connection (without the password being shown back) from the product, and the change applies after a restart. A connection set by environment variables is the operator's and is not editable that way.
5. Honest Limits
- Single machine, single user. Standalone mode is designed for one binary and one user account. For multiple replicas, containers or shared hosts, configure the database through environment variables and use the high-availability guidance instead.
- You still own PostgreSQL. The wizard connects to a database you run. Its backups, upgrades and availability are yours.
- Permissions protect the file, not a compromised account. Anyone who is already the same operating-system user can read the file on macOS and Linux.
- The platform-specific parts are tested on all three systems. Each platform has its own way of opening a browser and protecting a file, and those are exactly the parts that differ, so the configuration and wizard tests run in continuous integration on Windows and macOS as well as Linux.
Summary
The setup wizard appears only when no database is configured, listens on loopback, demands a one-time token carried in the URL fragment, rejects rebinding by checking the host header, applies the schema, and creates the first administrator without ever writing the password to disk. It generates the encryption, session and runner secrets once, stores them protected per user, and expects you to back up the encryption key separately.