SQL audit lets you query SQL statements in the current cluster by user, client IP address, or operation type, and export the results for 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 details, see SQL audit billing.
All tenants in an instance share the same SQL audit storage configuration. You can modify the configuration only on the instance page, not on a tenant page.
SQL audit supports tenants in MySQL-compatible and Oracle-compatible modes. For the database versions and audit rules supported when using object storage, see the object storage section in Enable SQL audit.
Enable SQL audit
Note
- When you enable SQL audit for a tenant, the tenant uses the instance's shared storage configuration. Object storage and Alibaba Cloud SLS both reference configurations in the instance's project. You do not need to enter the bucket, Project, Logstore, or access credentials again on the tenant page.
- To change the storage destination, use the instance page. For configuration instructions, see SQL audit for instances. The change applies to all tenants in the instance.
- After you switch from OceanBase Cloud to a custom log service or object storage, existing audit data in OceanBase Cloud is retained for the original retention period. You cannot view this data during that period, and it is automatically deleted when the period expires.
Log in to the OceanBase Cloud console.
In the left navigation pane, click Instances.
In the instance list, click the name of the target instance to open its workspace.
In the left navigation pane, click Diagnostics. On the Diagnostics page, select the Real-Time Diagnostics tab.
Click the SQL Audit tab in the middle of the page.
In the Tenant SQL audit list, find the target tenant and click Enable SQL Audit in the Actions column.
In the Enable SQL audit dialog box, configure the parameters for the instance's storage destination.
OceanBase CloudCustom log serviceObject storageThe steps are the same for tenants in MySQL-compatible and Oracle-compatible modes.
- Target tenant: The current tenant is selected by default. To also enable SQL audit for other tenants in the instance that do not have it enabled, select Enable or modify SQL audit for other tenants in this instance.
- Total storage duration: Set a retention period of 7 to 720 days. SQL execution records are deleted when this period expires. Audit data is billed on a pay-as-you-go basis. For details, see SQL audit billing.
Confirm that the tenant uses the instance's log service configuration. To also enable SQL audit for other tenants in the instance that do not have it enabled, select Enable or modify SQL audit for other tenants in this instance. This storage destination does not provide audit rule settings for SQL types or target database accounts.
Use the instance's object storage configuration and configure audit rules for the tenant's compatibility mode and database version.
Note
- All SQL types are selected by default, so statements of all types are recorded.
- SQL auditing with object storage is not supported for database versions earlier than V4.2.5. The specific version requirements and available rules for MySQL-compatible and Oracle-compatible modes are described below.
MySQL-compatible mode
Configure the following audit rules:
ParameterDescriptionTarget Database Account Select the database accounts to audit. You can select all accounts, including existing and future accounts, or specific accounts. - All accounts are selected by default.
- To specify accounts, select them from the drop-down list. You can search for accounts and select multiple accounts.
SQL Type Select SQL categories and subtypes based on the database version. Note
- V4.2.5 to V4.4.1 and V4.4.2 GA: You can select the connection, table access, and general events categories. General events include DDL, privilege changes, and system management. You cannot select individual subtypes.
- V4.4.2.1 to V4.5.0.0, and V4.6.1.0 and later: You can select connection, table access, DDL, privilege changes, and system management. For connection, table access, DDL, and privilege changes, use the drop-down lists to select all or specific subtypes. Multiple selections are supported. System management can only be selected as a whole.
- For versions that support subtype selection, see the drop-down lists for the available subtypes.
Oracle-compatible mode
Configure the following audit rules:
ParameterDescriptionTarget Database Account Select the database accounts to audit. You can select all accounts, including existing and future accounts, or specific accounts. - All accounts are selected by default.
- To specify accounts, select them from the drop-down list. You can search for accounts and select multiple accounts.
SQL Type Select the SQL types to record. Supported categories include connection, table access, DDL, privilege changes, and system management. Examples of subtypes include: - Table access: DELETE TABLE, INSERT TABLE, SELECT SEQUENCE, SELECT TABLE, and UPDATE TABLE.
- DDL: INDEX, OUTLINE, PROCEDURE, PROFILE, ROLE, SEQUENCE, SYNONYM, TABLE, and TABLESPACE.
- Privilege changes: ALTER SYSTEM, CLUSTER, SYSTEM AUDIT, SYSTEM GRANT, EXECUTE PROCEDURE, GRANT PROCEDURE, GRANT SEQUENCE, and GRANT TABLE.
Note
Supported database versions: V4.4.2.1 to V4.5.0.0, and V4.6.1.0 and later.
Audit record generation policy Supported options are Record all operations, Record successful operations, and Record failed operations.
Click OK to enable SQL audit.
Modify audit rules
You can modify audit rules only when the storage destination is object storage and SQL audit is enabled for the tenant.
On the instance's SQL Audit tab, find the target tenant, click … in the Actions column, and select Modify rules.
In the dialog box, modify the rules for the tenant's compatibility mode. The available rules are the same as those used when enabling SQL audit. See the object storage section in Enable SQL audit.
Click OK.
View the storage configuration
On the SQL Audit page, you can view the current storage configuration for SQL audit data.
The storage configuration area shows the current destination:
- OceanBase Cloud: The data is stored in the default storage provided by OceanBase Cloud.
- Log service: For Alibaba Cloud instances, the referenced SLS configuration is displayed, including the Project and Logstore.
- Object storage: The referenced object storage configuration and bucket information are displayed.
To change the storage destination, use the instance page. For detailed steps, see SQL audit. The change applies to all tenants in the instance.
Note
After you change the storage configuration, new audit data is delivered to the new destination. After you switch from OceanBase Cloud to a custom log service or object storage, existing audit data in OceanBase Cloud is retained for the original retention period. You cannot view this data during that period, and it is automatically deleted when the period expires.
Modify the retention period
Note
You can modify the retention period only when SQL audit data is stored in OceanBase Cloud. If the destination is a log service or object storage, configure the retention policy for audit data on that platform.
In the tenant list on the SQL Audit tab, click … in the Actions column of the target tenant and select Modify retention period.
Configure the following parameters in the dialog box:
- Target tenant: Displays the name of the current tenant.
- Modify for Other Tenants in the Instance: Select this checkbox to apply the setting to other tenants in the instance that have SQL audit enabled.
- Total storage duration: Set a retention period of 7 to 720 days. SQL execution records are deleted when this period expires.
Click OK.
Disable SQL audit
In the tenant list on the SQL Audit tab, find the target tenant and use the action for its storage destination.
- OceanBase Cloud or Object storage: Click … in the Actions column and select Disable SQL audit.
- Custom log service: Click Disable in the Actions column.
Enter close in the dialog box, then click Close.
View and download SQL audit records
Note
You can view and download audit records on this page only when SQL audit data is stored in OceanBase Cloud. If the destination is a log service or object storage, view or download the data on that platform.
In the tenant list on the SQL Audit tab, click the target tenant's name to open its audit records page. Then click Expand.
Specify any of the following optional filters:
FilterDescriptionDatabase Select one or more databases in the tenant. Node Select the nodes to query. Keyword Enter keywords to search for in SQL statements. You can combine multiple keywords with "and" or "or". Username Enter one or more database usernames. Operation Type Select one or more operation types from the drop-down list. Client IP Enter client IP addresses. Scanned Records Specify a range for the number of scanned records. Execution Time (ms) Specify a range for SQL execution time. Time range Select a SQL execution time range of no more than 6 hours. View the following fields in the query results: SQL Statement, Database, User, Client IP, Operation Type, Execution Result, Request Time, Execution Time (ms), Scanned Rows, and Affected Rows.
Click the download icon in the upper-right corner of the query results list to download the results.
Note
You can download up to 100 audit records. If a query returns more than 100 records, only the first 100 records in the current sort order are downloaded.