Insufficient Logging in Cockroachdb
How Insufficient Logging Manifests in CockroachDB
Insufficient logging in CockroachDB typically appears when critical database operations are not recorded in the audit log or when the log level is too low to capture security‑relevant events. CockroachDB exposes an HTTP admin API (default port 8080) that accepts SQL statements, cluster‑setting changes, and node‑management commands. If audit logging is disabled, an attacker who gains access to this endpoint can execute privileged actions — such as creating new users, altering roles, or exporting data — without leaving a trace in crdb_internal.audit_events or the node logs.
Common attack patterns that exploit this gap include:
- Privilege escalation via role manipulation: An attacker sends a POST to
/_admin/v1/sqlwith a body like{"statements":["CREATE ROLE attacker; GRANT admin TO attacker;"]}. Without audit logging, the creation of the role and the grant are invisible. - Data exfiltration through SELECT … INTO: A malicious query such as
SELECT * FROM users INTO '/tmp/users.csv'can be issued via the admin API. If the audit log does not capture theINTOclause, the exfiltration goes unnoticed. - Cluster‑setting abuse: Changing
sql.audit.enabledto false or adjustinglog.file.max_sizeto a tiny value can be done through the HTTP endpoint, effectively silencing further logging.
These actions map to OWASP API8:2023 – Security Misconfiguration, where insufficient logging prevents detection of misuse. Real‑world incidents, such as the 2017 Equifax breach, showed that attackers remained undetected for weeks partly because critical database actions were not logged.
CockroachDB‑Specific Detection
Detecting insufficient logging in a CockroachDB deployment involves verifying that audit logging is enabled and that the log level captures authentication, authorization, and data‑definition events. Since middleBrick scans exposed HTTP endpoints, it can be pointed at the CockroachDB admin UI (e.g., http://) to assess whether the endpoint returns detailed error messages or exposes internal state that should be logged.
During a scan, middleBrick performs the following relevant checks:
- Input Validation – Sends malformed SQL payloads to the admin API and checks whether the response leaks stack traces or internal state without a corresponding audit entry.
- Authentication – Tests if the admin endpoint is accessible without credentials; if so, any action performed will not be tied to a user in the audit log.
- Data Exposure – Looks for responses that contain table schemas or query results that should have triggered an audit log entry for a
SELECToperation. - SSRF / Unsafe Consumption – Verifies that the admin API does not inadvertently allow forwarding requests to internal services, which could bypass logging.
If the scan returns findings such as "Admin API accessible without authentication" or "Error messages include SQL stack trace", the risk score will reflect a missing logging control. The report includes a severity rating and remediation guidance that points to enabling CockroachDB’s built‑in audit logging.
Example of a middleBrick CLI command that targets a CockroachDB admin endpoint:
middlebrick scan http://cockroach-db.example.com:8080
The output will contain a per‑category breakdown, including a "Logging & Monitoring" finding if audit logging is disabled.
CockroachDB‑Specific Remediation
Remediation focuses on activating and configuring CockroachDB’s native audit logging facility, which was introduced in version 20.2. The audit log writes to the crdb_internal.audit_events system table and can also be streamed to an external sink via the cockroach audit command.
Step‑by‑step fix:
- Enable audit logging at the cluster level:
SET CLUSTER SETTING sql.audit.enabled = true;
- Choose what to audit. By default, all DDL and DML statements are logged. You can narrow the scope to reduce storage overhead:
SET CLUSTER SETTING sql.audit.dml = false; -- disable DML auditing if needed
SET CLUSTER SETTING sql.audit.ddl = true; -- keep DDL auditing
- Configure log retention to prevent the audit table from growing unbounded:
SET CLUSTER SETTING sql.audit.rotation.minutes = 60; -- rotate every hour
SET CLUSTER SETTING sql.audit.retention.duration = '720h'; -- keep 30 days
- Restrict access to the admin HTTP API so that only trusted networks can reach it:
# Start CockroachDB with --http-allow=
cockroach start --http-allow=10.0.0.0/8 --join=...
- Verify that audit entries are being written:
SELECT * FROM crdb_internal.audit_events ORDER BY timestamp DESC LIMIT 10;
If you prefer external logging, you can pipe the audit table to a log aggregation system using a changefeed:
CREATE CHANGEFEED FOR TABLE crdb_internal.audit_events INTO 'kafka://broker:9092/audit-topic' WITH updated, resolved;
After enabling these settings, a rescan with middleBrick should show the "Logging & Monitoring" finding resolved, and the risk score will improve accordingly.
Frequently Asked Questions
Does middleBrick modify my CockroachDB configuration to enable audit logging?
Can I audit only specific schemas or tables in CockroachDB?
crdb_internal.audit_events table and filter the incoming events downstream in your log‑processing pipeline.