Audit and Limits
This page covers the audit trail (what is recorded, how the file is chained and verified) and the limits that protect the server from abusive clients: the authentication rate limiter, buffer limits, timeouts and connection pools. For the operator summary of auditing see Security, section 5.
Audit trail
Turning it on
[audit] maps to AuditConfigFile (source: src/config.rs, AuditConfigFile).
| Key | Default | Meaning |
|---|---|---|
enabled |
false | Start the audit logger |
path |
none; required when enabled | Active segment, JSONL |
log_success |
true | Record successful actions |
log_failure |
true | Record failed and denied actions |
key_file |
none | File holding the 64-hex-character HMAC key |
require_key |
false | Refuse to start without a key |
retention_days |
2190 (6 years); 0 keeps forever | Prune rotated segments older than this |
rotate_mb |
256 | Rotate the active segment at this size |
checkpoint_secs |
3600; 0 turns off | Interval between checkpoint records |
log_statement |
true | Record SQL text |
log_parameters |
true | Record bound parameter values |
(source: src/config.rs, AuditConfigFile, default_audit_retention_days, default_audit_rotate_mb, default_audit_checkpoint_secs)
start_audit_logger reads the key from SYNERGYDB_AUDIT_KEY first, then from key_file. Without a key it either refuses to start (require_key) or logs a warning and writes an unkeyed SHA-256 chain. It then opens the chain writer, installs the logger process-wide, and writes a DATABASE_STARTUP record holding the version, process id, whether the chain is keyed, the key id, the retention and the previous chain head (source: src/server/mod.rs, start_audit_logger). SYNERGYDB_AUDIT_KEY is excluded from the generic SYNERGYDB_AUDIT_<KEY> config overrides (source: src/config.rs).
At shutdown the server writes a DATABASE_SHUTDOWN record and waits up to 10 s for the queue to drain with flush_blocking (source: src/server/mod.rs).
What is recorded
Each AuditEvent has: event_id, event_time, event_type, result, wire, user_oid, username, session_id, client_addr, database, schema, object_type, object_name, action, details, error_message (source: src/auth/audit.rs, AuditEvent). result is one of Success, Failure, Denied, Filtered (source: src/auth/audit.rs, AuditResult).
| Source of records | What it records | Source |
|---|---|---|
| SQL engine | One record per top-level statement for a session: event type from the plan (role and grant changes, policy changes, schema changes, table reads and writes, other queries), objects touched, statement text up to 8192 characters, up to 64 parameters of up to 256 characters each, duration |
src/query/engine.rs, execute, emit_audit_event
|
| Login | Success and failure per wire through record_login; a repeated successful login by the same user on one connection is recorded once |
src/auth/audit.rs, record_login; src/auth/wire_auth.rs, note_auth_result
|
| Non-SQL wires |
audit::access(kind, action, object) builder: record counts, up to 100 ids of up to 256 characters, outcome |
src/auth/audit.rs, access, AccessRecord
|
| HTTP wires |
http_access; 401 and 403 are recorded as Denied; OPTIONS and object-less GET requests are skipped |
src/auth/audit.rs, http_access
|
Wires that emit access or record_login records directly: Bolt, CouchDB, DynamoDB, Elasticsearch, Gremlin, the HTTP API, InfluxDB, Kafka, Memcached, MongoDB, MySQL, Prometheus, Redis, S3, Schema Registry (source: callers of audit::access, audit::http_access and record_login under src/protocol/). Wires that use the SQL engine are recorded by the engine.
Each connection runs inside audit::in_connection(wire, peer, ...), a task-local that supplies the wire and client address to every record (source: src/auth/audit.rs, in_connection, ConnContext). An empty user name is recorded as (unauthenticated) (source: src/auth/audit.rs, UNAUTHENTICATED). Error messages are cut at 500 characters (source: src/auth/audit.rs, truncate_chars).
AccessRecord::outcome classifies an error as Denied when its message contains text such as "permission denied", "not authorized" or "noperm"; other errors are Failure (source: src/auth/audit.rs, outcome).
The engine records a statement only when a session is attached (source: src/query/engine.rs, auditing). A sessionless engine, such as the one an anonymous loopback SQLite Hrana stream gets, writes no statement records (source: src/protocol/sqlite/hrana.rs). Not verified: no test checks for the absence of those records.
Filtering
should_log always records mandatory events. Others are dropped when their result is excluded by log_success or log_failure, or when an event-type filter is set and does not include them (source: src/auth/audit.rs, should_log). The server always installs an empty event-type filter (source: src/server/mod.rs, start_audit_logger).
Mandatory events (source: src/auth/audit.rs, is_mandatory; test test_audit_event_type_mandatory):
| Event |
|---|
| LoginFailure |
| PermissionDenied |
| RoleCreate |
| RoleDrop |
| SuperuserAction |
| DatabaseStartup |
| DatabaseShutdown |
| AuditTrailRecovered |
| AuditRetentionPrune |
| AuditCheckpoint |
Write path
(source: src/auth/audit.rs, AuditLogger::new; src/auth/audit_chain.rs)
-
AuditLogger::newuses acrossbeam-channelunbounded channel and a dedicatedaudit-writerthread that takes batches of up to 4096 events (source:src/auth/audit.rs,AuditLogger::new). - Each batch is one write followed by
fdatasync(source:src/auth/audit_chain.rs). - On a write error the writer keeps the pending events, sets
failing, logs once and retries every second. Events are not dropped and the database keeps serving; there is no fail-closed mode (source:src/auth/audit.rs,AuditLogger::new; testlogger_never_drops_and_flushes_in_order). - Because the channel is unbounded, events accumulate in memory while the disk is failing (source:
src/auth/audit.rs). - A one-second tick drives checkpoints and retention (source:
src/auth/audit.rs). -
AuditStatsreports queued, written and failing (source:src/auth/audit.rs,AuditStats).
The record is written after the client has its reply, so a crash in between can lose the record of an acknowledged action. The guide states the same from the status entries (Security, section 5).
Chain format
Each line is one JSON object (source: src/auth/audit_chain.rs):
| Field | Content |
|---|---|
seq |
Sequence number, contiguous across segments |
ts |
RFC 3339 time with microseconds (chrono) |
alg |
hmac-sha256 with a key, else sha256
|
kid |
First 8 hex characters of SHA-256 of the key |
prev_hash |
Hash of the previous record; 64 zeros (GENESIS_HASH) for the first |
| event fields | The flattened AuditEvent
|
hash |
HMAC-SHA256 or SHA-256 over the line before this field |
(source: src/auth/audit_chain.rs; test intact_chain_verifies, reopen_continues_the_chain, file_writer_chains_and_verifies)
Without a key, anyone who can write the file can rewrite it and recompute every hash; with a key, a forgery fails verification (source: src/auth/audit_chain.rs; test hmac_chain_needs_the_key_and_rejects_a_forgery).
| Behaviour | Detail | Test |
|---|---|---|
| Rotation | At rotate_mb or when the UTC day changes; segment named <path>.<first seq, 20 digits>
|
rotation_keeps_one_chain |
| Retention | Segments older than retention_days are deleted and an AUDIT_RETENTION_PRUNE record is written |
retention_prunes_old_segments_and_records_it, six_year_default_retention_keeps_five_year_old_segments
|
| Torn tail | A partial last line after a crash is cut and an AUDIT_TRAIL_RECOVERED record is written |
torn_tail_is_recovered_and_recorded |
| Tampering | Edited, deleted and reordered records are detected |
edited_record_is_detected, deleted_record_is_detected, reordered_records_are_detected
|
| Missing old segment | Deleting the oldest segment without a prune record is detected | deleting_the_oldest_segment_outside_retention_is_caught |
| Permissions | Files 0600, directory 0700, closed segments 0400 | none found |
(source: src/auth/audit_chain.rs, DEFAULT_ROTATE_BYTES, DEFAULT_RETENTION_DAYS)
synergydb audit
| Command | Effect |
|---|---|
synergydb audit verify [-c FILE] [--path LOG] [--json] [--expect-head SEQ:HASH] |
Reads every segment and the active file; checks each hash, each link, contiguous sequence numbers, and that segments missing at the start were removed by a recorded prune. --expect-head checks that a record noted earlier is still present, which catches a trail cut short at the end. Read-only |
synergydb audit generate-key |
Prints a new random 256-bit key (64 hex characters) and its key id |
Exit status of verify: 0 intact, 2 tampering or damage found, 3 could not read the trail or key (source: src/audit_cmd.rs, print_help, verify). verify_chain reports at most 50 errors (source: src/auth/audit_chain.rs, verify_chain). Not verified: src/audit_cmd.rs has no tests of its own; the chain checks it calls are tested in src/auth/audit_chain.rs.
The help text points to docs/security/hipaa-audit.md, which is not in the reviewed snapshot (source: src/audit_cmd.rs).
Authentication rate limiter
AuthRateLimiter counts failed logins per client IP (source: src/protocol/rate_limiter.rs).
| Setting | Default |
|---|---|
max_attempts |
100 failures per window |
window_secs |
60 |
lockout_secs |
60 |
max_tracked_ips |
10000 |
(source: src/protocol/rate_limiter.rs, RateLimiterConfig::default)
-
check_allowed(ip)refuses while the IP is locked out, and starts a lockout when the count has reachedmax_attempts(source:src/protocol/rate_limiter.rs,check_allowed). -
record_failure(ip)counts within the window and logs a warning when the lockout starts (source:src/protocol/rate_limiter.rs,record_failure). -
record_success(ip)deletes the IP's entry, so one successful login from an address clears all failures from that address (source:src/protocol/rate_limiter.rs,record_success). - When the map reaches
max_tracked_ips, entries older than two windows and not locked out are removed (source:src/protocol/rate_limiter.rs,cleanup_old_entries). - Tests:
test_rate_limiter_allows_under_threshold,test_success_resets_count(source:src/protocol/rate_limiter.rs).
The defaults carry the code comments "Increased for testing" and "Reduced lockout for testing". init_global_rate_limiter has no caller, so the global limiter always uses these defaults (source: src/protocol/rate_limiter.rs, global_auth_rate_limiter, init_global_rate_limiter).
Callers of global_auth_rate_limiter():
| Caller | Use |
|---|---|
| MySQL login | Check, record failure, record success |
HTTP Studio login (studio_login) |
Check, record failure, record success |
PostgresAuthenticator |
Not wired (see README) |
(source: src/protocol/mysql/auth.rs, verify_auth_response; src/protocol/http/routes.rs, check_http_rate_limit; src/protocol/postgres/auth.rs)
Other wires use the per-user failed-login delay instead; see Authentication. The encryption proxy has its own limiters in src/proxy/rate_limit.rs and src/proxy/query_rate_limit.rs; see Encryption proxy.
Buffer limits
BufferLimits holds per-connection size limits (source: src/protocol/buffer_limits.rs, BufferLimits).
| Limit | Default | restricted() |
large() |
|---|---|---|---|
max_message_size |
256 MiB | 16 MiB | 512 MiB |
max_query_length |
16 MiB | 1 MiB | 32 MiB |
max_parameters |
65535 | 10000 | 100000 |
max_columns |
1600 | 500 | 4000 |
max_rows_per_batch |
100000 | 10000 | 500000 |
max_string_length |
1 MiB | 256 KiB | 4 MiB |
max_blob_size |
64 MiB | 4 MiB | 128 MiB |
max_header_size |
8 KiB | 4 KiB | 16 KiB |
(source: src/protocol/buffer_limits.rs, DEFAULT_MAX_*, restricted, large; tests test_default_limits, test_restricted_limits, test_large_limits, test_check_message_size, test_check_query_length, test_check_parameter_count, test_builder_pattern, test_error_display)
Where the limits are enforced:
| Wire | Checks | Source |
|---|---|---|
| PostgreSQL | Message size, query length | src/protocol/postgres/mod.rs |
| MySQL | Packet size | src/protocol/mysql/mod.rs |
| MongoDB | Message size | src/protocol/mongodb/mod.rs |
| Redis | Inline line length (max_query_length), multibulk count (max_parameters), total command size, each bulk string (max_string_length) |
src/protocol/redis/mod.rs, read_command
|
| Bolt | Its own cap, MAX_BOLT_MESSAGE_SIZE 16 MiB |
src/protocol/bolt/mod.rs |
The handlers always use BufferLimits::default(): with_buffer_limits exists on each handler but the server never calls it, and there is no config key for these limits (source: src/protocol/*/mod.rs, with_buffer_limits; src/server/mod.rs).
On Redis this means a single bulk string longer than 1 MiB is refused with ERR Protocol error: invalid bulk length (source: src/protocol/redis/mod.rs, read_command; src/protocol/buffer_limits.rs, DEFAULT_MAX_STRING_LENGTH). Not verified: no test sends a value over 1 MiB to the Redis wire.
Errors map to each wire's own codes, for example SQLSTATE 54000 on PostgreSQL, ER_NET_PACKET_TOO_LARGE (1153) on MySQL, and code 10334 on MongoDB (source: src/protocol/buffer_limits.rs).
Pre-auth body limit
HTTP-style wires read at most PREAUTH_BODY_LIMIT (1 MiB) of a request body before the request's credentials are checked. A larger declared body from an unauthenticated client gets a raw 401 Unauthorized with Connection: close (PREAUTH_REFUSAL) (source: src/protocol/buffer_limits.rs, PREAUTH_BODY_LIMIT, PREAUTH_REFUSAL). Wires that apply it: CouchDB, InfluxDB, ClickHouse HTTP, DynamoDB, Elasticsearch, Snowflake (source: callers of PREAUTH_BODY_LIMIT under src/protocol/). Not verified: tests/wire_preauth_gate.rs does not send an oversized body.
Timeouts
TimeoutConfig holds four durations (source: src/protocol/timeout.rs, TimeoutConfig).
| Field | Default | aggressive() |
relaxed() |
|---|---|---|---|
connect_timeout |
30 s | 5 s | 60 s |
read_timeout |
60 s | 10 s | 120 s |
write_timeout |
60 s | 10 s | 120 s |
idle_timeout |
300 s | 30 s | 600 s |
(source: src/protocol/timeout.rs; tests test_default_config, test_aggressive_config, test_relaxed_config, test_custom_config)
| Wire | Uses | Source |
|---|---|---|
| PostgreSQL |
read_timeout for the startup message and after an SSL decline |
src/protocol/postgres/mod.rs |
| MySQL |
read_timeout per packet header, write_timeout, idle_timeout
|
src/protocol/mysql/mod.rs |
| MongoDB |
read_timeout per message header, idle_timeout
|
src/protocol/mongodb/mod.rs |
| Redis |
read_timeout per command, write_timeout, idle_timeout except in subscriber mode |
src/protocol/redis/mod.rs |
| Oracle |
connect_timeout, idle_timeout, read_timeout, write_timeout
|
src/protocol/oracle/mod.rs |
On MySQL, MongoDB and Redis, a read that times out closes the connection. Each read waits at most read_timeout (60 s), so with the defaults a client that sends nothing for 60 s is disconnected before the 300 s idle timeout is reached (source: src/protocol/mysql/mod.rs; src/protocol/mongodb/mod.rs; src/protocol/redis/mod.rs). Not verified: no test holds an idle connection open past 60 s.
As with buffer limits, handlers use TimeoutConfig::default() and the server does not call with_timeout_config (source: src/server/mod.rs).
Not wired: TimeoutStream and TimeoutAcceptor, the stream wrapper and acceptor in the same file, have no callers outside the module (source: src/protocol/timeout.rs, TimeoutStream, TimeoutAcceptor).
Connection pools and connection counts
Not wired: src/protocol/pool.rs provides a generic async ConnectionPool (defaults: 2 to 10 connections, 30 s acquire timeout, 600 s idle, 3600 s lifetime, 30 s health check, validate on borrow), with tests test_basic_pool_operations, test_pool_respects_max_connections, test_pool_statistics, test_try_get, test_connection_deref. Nothing outside the module uses it (source: src/protocol/pool.rs, PoolConfig::default).
The encryption proxy has a separate, used pool in src/proxy/pool.rs; see Encryption proxy.
The server has no limit on the number of client connections. max_connections is reported as 100 by the PostgreSQL catalog and 151 by MySQL SHOW VARIABLES, and Redis CONFIG GET maxclients reports 10000, but none of these is enforced (source: src/protocol/postgres/catalog.rs; src/protocol/mysql/session_vars.rs; src/protocol/redis/commands.rs). The per-role rolconnlimit is not enforced either (source: src/query/engine.rs, apply_role_options). Connection handling is described in Server runtime.