Note
The audit log management strategies described in this chapter are supported starting from V5.0.1 and apply only to scenarios where audit records are written to audit logs (audit_trail is LOG). To enable audit log writing, see Enable security audit.
After audit records are written to audit logs, you can configure management strategies as needed, such as the log writing strategy, log format, data desensitization, output path, archiving, cleanup, compression, and encryption.
Set the log strategy
Configure the audit log strategy using the audit_log_strategy parameter. Three log writing strategies are supported: ASYNCHRONOUS, PERFORMANCE, and SYNCHRONOUS. You can select the appropriate strategy based on your needs to balance performance and log integrity. For detailed descriptions of the parameters, see the relevant documentation at the end of this topic.
ASYNCHRONOUS: Indicates asynchronous log writing. The system waits synchronously when the buffer is full. This is the default strategy.
PERFORMANCE: Indicates asynchronous log writing. Data is discarded when the buffer is full.
SYNCHRONOUS: Indicates synchronous log writing.
For example, set the audit record file writing strategy to asynchronous log writing, where the system waits synchronously when the buffer is full.
obclient> ALTER SYSTEM SET audit_log_strategy='ASYNCHRONOUS';
When using asynchronous log writing, you can control the buffer size using the audit_log_buffer_size parameter. For detailed descriptions of the parameters, see the relevant documentation at the end of this topic.
Set the log format
Select the audit log format by setting the audit_log_format parameter. Currently, only the CSV format is supported. For detailed descriptions of the parameters, see the relevant documentation at the end of this topic.
obclient> ALTER SYSTEM SET audit_log_format='CSV';
Set data desensitization
Use the audit_log_query_sql parameter to select the SQL statements that are recorded in audit records. Valid values include ALL and NONE. For detailed descriptions of the parameters, see the relevant documentation at the end of this topic.
ALL: Record all Query SQL.
NONE: Do not record Query SQL.
For example, the following statement disables the recording of Query SQL in audit records.
obclient> ALTER SYSTEM SET audit_log_query_sql='NONE';
When Query SQL is recorded, the following statements are desensitized in audit files:
- CMD: Statements that contain sensitive information such as passwords or AK/SK, including user creation, backup and recovery initiation, and parameter modification, are recorded as
***. For other CMD statements, the original SQL is recorded. - Unknown statement type: Statements whose type cannot be determined, for example because parsing fails, are also recorded as
***.
Set the output path
You can set the output path for audit logs using the audit_log_path parameter. Local storage and cloud storage are supported. If the value of audit_log_path is not specified, the current working directory ${WORK_DIR}/audit is used by default. For more information about this parameter, see the related documentation at the end of this topic.
Local storage scenario
In the same tenant, audit logs from different OBServer nodes are written to different directories. In the same cluster, you may set the output path for different tenants to be the same. In this case, a
tenant_idsubdirectory is added to the output directory structure. The local output directory structure is shown in the following figure:- ${audit_log_path} - tenant_id_1 - ip1:port1 - audit.log.20231031080646317[.zst] - audit.log - ip2:port2 - audit.log.20231031072457838[.zst] - audit.log - tenant_id_2The following example shows how to configure the audit log output directory to be a local directory.
obclient> ALTER SYSTEM SET audit_log_path='file:///logs/audit';Cloud storage scenario
OceanBase Database supports multiple OBServer nodes writing to the same
oss/nfsdirectory. Because the performance of concurrent append writes and the subsequent compression and encryption features all require operations on local files, only archived files are stored in cloud storage, while append writes go to files in the localauditdirectory. When downstream components consume audit logs from cloud storage, some of the latest records exist only on the local OBServer node and are not visible to downstream components.The following example shows how to configure the audit log output directory to be an
OSSbucket.obclient> ALTER SYSTEM SET audit_log_path = 'oss://ob-audit/audit/?host=$OSS_HOST&access_id=$OSS_ACCESS_ID&access_key=$OSS_ACCESS_KEY';Replace
$OSS_HOST,$OSS_ACCESS_ID, and$OSS_ACCESS_KEYwith the actual host address, access key ID, and access key respectively. The access key is stored in encrypted form.
Set up log archiving
Audit records are continuously appended to the audit.log file. You can set the audit_log_rotate_on_size parameter to enable automatic log archiving. When the size of audit.log reaches the specified value, a new file is automatically generated. Archiving controls the size of individual log files but does not clean up files. For more information about this parameter, see the related documentation at the end of this topic.
For example, you can set the maximum size of an audit log file to 256 MB.
obclient> ALTER SYSTEM SET audit_log_rotate_on_size='256M';
Set up log cleanup
You can use the audit_log_max_size and audit_log_prune_seconds parameters to control the capacity and retention period of archived audit logs. Both parameters can take effect simultaneously. Each time a new archive log file is generated, it checks whether log cleanup is required. The total log size is calculated separately in the directory of each OBServer node.
Set the audit_log_max_size parameter to control the maximum amount of audit logs retained on a single OBServer node. The default value is 0 MB, which means no audit logs are saved.
For example, you can set the maximum amount of audit logs retained on a single OBServer node to 1 GB.
obclient> ALTER SYSTEM SET audit_log_max_size='1G';
Set the audit_log_prune_seconds parameter to control the maximum retention period of audit logs. The value is in seconds and you do not need to specify the unit. The default value is 0, which means no audit logs are saved.
For example, you can set the maximum retention period of audit logs to 2 hours.
obclient> ALTER SYSTEM SET audit_log_prune_seconds=7200;
For more information about these parameters, see the related documentation at the end of this topic.
Set log compression (Optional)
You can enable log compression by setting the audit_log_compression parameter. If compression is enabled, compressed files are generated during log archiving. The compression algorithm supports only ZSTD, which also supports stream compression. Compressed files can be directly decompressed using the external tool zstd. For more information about this parameter, see the related documentation at the end of this topic.
Note
Only archived files are compressed. The audit.log file is not compressed.
For example, you can set the compression algorithm for audit logs to ZSTD.
obclient> ALTER SYSTEM SET audit_log_compression='ZSTD';
Set log encryption (Optional)
Oracle tenants support encrypted storage of audit logs. This is implemented through the audit_log_encryption parameter and the audit functions AUDIT_LOG_ENCRYPTION_PASSWORD_SET() and AUDIT_LOG_ENCRYPTION_PASSWORD_GET(). For detailed operations on enabling encryption, generating archive passwords, retrieving passwords, and decrypting logs, see Set and view audit rules.
References
- Enable security auditing
- Set and view audit rules
- View audit records
- Enable the audit feature: audit_log_enable