After you enable security auditing, you must set specific security auditing rules to audit user operations.
Set a log strategy
You can set the auditing log strategy by using the audit_log_strategy configuration item. Valid values are ASYNCHRONOUS, PERFORMANCE, and SYNCHRONOUS. Choose a log strategy based on your business needs to balance performance and log integrity.
ASYNCHRONOUS: Writes logs asynchronously. When the buffer is full, the system waits for the buffer to be synchronized. This is the default strategy.PERFORMANCE: Writes logs asynchronously. When the buffer is full, data is discarded.SYNCHRONOUS: Writes logs synchronously.
For example, to set the auditing log write strategy to asynchronous mode (with synchronous wait when the buffer is full):
obclient [test]> ALTER SYSTEM SET audit_log_strategy='ASYNCHRONOUS';
When asynchronous log writing is enabled, you can control the buffer size by using the audit_log_buffer_size configuration item.
Set a log format
You can set the auditing log format by using the audit_log_format configuration item. Currently, only the CSV format is supported.
obclient [test]> ALTER SYSTEM SET audit_log_format='CSV';
Configure data masking
You can specify whether to record SQL statements in audit records by using the audit_log_query_sql configuration item. Valid values are ALL and NONE.
ALL: Records all query SQL statements.NONE: Does not record query SQL statements.
For example, to prevent audit records from recording query SQL statements, set the configuration item to NONE:
obclient [test]> ALTER SYSTEM SET audit_log_query_sql='NONE';
When query SQL statements are recorded, the audit file applies data masking to the following types of statements:
- CMD: For statements containing sensitive information such as passwords or AK/SK (for example, creating users, initiating backup and restore, or modifying configuration items), the system records
***. For other CMD statements, the original SQL is recorded. - Unable to determine statement type: If the statement type cannot be identified (such as when parsing fails), the system records
***.
Set the output path
You can use the audit_log_path configuration item to specify the output path for audit logs, supporting both local and cloud storage. If you do not specify a value for audit_log_path, the default path ${WORK_DIR}/audit is used.
Local storage
For the same tenant, audit logs from different OBServer nodes are stored in separate directories. In a single cluster, you can configure different tenants to use the same output path. In this case, the directory structure includes an additional
tenant_idlayer. The directory structure for local storage is as follows:- ${audit_log_path} - tenant_id_1 - ip1:port1 - audit.log.20231031080646317[.zst] - audit.log.20231031084835263[.zst] - audit.log - ip2:port2 - audit.log.20231031072457838[.zst] - audit.log.20231031093023607[.zst] - audit.log.20231031101213751[.zst] - audit.log - tenant_id_2Here is an example of setting the output directory for audit logs to a local path:
obclient [test]> ALTER SYSTEM SET audit_log_path='file:///logs/audit';Cloud storage
OceanBase AI Database allows multiple OBServer nodes to output to the same
s3/nfsdirectory. To ensure the performance of concurrent append writes and to support later compression and encryption, only archived files are stored in cloud storage. Append writes occur in local files under theauditdirectory. When consuming audit logs from cloud storage, some of the most recent records may exist only on the local OBServer node and are not yet visible downstream.Here is an example of setting the output directory for audit logs to
S3:obclient [test]> ALTER SYSTEM SET audit_log_path = 's3://ob-audit/audit/?host=$S3_HOST&access_id=$S3_ACCESS_ID&access_key=$S3_ACCESS_KEY';Here,
$S3_HOST,$S3_ACCESS_ID, and$S3_ACCESS_KEYshould be replaced with the actual host address, access key ID, and access key, respectively. The access key is stored in encrypted form.
Configure log archiving
Audit records are continuously appended to the audit.log file. You can configure log archiving by setting the audit_log_rotate_on_size configuration item. When the size of audit.log reaches the specified value, a new file is automatically generated. Log archiving only controls the size of individual log files; it does not handle file cleanup.
For example, to set the maximum size of each audit record file to 256 MB:
obclient [test]> ALTER SYSTEM SET audit_log_rotate_on_size='256M';
Set log cleanup
The audit_log_max_size and audit_log_prune_seconds configuration items control the capacity and retention period of archived audit logs. Both configuration items can take effect simultaneously. When a new log file is generated during log archiving, the system checks whether log cleanup is needed. The total log size is calculated separately for each OBServer.
To control the maximum size of audit logs on a single OBServer, set the audit_log_max_size configuration item. The default value is 0 MB, which means audit logs are not retained.
For example, to set the maximum audit log size on a single OBServer to 1 GB:
obclient [test]> ALTER SYSTEM SET audit_log_max_size='1G';
To control the maximum audit log retention period, set the audit_log_prune_seconds configuration item. The default value is 0, which means audit logs are not retained. The value is specified in seconds, and you do not need to include a unit when setting it.
For example, to set the maximum audit log retention period to 2 hours:
obclient [test]> ALTER SYSTEM SET audit_log_prune_seconds=7200;
(Optional) Set log compression
You can set the audit_log_compression configuration item to enable log compression. If log compression is enabled, archived log files are generated in compressed format. Only the ZSTD compression algorithm is supported, and streaming compression is available. Compressed files can be directly decompressed using the external tool zstd.
Note
Only archived files are compressed. The audit.log file itself is not compressed.
For example, to set the compression algorithm for audit logs to ZSTD:
obclient [test]> ALTER SYSTEM SET audit_log_compression='ZSTD';