Lifecycle and security · Engineering

Auth: principals, scopes, mTLS, and lockout

A small auth model for a small database: tokens, per-database scopes, client certificates, reloads, and failed-login protection.

A database that runs next to an application still needs an auth model. It may not need LDAP, inherited roles, or a full identity provider, but it needs a way to say who can read which collection and how credentials are rotated.

NonoDB uses a file-based auth registry outside LMDB: principals, scopes, token hashes, certificate fingerprints, and failed-login state. Unix-socket requests authenticate as the local administrator. TCP requires a bearer token, a registered client certificate, or both.

Principals and scopes

A principal is a named identity. Its scopes are database-qualified and collection-qualified:

read:app1/orders
write:app1/orders
admin:app1
metrics:read

That is deliberately narrower than “user” and “role”. A per-database administrator sees only its own database. admin:db and *:* see the instance.

Authorization is checked per request, and batches are checked per operation before the write transaction starts. A wildcard scope works where documented.

Tokens

Tokens are stored as hashes. The secret is shown when created and never stored. A token can be revoked by editing the registry; the change is picked up without a daemon restart.

Use a separate token per application or environment. A shared administrator token for every worker makes revocation and audit useless.

Certificates and mTLS

TCP can require a registered client certificate, a bearer token, or both resolving to the same principal. Certificate fingerprints are stored in the registry.

TLS handshakes reject unregistered certificates. Every request re-resolves the certificate, so disabling an entry affects existing keep-alive connections too.

Mutual TLS is useful for service-to-service traffic where a token file is awkward to distribute. It does not remove the need to protect the private key.

Reload behavior

The daemon watches the auth file. A valid change is swapped in atomically; an invalid edit keeps the last known good registry.

That is a safety feature: a typo in the auth file should not lock everyone out. It also means a failed reload may leave the old permissions active until the file is fixed.

Database restores do not roll back revocations. The auth registry lives outside LMDB and is not part of database backups. That is intentional: restoring an old database should not resurrect a revoked token.

Failed-login lockout

The daemon tracks failed logins by IP. NONODB_AUTH_MAX_FAILURES defaults to 10; NONODB_AUTH_FAILURE_WINDOW defaults to 60 seconds. Set the maximum to 0 to disable lockout.

Lockout is a blunt instrument. It helps against online guessing but can be triggered by a misconfigured client. Monitor auth failures and keep a recovery path for the local Unix socket.

Audit

Optional JSONL audit records include request metadata and auth decisions, including denials. Audit logs are append-only and stored outside the database.

They do not contain document bodies by default, but they can contain collection names, operations, principals, and timing. Protect the audit file accordingly.

MongoDB wire authentication

The MongoDB listener has its own optional SCRAM configuration. Set both NONODB_MONGO_USERNAME and NONODB_MONGO_PASSWORD to require auth. NONODB_MONGO_PRINCIPAL maps the SCRAM account to an auth-file principal, whose scopes are enforced.

Without NONODB_AUTH_FILE, the configured MongoDB account retains instance-wide administrative access. Use loopback or a trusted network, and prefer the auth registry for anything exposed.

Client-certificate auth is not implemented for the MongoDB listener; use the native TCP/TLS path for mTLS.

A practical setup

  1. Run the daemon on a Unix socket for the local application.
  2. Give each service a token scoped to its database and collections.
  3. Use separate admin tokens for migration and operations.
  4. Enable TCP/TLS only when remote clients need it.
  5. Register client certificates for service-to-service mTLS.
  6. Keep the auth file outside the data directory and back it up separately.
  7. Test revocation and lockout recovery.

What is missing

  • No LDAP/AD integration.
  • No inherited roles or attribute-based access control.
  • No MongoDB user database.
  • No per-field permissions.
  • No external identity provider.

The model is intentionally small. It is enough for a single-node or primary/replica deployment, not a replacement for an enterprise IAM system.

The auth guide documents scopes, token creation, mTLS, reload behavior, lockout, and audit fields.

All engineering notes →Read the docs