Configuration
The server reads its settings from environment variables. These settings control where the server listens, where it keeps its data, and who owns it. There is no configuration file.
Local mode and server mode #
Both modes require PostgreSQL 18. The standalone Local product has ended. Local mode still lets you develop without signing in. Running the code elsewhere is possible, but Mainworthy does not support it yet. The mode determines how the server identifies you.
In local mode you are the owner. The server listens on a loopback address, which accepts connections only from this machine. A request from this machine needs no token if it meets the conditions below. The web UI opens signed in, and commands run without --token. A request counts as yours when four conditions hold:
- Its
Hostheader names this machine:localhost, any address in127.0.0.0/8written in full (such as127.0.0.1), or[::1]or[::ffff:127.x.x.x]in brackets, each with an optional port. - The connection comes from a loopback address.
- It carries none of these proxy or tunnel headers:
Forwarded,X-Forwarded-For,X-Forwarded-Host,X-Real-IP,Via,CF-Connecting-IP. - No proxy is named: neither
MAINWORTHY_TRUSTED_PROXYnorMAINWORTHY_PROXY_SECRETis set. A proxy on this machine connects from loopback too.
Any other request needs a token or signed-in session. Both modes refuse browser requests made from another site's page when signing in or using a session cookie.
In server mode every request to a project needs a token or a browser that is signed in. A few addresses answer without either, including /health, /docs and the sign-in endpoints. See What answers without a token. The web UI shows a sign-in page, and a command needs --token or MAINWORTHY_TOKEN. People, agents and pipelines explains tokens and signing in.
Either MAINWORTHY_MODE=server or a non-loopback MAINWORTHY_HOST selects server mode. Setting MAINWORTHY_MODE=local does not override a non-loopback host. Every other start is local mode. The first line the server prints says which mode it is in:
$ mainworthy serve
Mainworthy 0.1.0 · local · data in ~/.mainworthy · http://127.0.0.1:7357
project "scratch" · you are robin@this-machine · policy: loose
Warning
When anything sits between users and the server, set
MAINWORTHY_MODE=server. Local mode does not treat a proxy that adds headers as the owner. However, it cannot distinguish you from a relay on the same machine that forwards bytes unchanged. Local mode trusts everyone who reaches that relay as the owner.
Variables the server reads #
mainworthy with no command, or mainworthy serve, starts the server. The server reads the following environment variables.
| Variable | Default | What it sets |
|---|---|---|
MAINWORTHY_HOST | 127.0.0.1 | The address to listen on. Use 0.0.0.0 to listen on every interface. A value that is not loopback selects server mode. |
MAINWORTHY_PORT | PORT, else 7357 | The port to listen on. |
MAINWORTHY_DATA | ~/.mainworthy | Local attachment storage in blobs/ and archive staging in spool/. PostgreSQL stores structured records separately. |
MAINWORTHY_MODE | none | server selects server mode. |
MAINWORTHY_OWNER | USER, else owner | The name of the operator, who runs the instance and has every capability on every project of the first organisation. |
MAINWORTHY_OWNER_WAS | none | The name the owner has now, when MAINWORTHY_OWNER holds a new name for the same person. The server renames the owner at startup. See rename the owner. |
MAINWORTHY_OWNER_TOKEN | none | An optional token for the owner, 20 to 512 visible ASCII characters without spaces. Without it, server mode generates one when the owner has no working token. |
MAINWORTHY_SESSION_IDLE | 14d | How long a browser stays signed in without being used. Use a whole number followed by h, d, or w, as in 12h, 14d, or 2w. |
MAINWORTHY_SESSION_MAX | 90d | How long a browser stays signed in at most, even with regular use. Use the same format as MAINWORTHY_SESSION_IDLE. |
MAINWORTHY_OIDC_ISSUER | none | The issuer address of the OpenID Connect identity provider people sign in through, such as https://accounts.google.com. Set it with MAINWORTHY_OIDC_CLIENT_ID, MAINWORTHY_OIDC_CLIENT_SECRET, MAINWORTHY_OIDC_NAME and MAINWORTHY_PUBLIC_URL. See sign in through an identity provider. |
MAINWORTHY_OIDC_CLIENT_ID | none | The client id the provider gave this instance. |
MAINWORTHY_OIDC_CLIENT_SECRET | none | The client secret the provider gave this instance. |
MAINWORTHY_OIDC_NAME | none | What the sign-in button calls the provider, such as Okta: "Sign in with Okta". |
MAINWORTHY_SIGNUP | closed | open lets anybody who signs in through the provider make an account and organisations of their own, each of which only reads until the operator approves it. Unset, empty or closed: people come in by invitation. Needs the provider and MAINWORTHY_DATABASE_CAPACITY. See let people sign up. |
MAINWORTHY_PADDLE_ENVIRONMENT | none | sandbox or live: which of Paddle's environments the instance sells through. Set all five MAINWORTHY_PADDLE_* variables, or none; with none, billing is off. See billing. |
MAINWORTHY_PADDLE_API_KEY | none | A Paddle API key of that environment (pdl_sdbx_... or pdl_live_...). |
MAINWORTHY_PADDLE_WEBHOOK_SECRET | none | The secret key of the Paddle notification destination that posts to /api/billing-event, as Paddle issued it (pdl_ntfset_...): startup refuses any other shape, and no notification is taken until Paddle's API lists it as a destination's secret. |
MAINWORTHY_PADDLE_PRICE | none | The id of the one price a checkout sells (pri_...). |
MAINWORTHY_PADDLE_CHECKOUT | none | The link of Paddle's hosted checkout, https://pay.paddle.io/hsc_... (sandbox-pay.paddle.io in the sandbox). |
MAINWORTHY_PUBLIC_URL | none | The address people open the instance at, such as https://mainworthy.example. The identity provider sends people back to it, and an invitation link starts with it. Required with an identity provider, and so for any invitation: without a provider the instance makes none. |
MAINWORTHY_TRUSTED_PROXY | none | The addresses or CIDR ranges of the proxy in front, comma-separated. Requires MAINWORTHY_CLIENT_ADDRESS_HEADER. Cannot be set with MAINWORTHY_PROXY_SECRET. |
MAINWORTHY_PROXY_SECRET | none | A secret of at least 32 characters that the proxy overwrites x-mainworthy-proxy with on every request. Requires MAINWORTHY_CLIENT_ADDRESS_HEADER. Requests without matching proof receive 403, except GET /health. |
MAINWORTHY_CLIENT_ADDRESS_HEADER | none | The header in which the proxy reports one visitor address. Requires either the trusted proxy addresses or the proxy secret. |
MAINWORTHY_JOB_KEY | none | Base64 encoding of 32 random bytes, shared by every instance that queues or runs private jobs. An invalid value stops startup. Without a key, the server refuses to queue private jobs. |
MAINWORTHY_JOB_RUNNER | 1 | Set to 0 to disable background job execution. The server stores jobs in the database. A job due immediately starts when the write that queued it commits. Once a minute, the runner queues recurring jobs and runs any jobs that came due, such as retries. Both Render Blueprints set it to 1. |
MAINWORTHY_DATABASE_URL | required | PostgreSQL connection URL. compose.yaml starts PostgreSQL 18 and sets this for the app. Connect directly or through a pooler in session mode. The server keeps locks, LISTEN subscriptions, and settings on its connections. A pooler in transaction or statement mode can give the connection to another client between statements. |
MAINWORTHY_DATABASE_CAPACITY | none | A budget for the database's own size in GB (10^9 bytes), such as 4GB; at most 1000000GB, and another value stops startup. Mainworthy compares it with what PostgreSQL's pg_database_size reports, which counts only this database's files: not the write-ahead log, other databases on the server, temporary files or logs. Set it below the disk, with room for those; the Render Blueprint sets 4GB for a 5 GB disk. From 85% of it on, no organisation but the operator's sends a report or an attachment, and the same happens from each start until the database's first good reading, and once its last good reading is five minutes old. Unset, the database never counts as full. The database is read again at the job runner's minute tick (and in the background when a report finds the last reading older than a minute), so with MAINWORTHY_JOB_RUNNER=0 and a size set, the first report after five quiet minutes finds the reading too old and is refused, and the reports after it are taken once the reading it started ends. Keep the runner on where a size is set; mainworthy.com runs it. The attachment disk under MAINWORTHY_DATA is read from the file system and refused at 85% the same way, and while its readings fail for five minutes. See limits of an organisation. |
MAINWORTHY_DB_POOL | 2 | Read-pool connections, an integer from 1 to 64. |
MAINWORTHY_DB_WRITE_POOL | 4 | Write-pool connections, an integer from 1 to 64. Writes lock their actors and projects; different projects can write concurrently. |
MAINWORTHY_DEMO | none | The server refreshes a marked demo once per deployed revision after it starts listening. The commit comes from MAINWORTHY_COMMIT or SOURCE_COMMIT. Restarting the same revision preserves edits and renews featured work. A new revision replaces the demo and keeps its grants. The server removes retired data in batches. It refuses unknown revisions and projects without a demo mark. See demo data. |
MAINWORTHY_COMMIT | none | The commit this server was built from, which /health reports. It must have 40 lower-case hexadecimal characters. If absent or invalid, the server tries SOURCE_COMMIT, then reports unknown. |
MAINWORTHY_GITHUB_PROJECT | none | The project, of the operator's organisation, allowed to send defects and optional gate commit statuses to GitHub. Set the project, repository, and token together. |
MAINWORTHY_GITHUB_REPOSITORY | none | The destination on github.com, written owner/repository. Requests cannot choose another repository. |
MAINWORTHY_GITHUB_TOKEN | none | A token for that repository. Defect requests need Issues write permission. Gate commit statuses need Commit statuses write permission on a fine-grained personal access token, or the repo:status scope on a classic token. Keep it in the server's secret environment, outside the repository. It is never stored in the database or an archive. |
MAINWORTHY_GITHUB_STATUSES | 0 | Set to 1 to publish commit gates as GitHub commit statuses. Requires the three GitHub variables and MAINWORTHY_PUBLIC_URL. See GitHub commit statuses. |
MAINWORTHY_JIRA_PROJECT | none | The Mainworthy project, of the operator's organisation, allowed to send Jira defects. Set all six Jira variables together. |
MAINWORTHY_JIRA_SITE | none | The Jira Cloud site as an HTTPS origin, for example https://example.atlassian.net, without a path, query, fragment, or embedded credentials. |
MAINWORTHY_JIRA_PROJECT_KEY | none | The Jira destination project key, for example QA. Requests cannot choose another project. |
MAINWORTHY_JIRA_ISSUE_TYPE | none | The issue type name available on that project's create screen, for example Bug. |
MAINWORTHY_JIRA_EMAIL | none | The Jira account email. Keep it in process configuration. It is never stored in the database or an archive. |
MAINWORTHY_JIRA_TOKEN | none | An API token for that account with Browse projects and Create issues permission. Keep it in the server's secret environment. It is never stored in the database or an archive. |
MAINWORTHY_HANDOFF_PROJECT | none | The project, of the operator's organisation, whose failure questions can be handed to a coding agent. Set the project, address and secret together. See hand a failure to a coding agent. |
MAINWORTHY_HANDOFF_URL | none | The address the server posts a hand-off to, for example a T3 Code webhook. It must be https, or http on 127.0.0.1 or localhost. Treat it as a secret when it carries a token, as a T3 Code webhook address does. It is never stored in the database or an archive. |
MAINWORTHY_HANDOFF_SECRET | none | At least 16 characters without whitespace. The server signs each post with it (HMAC-SHA256, hex, in X-Mainworthy-Signature: sha256=<digest>). Give the receiver the same secret. Keep it in the server's secret environment. |
Saving a case can wait for another transaction on the same project. In one server process, project operations and maintenance release their database connections while they wait for each other on that project. Other projects can use those connections. Changes to access and writes from another server process wait on PostgreSQL locks and can occupy write connections.
An invalid session duration also stops startup with a line that names the variable.
For MAINWORTHY_PUBLIC_URL, use https and a host name with nothing after it, or http://localhost with its optional port. The server refuses plain http anywhere else. Paths, queries, usernames and passwords are refused because the server needs the instance's root address. Links use that address's origin.
The server checks configuration before creating the data directory. A refused public address, owner token length or form, or reserved owner name creates no files.
Reads use pooled PostgreSQL connections. MAINWORTHY_READERS is removed. The server starts only with a PostgreSQL URL.
At startup, the server starts a grace period for any existing attachment file named by its hash that it has never tracked. Later starts keep the recorded age. The cleanup job keeps files that records still reference. It removes unreferenced files only after the grace period, including files left before the cleanup job existed.
PostgreSQL owns its write-ahead log and checkpoints. Back up PostgreSQL and local attachments together; Mainworthy creates no automatic upgrade copy.
GitHub Issues and Jira Cloud are optional. Each supports one destination for one project per instance, through the API and command line. See create or link a tracker defect. A partial or malformed configuration stops the server with a message that names the variables without quoting credentials. If both trackers name the same Mainworthy project, new defects go to Jira. GitHub remains available for commit statuses and existing defect holds.
Every start makes the person named by MAINWORTHY_OWNER in the first organisation the operator, and gives them every capability there. A project of another organisation with the same key as one of these settings gets none of these integrations. The owner must be a person. The server refuses to start if the name belongs to an agent, a pipeline or a forgotten person, or starts with forgotten-.
If you change MAINWORTHY_OWNER, the server makes the named person the operator. It creates that person if the first organisation has nobody by that name. If the previous operator still owns the first organisation, the new operator takes ownership. If somebody else owns it, they keep it.
The previous operator keeps their grant and tokens. If you no longer want them to administer the instance, remove their grant with mainworthy actor ungrant, revoke their tokens, or forget them. A new value for MAINWORTHY_OWNER_TOKEN also revokes earlier tokens the server issued through that variable.
On the first start after an import, the operator takes ownership of the first organisation regardless of who owned it in the archive. The operator can hand it on with org.transfer. To give the same person a new name, rename the owner.
Rename the owner #
The owner's name comes from MAINWORTHY_OWNER. When that variable is unset, the name comes from USER. When neither is set, the name is owner. These steps rename an owner currently named owner to robin.
-
Set
MAINWORTHY_OWNERto the new name andMAINWORTHY_OWNER_WASto the name the owner has now.MAINWORTHY_OWNER=robin MAINWORTHY_OWNER_WAS=owner -
Start the server again. It says one line:
MAINWORTHY_OWNER_WAS: owner is now robin, with the tokens, identities, sessions and history owner had. robin signs in under the new name. Unset MAINWORTHY_OWNER_WAS. -
Unset
MAINWORTHY_OWNER_WAS. If the variable stays set, the server renames nobody and says so at every start.
The owner's tokens and linked identities keep working. Their browser sessions stay signed in, and history shows their new name. A browser keeps an unrecorded draft for the person, not for their name, so the owner still sees their drafts under the new name.
Startup refuses the rename when MAINWORTHY_OWNER_WAS names nobody on the instance, an agent, a pipeline, a forgotten person, or somebody who is not the operator the last start named. The error says why.
The new name follows the same rule as any actor name. It uses letters, digits, ., _, @ and -, starts with a letter or digit, and has at most 64 characters. Any other name stops startup.
When the new name is already somebody's, the start renames nobody and says so. That person becomes the operator, as they do without the variable. When the name is an agent's, a pipeline's or a forgotten person's, the start is refused instead, as it is without the variable.
Nobody else's name can be changed.
If the owner name or token prevents startup, the server changes no actor or token. The server checks the token format and reserved owner names before it opens the database. It applies database migrations before checking whether an existing actor can become the owner. Mainworthy does not make an automatic PostgreSQL upgrade backup.
For the first server-mode sign-in, use the owner's token. Then link your identity at the provider in Settings, Your sign-in. If you set MAINWORTHY_OWNER_TOKEN, the server adds that value as a token for the owner. Otherwise, a start on which the owner has no working token prints a generated one. The first start and a start after an import do this.
To replace a lost token, set MAINWORTHY_OWNER_TOKEN to a new value and restart. The start revokes every token previously issued through that variable, whoever the owner was then. It ends browser sessions opened with those tokens and names each token and actor in one log line. Tokens you made yourself and tokens the server generated keep working.
A value shorter than 20 characters or longer than 512 stops startup. Only visible ASCII characters are accepted: letters, digits and punctuation, with no spaces, tabs, line breaks, other control characters or non-ASCII characters. The server uses the exact value for browser sign-in and HTTP bearer authentication. An invalid value stops startup before any token is created or revoked, so a refused rotation leaves the previous token and its browser sessions working. If an earlier build accepted an invalid value, replace it. openssl rand -hex 32 makes a suitable value. Keep it out of version control.
A value shorter than 32 characters starts with a warning each time. No bearer token or sign-in token longer than 512 characters works.
A value already stored as a token revokes nothing. If that token was revoked, expired or belongs to somebody else, the server leaves it unchanged and says why on standard error. Set a new value in that case.
Variables and flags the command line reads #
Commands that talk to a server find its address in this order: the flag, then the variable, then the default. Local commands such as fmt and audit verify need no server.
| Variable | Flag | Default |
|---|---|---|
MAINWORTHY_URL | --url | http://127.0.0.1:7357 |
MAINWORTHY_TOKEN | --token | none |
MAINWORTHY_TOKEN_FILE | --token-file | none |
MAINWORTHY_PROJECT | --project | the only project, if there is one |
health, fmt and help output ignore MAINWORTHY_TOKEN, MAINWORTHY_TOKEN_FILE and their flags. They do not read token files. The server reads its own settings instead of these client token options.
With more than one project and no choice, a command stops with invalid: choose a project with --project or MAINWORTHY_PROJECT; projects: scratch, checkout. The mainworthy health command, with no --url or MAINWORTHY_URL, asks the server on this machine at MAINWORTHY_PORT.
Prefer MAINWORTHY_TOKEN or --token-file to --token. The process list and the shell's history show the value passed through --token. Command line says more. For these variables, a value that is set but empty counts as not set. Command line lists every command.
Variables that describe a CI build #
MAINWORTHY_COMMIT, MAINWORTHY_BRANCH, MAINWORTHY_PR, MAINWORTHY_BASE, MAINWORTHY_ATTEMPT, MAINWORTHY_JOB, MAINWORTHY_BUILD_URL, MAINWORTHY_REPO and MAINWORTHY_ENV tell mainworthy report which build produced the results. The server also reads MAINWORTHY_COMMIT to identify its own build, as the table above describes. A CI job sets these variables when Mainworthy cannot detect the build. Report results explains each.
Run the app and PostgreSQL #
The source tree includes a Dockerfile and compose.yaml. Compose builds the app and starts PostgreSQL 18.
It publishes the app on port 7357, mounts mainworthy-data at /data for attachments and staging,
and gives PostgreSQL its own mainworthy-postgres volume at /var/lib/postgresql.
$ docker compose up -d
The app waits for PostgreSQL health before starting. MAINWORTHY_POSTGRES_PASSWORD overrides the development password
in compose.yaml. The Render Blueprints use the managed database's connection string. See the repository's
docs/render-migration.md for Render setup. Both Blueprints store the tested :main image tag so a settings
redeploy follows tested releases. CI deploys exact digests. See docs/deploy.md, "Render settings redeploys and
rollback", before pinning an older image; it must support the current database schema.
Compose passes owner, session, proxy, public URL, identity provider and demo settings to the app.
Set MAINWORTHY_OWNER_TOKEN to a long random string. If you leave it empty on first start, the server generates one and prints it once in docker compose logs. Open http://localhost:7357 and sign in with it.
The image checks its own health every 30 seconds by running mainworthy health. The check calls /health, which needs no token:
$ curl -s http://127.0.0.1:7357/health
{"ok":true,"version":"0.1.0","apiVersion":4,"commit":null}
$ mainworthy health
healthy: Mainworthy 0.1.0 at http://127.0.0.1:7357
mainworthy health exits 0 when the server answers and 1 when it does not. Use /health for a monitor of your own. Its apiVersion is the CLI compatibility contract. mainworthy health --json also reports compatible, which is false for an older server that advertises no API version. An incompatible healthy server still exits 0. CLI and server versions explains refusal of operations.
During startup, health answers HTTP 503 with ok: false, state: "upgrading", so a probe that reads only the status waits. The health command reads the body, exits 0 and prints upgrading, so Docker can start dependent services. Other requests receive HTTP 503 until ready. A readiness monitor must require ok: true and, for a deployment, the expected commit. Startup failure closes the listener.
commit identifies the server's build when the commit was supplied. To include the commit, build the image with MAINWORTHY_COMMIT=$(git rev-parse HEAD) docker compose build. Then /health names that commit, and mainworthy health prints its first 12 characters. Without a supplied commit, the answer is null.
Back up PostgreSQL and the attachment volume. Your data explains how.
Run behind a proxy that ends TLS #
The server speaks plain HTTP. To serve it over HTTPS, put a proxy in front of it to handle the encrypted connection. Set MAINWORTHY_MODE=server and configure the proxy as follows.
- Pass the
Hostheader on unchanged, so the server sees the name the browser used. - Set
X-Forwarded-Proto: https. A list such ashttps,httpcounts as https.
When a browser sends Origin while signing in or using a session cookie, the server checks that it has the request's scheme and host. Without X-Forwarded-Proto, the server sees http and refuses sign-in from the https page with unauthenticated: a token is required. The error does not name the cause. With the header, the session cookie is marked Secure.
The server also reads Sec-Fetch-Site, the header that identifies which site made a browser request. The server refuses sign-in and session-cookie requests from another site's page. A browser sends that header only to HTTPS addresses and to this machine. For plain HTTP to a name or address on your network, the browser sends no Sec-Fetch-Site header. The server then checks Origin alone.
The session cookie still has SameSite=Strict, so the browser excludes it from requests made by another site's page. However, plain HTTP sends the token and the cookie without encryption. The cookie also lacks its __Host- prefix and Secure mark. HTTPS through a proxy is the supported way to serve an instance to anybody but yourself.
The server counts wrong tokens by their source address and first 8 characters, both on authenticated operations and in the sign-in form. /health, the API description and the documentation need no sign-in and ignore tokens. The fifth wrong token within 15 minutes blocks that address or token prefix for one second. Each further wrong token doubles the wait, up to 15 minutes. A blocked request gets HTTP 429 with Retry-After. Repeated checks and valid sign-ins do not spend the failed-attempt allowance.
All instances on the same database share failed-attempt counts and limits for anonymous sign-in starts. Restarting an instance does not reset them. Jobs that expire sessions or clean up sign-in records wait for identity and actor locks. Then they check that they still have the lease to do the work. A worker whose lease has expired cannot commit over its successor.
A provider sign-in can start on one instance and finish on another. Each sign-in attempt works once. Importing an archive invalidates every pending provider sign-in on all instances. The server records when a token or session was last used during a request, at most once a minute for each credential. The server checks that recorded time to decide whether a session is idle, so an active session can end up to a minute early.
A signed-in browser is unaffected. A correct server-generated token also works while blocked. These include tokens from mainworthy token new or Settings and the owner token printed at startup. A token supplied through MAINWORTHY_OWNER_TOKEN waits with other user-chosen tokens. Copying an existing server-generated token into that variable keeps its server-generated status. A request that presents a token uses that token's identity, whatever cookie comes with it.
Refused provider answers and invitation codes count by address alone. A valid invitation code still works from a blocked address.
Behind a proxy every connection comes from the proxy, so the server cannot tell visitors apart unless you tell it where to look. Set MAINWORTHY_TRUSTED_PROXY to the proxy's address as the server sees it. Set MAINWORTHY_CLIENT_ADDRESS_HEADER to the header the proxy writes the visitor's address in. Choose a header that the proxy sets and visitors cannot control. Otherwise, a visitor could choose the address Mainworthy counts. The header must hold one address and nothing else. The server refuses startup if only one variable is set, an address or range is invalid, or the header name is invalid. The startup message identifies the invalid setting. With a proxy named, by address or by MAINWORTHY_PROXY_SECRET, nobody is signed in just by connecting from the machine Mainworthy runs on, even in local mode: the proxy connects from that machine too. Set MAINWORTHY_OWNER_TOKEN and sign in with it, because local mode makes no owner token of its own.
When direct and proxied requests arrive from the same front end, address-based trust cannot distinguish them. Set MAINWORTHY_PROXY_SECRET instead of trusted proxy addresses. The proxy must overwrite x-mainworthy-proxy with that secret on every request. Set MAINWORTHY_CLIENT_ADDRESS_HEADER to its visitor-address header, such as cf-connecting-ip. Mainworthy compares the proof in constant time before any request handler runs. Missing or incorrect proof receives a JSON 403, including on sign-in, docs, static files, streams and archives. GET /health needs no proof, for host health checks. POST /api/job cannot run jobs over HTTP; only the internal runner can invoke the job operation. A missing or malformed visitor address gives a proved request no address. Provider sign-in starts with no address share one source. A full store makes room from a source with the most stored records, so a flood of these starts loses its own records once that source is the largest. Startup refuses a secret shorter than 32 characters, a secret without an address-header name, or a secret together with trusted proxy addresses.
With no proxy configured, what happens depends on the connection's address. A loopback or private address, such as a proxy on the same machine or the same Docker network, is not counted at all. For those addresses, wrong tokens are counted only by their first 8 characters. A server-mode start says so in one line. A public proxy address has one shared count for every visitor behind it. One visitor's wrong tokens can block your chosen owner token for all visitors until the wait ends. Configuring either proxy trust method fixes both.
After three minutes of silence, the server closes a connection nobody has signed in on. If a sign-in's body has not arrived within five seconds, the server answers with 408. A request with a valid token or session is not timed out, so a long reply is not cut off.
The server accepts a request body of up to 64 MiB for an operation. A proxy with a lower limit rejects a large report. mainworthy export and mainworthy import stream archives of up to 8 GiB, so give those paths the same room.
What answers without a token #
In server mode everything that reads or changes a project needs a token or a signed-in session. These addresses answer without a session. When a proxy secret is configured, all except GET /health still require the proxy's proof:
| Address | What it returns |
|---|---|
/health | Whether the server is up, its software and API versions, and the commit it runs when it was told. It needs no proxy proof, so host health checks can read it. Both Render Blueprints use this path. |
/docs and the pages under it | This documentation, the same for every instance of a version |
/api/openapi.json | The description of the API, built from the list of operations |
/ | The web UI's own files. The page then asks you to sign in. /invite, the page an invitation link opens, is one of them. |
/api/login opens a browser's session and sets its cookie. /api/logout ends the session and clears the cookie. GET /api/login/methods answers anyone and names the instance's identity provider, if it has one. /api/login/oidc gives a browser the provider's address to sign in, accept an invitation, link an identity or confirm it is you. /api/login/invitation says, for a valid invitation code, whose invitation it is and when it expires. Without a valid code, it reveals no invitation details.
/api/login, /api/logout, /api/login/oidc and /api/login/invitation refuse requests from another site's page. A script, curl or the command line can send requests without a site header. If nobody outside your network should see these addresses, keep the server off the public internet or put the proxy's access control in front of it.
Send traces to an OpenTelemetry collector #
The server can send a trace of each request to an OpenTelemetry collector, or to a vendor that accepts OTLP over HTTP, such as Sentry or Grafana Cloud. It is off until you name an endpoint. A trace shows the request, the operation it ran, each PostgreSQL statement, and the wait for a connection, with their durations. A background job is a trace of its own.
| Variable | Default | What it sets |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | none | The collector's base address. The server sends to <address>/v1/traces. It must use https, or http only on localhost, 127.0.0.1 or [::1], and hold no user name or password: the batches carry the headers below. |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | none | The whole address for traces, used as written. It takes precedence over the base address. |
OTEL_EXPORTER_OTLP_HEADERS | none | Headers sent with each batch, such as a vendor's key: name=value pairs separated by commas, each value percent-encoded. OTEL_EXPORTER_OTLP_TRACES_HEADERS adds to them and wins where a name repeats. Keep the value in the server's secret environment. |
OTEL_TRACES_SAMPLER | parentbased_always_on | Which traces to keep: always_on, always_off, traceidratio, or the same with parentbased_ before it. |
OTEL_TRACES_SAMPLER_ARG | 1 | The share of traces kept by a traceidratio sampler, from 0 to 1. |
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES | mainworthy | The name the collector shows, and further attributes such as deployment.environment.name=production. |
OTEL_SDK_DISABLED, OTEL_TRACES_EXPORTER | none | OTEL_SDK_DISABLED=true or OTEL_TRACES_EXPORTER=none turns tracing off with an endpoint set. |
The server sends OTLP as JSON over HTTP. Another protocol in OTEL_EXPORTER_OTLP_PROTOCOL, an exporter other than otlp, an unknown sampler, a malformed address or header, or plain http to another machine stops the start with a line that names the variable. When tracing is on, the start says where traces go: traces go to https://collector.example.
A trace carries what the server knows about its own code: the route's pattern (POST /api/p/:project/:op, or the method alone for a request no route took), the operation's name, a statement's text as it is written in the source, with $1 in place of each value, an error's type and a status code. It never carries what a caller sent or named: no request body, project key, case text, person, token, address, or error message, and no text of a statement the server builds while it runs. The service version is the commit from MAINWORTHY_COMMIT when it is set. The server starts a new trace for each request and for each background job, and ignores a traceparent header. The health probe is not traced. A recurring job, which the server runs every minute, sends its trace once an hour for each kind, and whenever a run fails or does something, such as posting a commit status or ending a tracker hold; the sampler still applies.
A collector that is slow, refuses or is gone costs requests nothing: spans wait in a queue of 2,048, and new ones are dropped while it is full. The log says once when sending starts failing and once when it works again. A stopping server tries for two seconds to send what is left. While tracing is on, the log line of a failed request, operation or job, and of a slow write, carries (trace <id>), the id to search for in the collector.
To watch traces on your own machine, run bun scripts/traces.ts in the source tree. It prints the variable to start the server with and then each trace as a tree.
Build the single executable #
bun run build compiles the server, the web UI, the command line and the MCP endpoint into one file, dist/mainworthy, tens of megabytes in size. It needs Bun and the source tree, and the result needs neither. The file carries the Bun that built it. If you build with a Bun other than the one THIRD-PARTY-NOTICES.md lists, the build says so. The notices then do not describe that runtime.
$ ./dist/mainworthy
Mainworthy 0.1.0 · local · data in ~/.mainworthy · http://127.0.0.1:7357
The same file is the command line: ./dist/mainworthy gate. The variables above apply to it unchanged.
See also #
- People, agents and pipelines for the owner's token and other tokens.
- Your data for the data directory, backups and moving machines.
- What you can customize for settings that are not environment variables.
Sign in through an identity provider #
People other than the owner sign in through one OpenID Connect identity provider, such as Google, Microsoft Entra ID,
Okta, Keycloak, Authentik, or a hosted service such as Clerk. The provider handles passwords, passkeys, second
factors, and account recovery. Mainworthy keeps none of those credentials and sends no mail. Without a provider,
the instance has agents and pipelines and one person, the owner. The owner signs in with their token, and
mainworthy invite refuses to run.
Mainworthy uses the authorization code flow with PKCE and checks the provider's ID token, including its signature.
- At the provider, register a web application (a "confidential client"). Set its redirect address, also called the callback URL, to the instance's public address followed by
/signin/oidc, for examplehttps://mainworthy.example/signin/oidc. Allow the scopesopenid,emailandprofile. - Set
MAINWORTHY_OIDC_ISSUERto the provider's issuer address. It is the address whose/.well-known/openid-configurationthe provider publishes, exactly as that document'sissuerwrites it. SetMAINWORTHY_OIDC_CLIENT_IDandMAINWORTHY_OIDC_CLIENT_SECRETto what the provider gave you, andMAINWORTHY_OIDC_NAMEto the name the button shows. - Make sure
MAINWORTHY_PUBLIC_URLis set, then restart the instance. - Sign in with the owner token, open Settings, Your sign-in, and link your identity at the provider. Then invite people.
Set all four provider variables together. When you configure a provider, startup fails if any provider variable or MAINWORTHY_PUBLIC_URL is missing. The issuer must use https. The server accepts plain http only on a loopback address, for a provider on the same machine.
When sign-up is closed, an organisation admin invites each new person, who accepts through the provider. Someone who already has an account can link an identity from their settings. See through the identity provider. The client secret goes to the provider and nowhere else: it is not in an archive, the log or a reply.
To confirm it is somebody before a sign-in change, Mainworthy sends them back to the provider with max_age=0, which asks the provider to sign them in again. It also asks for the auth_time claim, and takes the proof only when the ID token says the person signed in there after the confirmation began. The proof lasts ten minutes from that sign-in. A provider that leaves the claim out gives no proof, so enable it where the provider offers the choice. Confirm it is you has the rest.
An identity pairs the provider's issuer address with the subject, the ID the provider assigns to the person. If you change MAINWORTHY_OIDC_ISSUER, identities linked at the old issuer stop working. Sign in with the owner token, link your new identity, and invite everybody else again.
Let people sign up #
A hosted instance where customers make their own organisations sets MAINWORTHY_SIGNUP=open. When someone signs in through the provider with an identity that no account has linked, Mainworthy creates an account.
That person can create organisations they own, each with a first project (sign up and make an organisation). Nobody
who signs up becomes the operator or reaches another organisation. A self-hosted instance leaves it unset. Startup stops if the value is invalid, or if you set open without a provider or without MAINWORTHY_DATABASE_CAPACITY: once the database is full by that measure, nobody new signs up or makes an organisation, and nobody links an identity. Turn it on only once every server process runs a release that has approval: an older one serving the same database lets a waiting organisation write.
An organisation made this way reads and exports, and is refused every write, until the operator approves it with
mainworthy org --do approve --org 2. While it waits, its people can still revoke tokens and invitations, end
sessions and link another identity at the provider to their account; leaving the organisation and deleting an account
wait for the approval. Mainworthy sends no mail: the server logs one line for each new organisation,
with its id and that command; its name, which the applicant chose, is left out. org --do list shows which are waiting, and the identities each one's owner
signs in with. The 50 organisations a day the whole instance makes are shared by everybody who
signs up: an account makes no other while one of its organisations waits, so 50 identities use up a day. The number is fixed in this build; the provider's own
defences against automated sign-ups, such as Clerk's bot protection on mainworthy.com, are what keep one person from
holding that many identities. open has no mode without
approval, and before 1.0 what it means may change again.
Each organisation but the operator's own has limits on projects, members,
attachment bytes, results and requests a minute. The operator reads and raises them for one organisation with the org
operation's limits and limits.set. The requests a minute are counted by each server process: with more than one
behind a load balancer, each allows an organisation its limit.
Google accounts #
To let people sign in with their Google account or Google Workspace account:
- In the Google Cloud console, open Google Auth Platform, then Clients, and create a client of type Web application.
- Under Authorised redirect URIs, add the instance's public address followed by
/signin/oidc, for examplehttps://mainworthy.example/signin/oidc. - Set
MAINWORTHY_OIDC_ISSUER=https://accounts.google.com,MAINWORTHY_OIDC_CLIENT_IDandMAINWORTHY_OIDC_CLIENT_SECRETto the client's id and secret, andMAINWORTHY_OIDC_NAME=Google. - Enable the
auth_timeclaim for the client. Google's OpenID Connect page says it providesauth_timewhen a request asks for it, which Mainworthy does when confirming it is somebody, and it is enabled in settings. Without it, nobody signed in through Google can confirm it is them, and only token sessions can make sign-in changes.
Google decides who may sign in to the client. Under Audience in the same console, choose the users of your Workspace organisation, or any Google account; an external client that is still in testing admits only the test users listed there. When Mainworthy sign-up is closed, it admits only an identity somebody invited or linked.
Clerk #
mainworthy.com signs in through Clerk, with an email address and password. To point your own instance at a
Clerk application:
- In Clerk's dashboard, open OAuth applications and add an application. Add
openidto its scopes besideemailandprofile: a new application starts without it, and every sign-in then fails withinvalid_scope. - Add the instance's public address followed by
/signin/oidcunder Redirect URIs. - Switch the application's Consent screen off when the application is your own, so people are not asked to approve their own instance.
- Set
MAINWORTHY_OIDC_ISSUERto the application's issuer (its Discovery URL without/.well-known/openid-configuration),MAINWORTHY_OIDC_CLIENT_IDandMAINWORTHY_OIDC_CLIENT_SECRETto its credentials, andMAINWORTHY_OIDC_NAMEto what the button should say. Clerk shows the secret once.
Keep Verify at sign-up on. Clerk joins a person's password and social sign-ins into one user by email
address, so enable only the social providers you trust to verify an address. Clerk sends auth_time without
further setting, and asks for the password again when Mainworthy confirms it is somebody.
Container network lockdown #
MAINWORTHY_LOCKDOWN=1 blocks new outbound network connections from Mainworthy. The ordinary image defaults
to 0; any other value refuses startup. Its entrypoint installs the policy before starting the app without capabilities.
Lockdown permits loopback, the configured database endpoint and replies to established connections.
Other new outbound connections are blocked, including external webhooks and identity providers.
Both Render Blueprints and the local Compose file leave lockdown unset and use the image's default of 0, which retains these integrations.
See the repository's docs/deploy.md for the Linux startup checks and the trusted-proxy boundary.