Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

CREATE AUDIT POLICY

Updated on 2024-08-20 GMT+08:00

Description

Creates a unified audit policy.

Precautions

  • Only the user with the poladmin or sysadmin permission, or initial user has the permission to maintain audit policies.
  • Before creating an audit policy, ensure that the security policy function has been enabled. That is, the masking policy takes effect only after the GUC parameter enable_security_policy is set to on.
  • A system administrator or security policy administrator can access the GS_AUDITING_POLICY, GS_AUDITING_POLICY_ACCESS, GS_AUDITING_POLICY_PRIVILEGES, and GS_AUDITING_POLICY_FILTERS system catalogs to query the created audit policies.
  • The audit policy name must be unique to avoid conflicts with existing policies. You can use IF NOT EXISTS to check whether the specified audit policy exists to avoid repeated creation.
NOTICE:

When you use database links to perform operations on remote objects, the client initiates a database link request. The actual sender is the server, and the attributes such as the IP address of the sender are the values of the server. For details, see DATABASE LINK.

Syntax

CREATE AUDIT POLICY [ IF NOT EXISTS ] policy_name { { privilege_audit_clause | access_audit_clause } [, ... ] [ filter_group_clause ] [ ENABLE | DISABLE ] };
  • privilege_audit_clause
    1
    PRIVILEGES { DDL | ALL } [ ON LABEL ( resource_label_name [, ... ] ) ]
    
  • access_audit_clause
    ACCESS { DML | ALL } [ ON LABEL ( resource_label_name [, ... ] ) ]
  • filter_group_clause

    FILTER ON { FILTER_TYPE ( filter_value [, ... ] ) } [, ... ] 

Parameters

  • policy_name

    Specifies the audit policy name, which must be unique.

    Value range: a string. It must comply with the naming convention.

  • resource_label_name

    Specifies the resource label name.

  • DDL

    Specifies the operations that are audited in the database: CREATE, ALTER, DROP, ANALYZE, COMMENT, GRANT, REVOKE, SET, and SHOW.

    If this parameter is set to ANALYZE, both ANALYZE and VACCUM operations are audited.

  • DML

    Specifies the operations that are audited within the database: SELECT, COPY, DEALLOCATE, DELETE, EXECUTE, INSERT, PREPARE, REINDEX, TRUNCATE, and UPDATE.

  • ALL

    Specifies all operations supported by the specified DDL or DML statements in the database. When the form is { DDL | ALL }, ALL indicates all DDL operations. When the form is { DML | ALL }, ALL indicates all DML operations.

  • FILTER_TYPE

    Specifies the types of information to be filtered by the policy, including APP, ROLES, and IP.

  • filter_value

    Indicates the detailed information to be filtered.

  • ENABLE|DISABLE

    Enables or disables the unified audit policy. If ENABLE|DISABLE is not specified, ENABLE is used by default.

Examples

  • Creates audit policy for executing CREATE on the database.
    -- Create the adt1 policy.
    gaussdb=# CREATE AUDIT POLICY adt1 PRIVILEGES CREATE; 
    
    -- View the adt1 policy.
    gaussdb=# SELECT * FROM GS_AUDITING_POLICY;
     polname | polcomments |         modifydate         | polenabled 
    ---------+-------------+----------------------------+------------
     adt1    |             | 2023-11-06 16:41:40.947417 | t
    
    -- Check the location where the audit policy is stored.
    gaussdb=# SHOW audit_directory;
    
    -- Delete the audit policy adt1.
    gaussdb=# DROP AUDIT POLICY adt1;
  • Create an audit policy to audit only the CREATE operation performed by the dev_audit user.
    -- Create user dev_audit.
    gaussdb=# CREATE USER dev_audit PASSWORD '********';
    
    -- Create the tb_for_audit table.
    gaussdb=# CREATE TABLE tb_for_audit(col1 text, col2 text, col3 text); 
    
    -- Create the adt_lb0 resource label based on the tb_for_audit table.
    gaussdb=# CREATE RESOURCE LABEL adt_lb0 add TABLE(public.tb_for_audit);
    
    -- Create the adt2 audit policy for the CREATE operation on the adt_lb0 resource.
    gaussdb=# CREATE AUDIT POLICY adt2 PRIVILEGES CREATE ON LABEL(adt_lb0) FILTER ON ROLES(dev_audit);
    
    -- Delete the audit policy adt2.
    gaussdb=# DROP AUDIT POLICY adt2;
    
    -- Delete the tb_for_audit table.
    gaussdb=# DROP TABLE tb_for_audit;
    
    -- Delete the dev_audit user.
    gaussdb=# DROP USER dev_audit;
  • Create an audit policy to audit only the SELECT, INSERT, and DELETE operations performed on the adt_lb0 resource by user dev_audit using client tool gsql on the servers whose IP addresses are 10.20.30.40 and 127.0.0.0/24, respectively.
    -- Create a user dev_audit.
    gaussdb=# CREATE USER dev_audit PASSWORD '********';
    
    -- Create the audit policy adt3.
    gaussdb=# CREATE AUDIT POLICY adt3 ACCESS SELECT ON LABEL(adt_lb0), INSERT ON LABEL(adt_lb0), DELETE FILTER ON ROLES(dev_audit), APP(gsql), IP('10.20.30.40', '127.0.0.0/24');
    
    -- Delete the audit policy adt3.
    gaussdb=# DROP AUDIT POLICY adt3;
    
    -- Delete the dev_audit user.
    gaussdb=# DROP USER dev_audit;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback