The SQL audit feature allows you to query SQL statements in the current cluster by execution user, access IP address, or operation type. You can also export the query results to enhance security auditing. This topic describes how to use SQL audit.
Considerations
SQL audit is a paid feature. Fees vary by cloud provider, region, and billing item. For more information, see SQL audit billing.
Note
SQL audit currently supports only tenants in MySQL mode. Tenants in Oracle mode are not supported. Audit rule configuration, including SQL types and target database accounts, is supported only for instances of OceanBase Database V4.2.5 or later.
Enable SQL audit
Note
Audit data for tenants with SQL audit enabled is stored in OceanBase Cloud.
Log in to the OceanBase Cloud console.
In the left-side navigation pane, click Instances.
In the instance list, find the target instance and click its name to go to the instance workspace.
In the left-side navigation pane, click Diagnostics. On the Diagnostics page, select the Real-Time Diagnostics tab.
In the middle of the page, click the SQL Audit tab.
In the upper-left corner of the SQL Audit tab, select a tenant.
On the SQL Audit tab, click Enable SQL Audit.
Configure Enable For in the dialog box. If you select this option, SQL audit is also enabled for all tenants in the instance.
Configure SQL audit push settings in the dialog box, and then click Enable:
OceanBase Cloud
ParameterDescriptionTotal Storage Duration SQL execution records can be stored for 7 to 720 days. Records older than the specified duration are deleted. Hot Storage Duration Within the total storage duration, data is automatically moved to cold storage after the specified hot storage duration. Custom log service
Note
Only Alibaba Cloud and Baidu Cloud instances support pushing SQL audit data to a custom log service.
ParameterDescriptionProject The name of the log service project. Logstore The name of the log service Logstore. AccessKey ID The access ID used by the log service to identify the user. AccessKey Secret The key used to encrypt a signature string and by the log service to verify the signature. Keep this key confidential. Object storage
ParameterDescriptionBucket The name of the object storage bucket. Directory The directory in the object storage bucket. Multi-level directories are supported. Access Key ID The AccessKey ID used to access object storage. Access Key Secret The AccessKey Secret used to access object storage. Note
- Only Alibaba Cloud and AWS instances support pushing SQL audit data to object storage.
- SQL audit data is stored in the object storage bucket that you specify.
MySQL
If the storage destination is object storage, configure the following audit rules:
ParameterDescriptionTarget Database Account Select the database accounts to audit. You can select all accounts, including existing accounts and accounts created in the future, or specify accounts. - All accounts are selected by default.
- When you switch to specified accounts, an account selection field appears. You can select multiple accounts or search for accounts.
SQL Type Select the SQL types to record. - Versions 4.2.5 to 4.4.1:
- Connection: Login/Logout/Connect/Disconnect
- Table access: Query/DML (SELECT/INSERT/UPDATE/DELETE)
- General event: DDL/Privilege change/System administration
Note
- All SQL types are selected by default. This means that all types of SQL statements are recorded.
- Audit rules can be configured only when the storage destination is object storage.
- This feature supports only tenants in MySQL mode on clusters of OceanBase Database V4.2.5 or later.
View the storage configuration
On the SQL Audit page, you can view the current storage configuration for SQL audit data.
The Storage Configuration section displays the destination service in which the current audit data is stored:
- OceanBase Cloud: Data is stored in the default storage provided by OceanBase Cloud.
- Custom log service: Data is stored in a log service. The Project and Logstore information is displayed.
- Object storage: Data is stored in object storage. The bucket name is displayed.
Click Modify Push Configuration to modify the storage destination and related parameters.
Note
After you modify the storage configuration, new audit data is pushed to the new storage destination. Data in the original storage location is not affected.
View and download SQL audit records
Note
You can directly view and download audit records on the page only when SQL audit data is stored in OceanBase Cloud. If the storage destination is a log service or object storage, view or download the data on the corresponding platform.
On the SQL Audit tab, click Expand.
Specify filter conditions. All the following filter items are optional.
Filter itemDescriptionDatabase Select one or more databases in the tenant. Node Select one or more nodes. Keyword Enter one or more keywords that may appear in the SQL statements. Use “and” or “or” to define the relationship between keywords. Username Enter one or more tenant names. Operation Type Select one or more operation types from the drop-down list. Client IP Enter a client IP address. Scanned Records Enter a range for the number of scanned records. Execution Duration (ms) Enter an execution duration range for SQL statements. Time Range Select a SQL execution time range. The time range cannot exceed 6 hours. View the following information in the query results: SQL Statement, Database, User, Client IP, Operation Type, Execution Result, Request Time, Execution Duration (ms), Scanned Rows, and Updated Rows.
Click the icon
in the upper-right corner to download the query result list.Note
You can currently download a maximum of 100 audit records. If the query returns more than 100 records, only the first 100 records are downloaded based on the page sort order.
Modify the storage duration
Note
You can modify the storage duration only when SQL audit data is stored in OceanBase Cloud. If the storage destination is a log service or object storage, modify the storage configuration on the corresponding platform.
In the tenant list on the SQL Audit tab, click Modify Storage Duration in the Actions column of the target tenant.
Configure the following parameters in the dialog box:
- Configuration Scope: Displays the current tenant name.
- Apply to Other Tenants in the Instance: Select this option to synchronize the configuration to other tenants in the instance for which SQL audit is enabled.
- Total Storage Duration: Set a value from 7 to 720 days. SQL execution records older than the specified duration are deleted.
Click OK.
Disable SQL audit
In the tenant list on the SQL Audit tab, click Disable SQL Audit in the Actions column of the target tenant.
Enter close in the text box of the dialog box, and then click Disable.
