Security
DianaDB is built with security as a core requirement — every connection, request, and stored file is protected by design, not as an afterthought.
TLS / mTLS
Encrypt connections in transit between clients and the server. Optional mutual TLS lets the server verify client identity via certificates, for environments that require it. The ODM checks the server's certificate by default since 4.6.10. What the protocol does and does not protect without TLS is listed under Security properties.
Password never sent over the wire
Client and server prove to each other that they know the password with a salted challenge and response; the password itself is never transmitted. Every request and response is then encrypted with AES-256-GCM using a key made for that connection only. This works with or without TLS, so both can be layered for defense in depth.
Segregated access control
Grant fine-grained access per user and per database — read-only, write, or full management — so credentials only carry the permissions they actually need.
Private storage support
Store dumps and backups in a private S3-compatible bucket, keeping data isolated from public access rather than relying on local disk alone.
How authentication and request encryption work
1. Identify
Client sends its username and a random nonce. Server answers with the user's salt and its own nonce.
2. Prove
Client stretches the password with scrypt and the salt and sends a proof bound to both nonces. Server checks it and answers with its own proof, so the client knows the server is genuine too.
3. Session key
Both sides derive an AES-256-GCM key from the proof and the nonces. It is different for every connection, so recorded traffic can't be replayed on another one.
4. Encrypted requests and replies
Every request and response is encrypted with that key. A tampered or incorrectly-keyed line fails authentication and the server closes the connection.
The exact lines and formulas are in Client Protocol.
Salted credentials, not passwords
Since 4.6.5 diana-db add-user stores a random salt per user and two verifiers made from the password with scrypt, never the password. Users created by older versions keep working without any change. While legacy_auth is on, the file also keeps the unsalted key that clients older than 4.6.5 use.
Authenticated subscribers
A subscriber connection authenticates with the same handshake as any other connection and only receives updates of databases its user can read. Details
No document data in logs
Server logs record request metadata only — request id, user, action, database, collection, timing and error — never the documents or queries themselves.
Access checked first
Access rights are checked before a database is looked up, so a request can't create a database its user has no rights to. $lookup into another database needs read access to that database.
Hardened request parsing
Keys that reach an object's prototype (__proto__, constructor, prototype, …) are removed from every request at any depth, also when written with \u escapes; the rest of the request is processed. Nesting deeper than 256 levels is refused before the request is built. Field names are matched against the schema's own fields only.
Safe names
New databases are named with letters, digits, _ and - (1–128 characters). Collection, view, field and migration names can't contain quotes, brackets or control characters, or be a prototype key: such names would be unreadable in the dump.
Upgrading from 4.0
The handshake above is new in 4.6.5. Both sides still speak the earlier one, so server and clients can be upgraded in any order:
- ODM 4.6.5 falls back to the earlier handshake when the server is older than 4.6.5 and logs a warning. Pass
legacyAuth: false(or?legacyAuth=falsein a connection string) to refuse such servers. - Server 4.6.5 accepts clients older than 4.6.5 while
legacy_authis on, which is the default. Existing users work with both handshakes. - When every client is on 4.6.5 or newer, set
legacy_auth=0.
Between servers
Servers of a cluster authenticate each other with cluster_secret and encrypt their connections with a key made for each connection. A server with another secret, or with a server_id that is already in the cluster, is refused. The monitoring HTTP server listens on 127.0.0.1 unless configured otherwise and can require a token.
Access levels
Granted per user and database with diana-db grant-access -u <user> -db <db:level>.
| Level | Allows |
|---|---|
1 read | find, count, distinct, max, min, findByView, countByView, getCollectionNames, getCollectionSchema, getDatabases, getHealth, getVersion, subscriptions |
2 write | Everything in read, plus insert, insertMany, update, remove, createView (read was enough before 4.7.16), removeView, createCollection, transactions and migrations |
3 manage | Everything in write, plus createDatabase, removeDatabase, removeCollection, schema update, lock / unlock, getCollectionSchemaLock, getCollectionViews |