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 tenant SQL audit.
Configure storage
Note
For tenants with SQL audit enabled, audit data can be stored in OceanBase Cloud, a custom log service, or object storage.
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.
Click the button for the current storage destination, and select a storage destination in the dialog box.
- If the current destination is OceanBase Cloud, click Modify storage configuration.
- If the current destination is Custom log service or Object storage, click Modify delivery configuration.
Configure the selected storage destination:
Storage destinationConfigurationRequirements and notesOceanBase Cloud Set the retention period. The supported range is 7 to 720 days. SQL execution records are automatically deleted when this period expires. Object storage Select an Object storage configuration and set the Storage path prefix.
When you reference an existing configuration, you do not need to enter the bucket or access credentials again.
If no suitable configuration is available, click Add object storage configuration in the drop-down list. Create a configuration on the current page, then select it. You can also manage configurations on the Project settings > Data delivery destinations > Object storage tab. For details, see Manage object storage configurations.The configuration must belong to the instance's project, match its cloud provider and region, and pass validation. Alibaba Cloud instances use Alibaba Cloud OSS, AWS instances use AWS S3, and Azure instances use Azure Blob Storage. Custom log service Select a Log service configuration.
When you reference an existing configuration, you do not need to enter the Project, Logstore, or access credentials again.
If no suitable configuration is available, click Add log service in the drop-down list to add one. You can also manage configurations on the Project settings > Data delivery destinations > Log service tab. For details, see Manage log service configurations.Supported only for Alibaba Cloud instances. Select an SLS configuration that belongs to the instance's project, matches its region, and passes validation. The credentials must have permissions to write logs to Logstore and view its metadata. Click OK. When switching from OceanBase Cloud to a custom log service or object storage, read the additional confirmation message and click OK again.
Note
Changes to the storage configuration apply to all tenants in the instance. 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.
Enable tenant SQL audit
Note
When you enable SQL audit for a tenant, the tenant uses the instance's shared storage configuration. To change the storage destination, follow the Configure storage procedure on the instance page. The change applies to all tenants in the instance.
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 tenant SQL audit.
Click OK.
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.