Authentication

This page describes how a client proves who it is on each wire, where passwords are stored, how the first superuser is created, and what slows down password guessing. For the operator summary per wire see Security, section 1.

The user store

Users are roles in the catalog table pg_authid, one record per role (source: src/catalog/system_tables.rs, AuthId).

Field Meaning
oid, rolname Role id and name
rolsuper Superuser; bypasses every privilege check
rolinherit Inherits privileges of roles it is a member of
rolcreaterole, rolcreatedb, rolreplication, rolbypassrls Role attributes
rolcanlogin May log in
rolconnlimit Stored; see "Gaps" below
rolpassword Argon2id PHC string, or none
rolvaliduntil Password expiry; see "Gaps" below
rolconfig, created_at, updated_at Per-role settings and timestamps

(source: src/catalog/system_tables.rs, AuthId)

Records are stored under these keys (source: src/catalog/system_tables.rs):

Key Content
__catalog::pg_authid::{oid} The role
__catalog::pg_authid_name::{name} Name to oid index
__catalog::pg_auth_members::{oid} A membership
__catalog::pg_auth_members_member::{member} Memberships by member

Per-wire verifier side records

Some wire protocols cannot check a password against an Argon2 hash because the client never sends the password. For those, the catalog keeps a second verifier per role (source: src/catalog/repository.rs, set_password_verifiers):

Key Verifier Used by
__catalog__:mysqlpw:{oid} * followed by hex of SHA1(SHA1(password)) MySQL mysql_native_password
__catalog__:scramsha256:{oid} SCRAM-SHA-256 salt, iteration count, StoredKey, ServerKey (bincode) MongoDB
__catalog__:oracle12c:{oid} Oracle 12C O5LOGON verifier Oracle

set_role_password writes the Argon2id hash into rolpassword and then writes all three side records (source: src/catalog/repository.rs, set_role_password). clear_password_verifiers removes them, including when a role is dropped (source: src/catalog/repository.rs, clear_password_verifiers).

A role whose password was set before the side records existed gets them on its next successful password login on any wire: verify_credential calls backfill_password_verifiers after a good password check (source: src/auth/wire_auth.rs, backfill_password_verifiers; test successful_login_backfills_missing_wire_verifiers).

PostgreSQL SCRAM uses a separate record, described under "PostgreSQL" below.

Password hashing

PasswordHasher::new() uses the argon2 crate with Argon2id, version 0x13, memory 65536 KiB, 3 iterations, parallelism 4, and a 32-byte output, and stores a PHC string. If those parameters are rejected it falls back to memory 19456 KiB, 2 iterations, parallelism 1 (source: src/auth/password.rs, PasswordHasher::new; tests test_hash_and_verify, test_different_passwords_different_hashes, test_is_valid_hash).

Verifier Construction Parameters Test
Argon2id PHC string m=65536, t=3, p=4 test_hash_and_verify
MySQL native * + HEX(SHA1(SHA1(pw))), sha1 crate none test_convenience_methods
SCRAM-SHA-256 (MongoDB) RFC 5802 / RFC 7677, password SASLprep'd with stringprep 28-byte salt, 15000 iterations (SCRAM_SHA256_ITERATIONS) scram_sha256_verifier_matches_rfc7677_example
SCRAM-SHA-256 (PostgreSQL) same, pbkdf2 + hmac + sha2 16-byte salt, 4096 iterations (DEFAULT_ITERATIONS) rfc7677_vector, full_exchange_and_record
Oracle 12C O5LOGON verifier 16-byte salt, 4096 rounds (ORACLE_12C_VGEN_COUNT) oracle_12c_verifier_matches_the_wire_derivation
MD5 md5_password_hash none test_md5_password_hash

(source: src/auth/password.rs; src/auth/scram.rs)

Not wired: The MD5 helpers md5_password_hash and verify_md5_password are used only by the unused PostgresAuthenticator (source: src/auth/password.rs; src/protocol/postgres/auth.rs, PostgresAuthenticator).

The verify cache

Argon2 is slow on purpose, so password checks go through verify_password_cached (source: src/auth/verify_cache.rs):

  • The key derivation runs on spawn_blocking, so it does not stall the async runtime.
  • A Semaphore limits concurrent derivations to the machine's available parallelism, with a minimum of 2 (4 if parallelism is unknown).
  • Identical concurrent checks share one derivation (single flight, through a DashMap of per-key mutexes).
  • Results are kept in an lru cache of 8192 entries: successes for 30 s, failures for 2 s.
  • The cache key is SHA-256 over a per-process random salt and the length-prefixed user name, stored hash and password, so the cache never holds a password in clear.

(source: src/auth/verify_cache.rs, CACHE_CAPACITY, SUCCESS_TTL, FAILURE_TTL; tests correct_and_wrong_passwords, concurrent_identical_credentials_single_flight (128 concurrent checks cause at most 8 derivations), cache_serves_repeat_without_kdf)

Because a success is cached for 30 s, a password change can take up to 30 s to stop an old password from working on a wire that uses the cache. Not verified: no test covers a password change inside the success window (source: src/auth/verify_cache.rs, SUCCESS_TTL).

Superuser bootstrap

On first start, BootstrapConfig::from_env and run create the first superuser (source: src/catalog/bootstrap.rs).

Input Effect
SYNERGYDB_SUPERUSER Superuser name, default postgres
SYNERGYDB_SUPERUSER_PASSWORD Password used as given
SYNERGYDB_ADMIN_PASSWORD Used when SYNERGYDB_SUPERUSER_PASSWORD is not set
SYNERGYDB_DATABASE First database, default synergydb
SYNERGYDB_NON_INTERACTIVE Never prompt
--dev Sets a fixed, well-known superuser password, turns on non-interactive mode, binds to loopback unless --bind-all

(source: src/catalog/bootstrap.rs, BootstrapConfig::from_env; src/main.rs, async_main)

flowchart TD A["Start"] --> B{"Already bootstrapped?"} B -- yes --> Z["Skip"] B -- no --> C{"Password in environment?"} C -- yes --> F["Use it as given"] C -- no --> D{"Interactive TTY?"} D -- yes --> E["Prompt, check with validate_password"] D -- no --> G["Generate 24 characters, write initial_superuser_password"] E --> H["Create superuser with set_role_password"] F --> H G --> H H --> I["Create database, schemas, default roles"] I --> J["Mark bootstrapped"]

(source: src/catalog/bootstrap.rs, run)

Details:

  • A typed password must be at least 8 characters and must not equal the user name (source: src/catalog/credentials.rs, MIN_PASSWORD_LEN, validate_password; tests short_passwords_are_rejected, password_equal_to_user_name_is_rejected).
  • A generated password is 24 alphanumeric characters from OsRng. It is written to initial_superuser_password in the data directory with mode 0600 and an fsync before the role is created, and is never printed (source: src/catalog/credentials.rs, INITIAL_PASSWORD_FILE; tests generated_passwords_are_long_alphanumeric_and_distinct, initial_password_file_holds_the_password_and_overwrites_stale_ones, non_interactive_first_boot_generates_a_password_not_a_known_or_empty_one).
  • On non-Unix systems the file mode is not set; the file relies on the data directory's ACL (source: src/catalog/credentials.rs).
  • A password from the environment is used as given and no file is written (source: src/catalog/bootstrap.rs; test configured_password_is_used_as_given_and_no_file_is_written).
  • Bootstrap also creates the pg_catalog and public schemas, the per-protocol schemas, and the roles pg_read_all_data, pg_write_all_data, pg_database_owner, pg_signal_backend and pg_monitor (source: src/catalog/bootstrap.rs, run).
  • At start, the server exits with a fatal error if the superuser password is one of a short list of placeholders such as CHANGE_ME or changeme (source: src/main.rs, async_main). The dev default used by --dev is not on that list.

Shared login path

Most wires call into src/auth/wire_auth.rs (source: src/auth/wire_auth.rs).

verify_credential(storage, legacy, user, password):

  1. Looks the role up in the catalog.
  2. A role without LOGIN, without a password, or a catalog read error spends a dummy Argon2 verify against DUMMY_HASH and returns false, so the response time does not reveal which case applied.
  3. Otherwise checks the password through the verify cache. On success, backfills the wire verifiers.
  4. A name not in the catalog is checked against an optional per-wire legacy map; with no map it fails.
  5. Calls note_auth_result, which feeds the failed-login delay and writes an audit login record.

(source: src/auth/wire_auth.rs, verify_credential, verify_credential_unthrottled, note_auth_result)

verify_wire_credential(wire, ...) adds the wire-role check described in Authorization (source: src/auth/wire_auth.rs, verify_wire_credential).

Failed-login delay

After repeated failures for the same user name, the next check is delayed (source: src/auth/wire_auth.rs, auth_failure_delay):

Constant Value
FREE_AUTH_FAILURES 5 failures without delay
AUTH_FAILURE_WINDOW 600 s
Delay 200 ms doubled per further failure, at most 8 doublings
MAX_AUTH_DELAY 5 s
MAX_TRACKED_AUTH_NAMES 16384

The key is the lower-cased user name, a success clears it, and a warning is logged at the sixth failure and every hundredth after (source: src/auth/wire_auth.rs; tests delay_starts_after_free_failures_and_is_capped, success_clears_the_count).

The delay applies only to wires that go through note_auth_result. MySQL does not: it uses the per-IP rate limiter instead (source: src/protocol/mysql/mod.rs; see Audit and limits).

Protected mode

[server] protected_mode (default true) sets PROTECTED_MODE. protected_mode_refuses(open_without_password, peer) refuses a connection when the wire would accept it without a password and the peer is not loopback (IPv4, IPv6 or IPv4-mapped) (source: src/auth/wire_auth.rs, protected_mode_refuses, is_loopback; test protected_mode_only_refuses_open_remote_connections).

At start, on a non-loopback bind, the server exits with a fatal error if SYNERGYDB_DEV_INSECURE_AUTH or SYNERGYDB_TEST_AUTH_CHEAP is set while protected mode is on, unless SYNERGYDB_ALLOW_INSECURE_BIND is set (source: src/main.rs, async_main).

Developer switches

Variable Effect
SYNERGYDB_DEV_INSECURE_AUTH = 1 or true Opens several wires without login (Redis, Memcached, SQLite Hrana, Cassandra, Kafka, HTTP Basic paths) and enables a MySQL legacy user map
SYNERGYDB_TEST_AUTH_CHEAP On Redis, any credential passes

(source: src/auth/wire_auth.rs, dev_insecure_auth_enabled; src/protocol/redis/commands.rs; src/protocol/mysql/auth.rs)

Per wire

Wire Mechanism Credential check Source
PostgreSQL SCRAM-SHA-256, else cleartext password message Catalog src/protocol/postgres/mod.rs
MySQL mysql_native_password; caching_sha2_password full auth only Catalog plus side record src/protocol/mysql/auth.rs
MongoDB SCRAM-SHA-256 only Catalog side record, Mongo users, env-seeded users src/protocol/mongodb/commands.rs
Redis AUTH, HELLO AUTH, Redis 8 ACL users requirepass, ACL users, catalog src/protocol/redis/commands.rs
Cassandra SASL PasswordAuthenticator verify_credential src/protocol/cassandra/
Kafka SASL PLAIN verify_wire_credential("kafka") src/protocol/kafka/
Oracle O5LOGON Oracle 12C side record src/protocol/oracle/
SQL Server LOGIN7 verify_credential src/protocol/mssql/
S3, DynamoDB AWS SigV4 src/auth/aws_keys.rs src/protocol/s3/, src/protocol/dynamodb/
HTTP-based wires HTTP Basic authorize_http_basic_for(wire) src/auth/wire_auth.rs
Memcached SASL or auth file verify_wire_credential("memcached") src/protocol/memcached/
SQLite Hrana HTTP Basic, or Bearer carrying user:password verify_wire_credential("sqlite") src/protocol/sqlite/hrana.rs
gRPC, Arrow Flight Interceptor verify_credential src/protocol/grpc/, src/protocol/arrow/

Wires that call verify_wire_credential (and so need a wire role): Prometheus, CouchDB, Redis, Gremlin, InfluxDB, Kafka, SQLite, Memcached, Elasticsearch. Wires that call plain verify_credential: gRPC, Redis, SQL Server, Oracle, Snowflake, Arrow, ClickHouse native and HTTP, Cassandra, Bolt, the HTTP API, Prometheus, InfluxDB, Gremlin. Some wires appear in both lists because different entry points use different calls (source: grep of verify_wire_credential and verify_credential callers under src/protocol/).

PostgreSQL

sequenceDiagram participant C as Client participant S as Server C->>S: StartupMessage (user) alt SCRAM enabled and role has a stored verifier S->>C: AuthenticationSASL SCRAM-SHA-256 C->>S: client-first S->>C: server-first (salt, iterations, nonce) C->>S: client-final (proof) S->>C: server-final, AuthenticationOk else unknown or non-login role S->>C: SCRAM with mock_verifier, always fails else no stored verifier yet S->>C: AuthenticationCleartextPassword C->>S: PasswordMessage S->>S: verify_password_cached, then store_scram_verifier S->>C: AuthenticationOk end

(source: src/protocol/postgres/mod.rs, scram_exchange; src/auth/scram.rs)

  • SCRAM is on unless SYNERGYDB_PG_SCRAM is 0, false, off or no (source: src/protocol/postgres/mod.rs, scram_enabled).
  • The verifier is stored under __auth__:scram:<user> as a tag followed by SCRAM-SHA-256$iter:salt$StoredKey:ServerKey. The tag is base64 of the first 16 bytes of SHA-256 of the role's Argon2 hash, compared in constant time with subtle, so a password change invalidates the old SCRAM verifier (source: src/auth/scram.rs, password_tag).
  • A role with a password but no SCRAM verifier logs in once with a cleartext password message; the server then stores a SCRAM verifier, but only on a single node or on the cluster leader (source: src/protocol/postgres/mod.rs, store_scram_verifier).
  • For an unknown user, a non-login role or a role without a password, the server runs SCRAM against mock_verifier, which derives a stable fake salt from a per-process secret, so the exchange looks the same as for a real user (source: src/auth/scram.rs, mock_verifier).
  • ServerExchange::start accepts GS2 flags n and y and refuses p=: there is no channel binding (source: src/auth/scram.rs, ServerExchange::start). finish checks the channel-binding echo and nonce, then the proof in constant time (source: src/auth/scram.rs, ServerExchange::finish; tests rfc7677_vector, full_exchange_and_record).

Not wired: PostgresAuthConfig defaults to development(), which is Trust, but nothing reads it. Its doc comment says SCRAM is incompatible with Argon2; the code above shows otherwise (source: src/protocol/postgres/auth.rs, PostgresAuthConfig).

MySQL

  • verify_auth_response first checks the per-IP rate limiter, then looks the user up in the catalog. An unknown user is rejected, except under SYNERGYDB_DEV_INSECURE_AUTH, which enables a hard-coded legacy user map (source: src/protocol/mysql/auth.rs, verify_auth_response).
  • It checks rolcanlogin and rolvaliduntil, returning ER_PASSWORD_EXPIRED for an expired password. MySQL is the only wire that checks expiry (source: src/protocol/mysql/auth.rs).
  • verify_native_password uses the __catalog__:mysqlpw side record, then a * hash stored in rolpassword. Argon2 candidate probing is used only under the dev flag (source: src/protocol/mysql/auth.rs, verify_native_password).
  • If a LOGIN role has no password and the client sends an empty auth response, the login succeeds (source: src/protocol/mysql/auth.rs, verify_native_password). Not verified: no test covers this case.
  • caching_sha2_password is accepted only as full authentication with the password sent in clear, checked against Argon2; the fast-auth path is not implemented (source: src/protocol/mysql/auth.rs, verify_caching_sha2).
  • MySqlAuthConfig defaults to NativePassword (source: src/protocol/mysql/auth.rs, MySqlAuthConfig).
  • The test auth_reply_after_ssl_request_uses_sequence_three covers the login reply after a TLS upgrade (source: src/protocol/mysql/mod.rs).

MongoDB

  • Only SCRAM-SHA-256 is accepted; SCRAM-SHA-1 is refused (source: src/protocol/mongodb/commands.rs).
  • Credentials come from the catalog SCRAM side record, gated by wire_access_allowed("mongodb") (source: src/protocol/mongodb/commands.rs, catalog_scram_credentials), from MongoDB users stored as __mongouser__:<db>.<user> (source: src/protocol/mongodb/users.rs), or from users seeded from the environment: MONGODB_ADMIN_USER with MONGODB_ADMIN_PASSWORD, SYNERGYDB_SUPERUSER_PASSWORD, and MONGODB_TENANT_USERS in the form user:password:db1,db2 (source: src/protocol/mongodb/commands.rs).
  • The env-seeded superuser is named by SYNERGYDB_SUPERUSER, default synergy. Bootstrap's default for the same variable is postgres (source: src/protocol/mongodb/commands.rs; src/catalog/bootstrap.rs).
  • A logged-in user with no MongoDB user record has full access (source: src/protocol/mongodb/users.rs).

Redis

  • A connection starts unauthenticated unless SYNERGYDB_DEV_INSECURE_AUTH is set; before login only AUTH, HELLO, QUIT and RESET are allowed (source: src/protocol/redis/commands.rs, requires_auth; tests test_no_password_configured_fails_closed, test_requirepass_gates_commands_until_auth).
  • SYNERGYDB_REDIS_REQUIREPASS is compared in constant time (source: src/protocol/redis/commands.rs, configured_requirepass; test test_requirepass_hello_auth_and_reset).
  • The legacy credential map is empty (source: src/protocol/redis/commands.rs; test demo_credentials_are_not_a_backdoor).
  • Redis 8 ACL users are stored as __redisacl__:<name>; their password hash is unsalted SHA-256 hex, as Redis itself stores it (source: src/protocol/redis/commands/acl.rs, hash_password). An ACL default user with a password, or disabled, forces login on new connections (test acl_default_user_with_password_locks_new_connections).
  • Protected mode is checked at connect (source: src/protocol/redis/mod.rs).

The doc comments on configured_requirepass and on the requirepass field still describe an open default; the code fails closed (source: src/protocol/redis/commands.rs).

Other wires

Wire Default Source
Kafka SASL required unless [server] kafka_require_sasl is false or SYNERGYDB_DEV_INSECURE_AUTH is set src/server/mod.rs; test kafka_metadata_without_sasl_is_refused_by_default
Cassandra Auth required unless SYNERGYDB_DEV_INSECURE_AUTH is set (require_auth) src/protocol/cassandra/mod.rs
Memcached LocalOnly: loopback open, others must log in. SYNERGYDB_MEMCACHED_AUTH = users/sasl/on/required/true/1 requires login everywhere; open/off/none/no/false/0 opens it. SYNERGYDB_MEMCACHED_AUTH_FILE selects file mode; a read failure fails closed src/protocol/memcached/, AuthMode
Schema Registry LocalOnly unless SYNERGYDB_SCHEMA_REGISTRY_AUTH says otherwise src/protocol/schema_registry/, SrAuth
SQLite Hrana LocalOnly unless SYNERGYDB_SQLITE_AUTH says otherwise src/protocol/sqlite/hrana.rs, AuthPolicy
HTTP API SYNERGYDB_API_KEY, SYNERGYDB_METRICS_TOKEN, loopback checks src/protocol/http/routes.rs

decode_basic_authorization matches the Basic scheme case-insensitively, accepts unpadded base64, and splits on the first colon so passwords may contain colons (source: src/auth/wire_auth.rs; tests decodes_basic_credentials, password_may_contain_colons, scheme_matches_case_insensitively, other_schemes_and_garbage_are_rejected). With no Authorization header, authorize_http_basic_for allows the request only under the dev flag (source: src/auth/wire_auth.rs, authorize_http_basic_for).

The pre-auth gate

tests/wire_preauth_gate.rs checks that wires do not run commands before login. Each test seeds a secret marker, opens a raw socket that skips the login handshake, sends a command, and asserts the marker never appears in the reply. require_production_auth clears the dev flag first (source: tests/wire_preauth_gate.rs).

Test Wire Expected
mssql_sql_batch_without_login7_is_refused SQL Server Refused
mssql_insert_without_login7_does_not_write SQL Server No write
mssql_sql_batch_after_failed_login_is_refused SQL Server Refused
oracle_ttc_execute_before_o5logon_is_refused Oracle ORA-01012
oracle_ttc_fetch_before_o5logon_is_refused Oracle Refused
schema_registry_rejects_unauthenticated_requests Schema Registry, with auth users 401 for GET, POST, DELETE and a bad credential
kafka_metadata_without_sasl_is_refused_by_default Kafka Connection closed, no reply
clickhouse_native_query_without_hello_is_refused ClickHouse native Refused
clickhouse_native_ddl_without_hello_does_not_run ClickHouse native DDL not run
couchdb_rejects_unauthenticated_requests CouchDB 401; no _admin role; /_up stays 200
mongodb_gate::collstats_is_refused_unauthenticated and two siblings MongoDB Code 13
mongodb_gate::handshake_commands_still_work_unauthenticated MongoDB hello, ping, buildInfo, whatsmyuri work

(source: tests/wire_preauth_gate.rs)

MongoDB allows a fixed list of commands before login, including hello, isMaster, saslStart, saslContinue, ping, buildInfo, serverStatus, listDatabases and the session-kill commands. Other commands need a login, and database-scoped commands also pass check_database_access; refusals use code 13 (source: src/protocol/mongodb/commands.rs, allowed_preauth). Setting MONGODB_ENFORCE_DB_ACCESS to false turns these checks off, which allows unauthenticated access (source: src/protocol/mongodb/commands.rs).

Gaps

  • VALID UNTIL is accepted by ALTER ROLE but not stored; pg_authid reports it as NULL. Only MySQL reads rolvaliduntil, so password expiry is not enforced on any wire in practice (source: src/query/engine.rs, apply_role_options; src/protocol/mysql/auth.rs).
  • rolconnlimit is stored but never enforced (source: src/query/engine.rs, apply_role_options).
  • The PostgreSQL path does not consult SYNERGYDB_DEV_INSECURE_AUTH (source: src/protocol/postgres/mod.rs).
  • A name that authenticated outside the catalog (for example an env-seeded or file user) becomes a superuser session; see Authorization (source: src/auth/session.rs, resolve_from_catalog).
  • No wire maps a TLS client certificate to a user; see TLS (source: src/protocol/tls.rs).