Running in production¶
The commands in Build from source (flask --app vulniverse_api run
--debug, npm run dev) are development-only. Follow these steps in order
for a real, bare-metal deployment (systemd + nginx on the host). If you'd
rather run it in containers instead, see Docker.
Step 1 — Configure the environment¶
create_app() requires a SECRET_KEY and a CNA_CREDENTIAL_ENCRYPTION_KEY
from the environment — it refuses to start without either.
- Install the dependencies and copy the template:
This creates
backend/.venv, which the systemd unit in Step 5 runs from. The unit assumes the checkout lives at/opt/vulniverse; adjust its paths if yours is elsewhere. - Generate a real secret and paste it into
.env'sSECRET_KEY=: - Generate a Fernet key and paste it into
.env'sCNA_CREDENTIAL_ENCRYPTION_KEY=— this encrypts each user's CNA credentials at rest. Changing it later makes previously-saved credentials undecryptable, so treat it likeSECRET_KEY: generate it once, keep it, back it up: - Leave
DATABASE_URLunset for now if you're staying on SQLite — skip to Step 3. Otherwise continue to Step 2.
Step 2 — (Optional) Set up PostgreSQL¶
Skip this entirely unless you want to run a separate PostgreSQL instance.
- Create a dedicated role and database — don't reuse one that belongs to another application:
- Set
DATABASE_URLin.env, using the+psycopgscheme — plainpostgresql://resolves to the olderpsycopg2driver, which isn't installed here (psycopg[binary]is): - Continue to Step 3 — migrations run exactly the same way regardless of which database you're on.
Step 3 — Run migrations¶
Run the DB migrations:
If you're running in local mode ([server] mode = "local" in
config/vulniverse.toml, the default), also create the internal local
user — this is a separate, one-time step migrations don't do for you:
Without it, every request gets "Authentication required" instead of
being auto-authenticated, even though the deployment is genuinely in
local mode — db upgrade only creates the user table, not this row.
Step 4 — Run under gunicorn¶
flask run --debug is the development server — with debug=True it
exposes Werkzeug's interactive debugger, which allows arbitrary code
execution to anyone who can trigger an unhandled exception. Never run it
outside development.
-
Start the app using gunicorn:
Two workers is deliberate, not a placeholder: SQLite allows only one writer at a time, so more worker processes sharing the one SQLite file risks lock contention under real concurrent writes. -
Confirm it's actually answering:
Step 5 — Supervise it with systemd¶
backend/deploy/vulniverse.service is a template to run the backend as a systemd service. Copy
it to your systemd path and adjust the values:
To use it follow these steps:
- Remove or fill in the placeholder keys. The template sets
Environment=SECRET_KEY=replace-…andEnvironment=CNA_CREDENTIAL_ENCRYPTION_KEY=replace-…. Values already in the environment win overbackend/.env, so these placeholders would be used instead of your real keys — and an invalid Fernet key breaks CNA credentials and 2FA. Delete both lines so.envis used, or replace them with your real values. - Create the service user the template runs as (or edit
User=/Group=to an existing one): - Install and start it. The unit runs
db upgrade(ExecStartPre=) before every start, so migrations stay current after updates:
Step 6 — Serve the frontend and expose it with nginx¶
- Build the frontend:
This writes static files to
frontend/dist. backend/deploy/vulniverse.nginx.confis a template that servesfrontend/distand reverse-proxies/api/to gunicorn. Copy it and adjustserver_nameand therootpath for your deployment:- Add TLS (for example with Certbot/Let's Encrypt) rather than serving over plain HTTP in production.