Help Center/ GaussDB(for MySQL)/ User Guide/ Permissions Management/ Creating a GaussDB(for MySQL) Custom Policy
Updated on 2024-11-06 GMT+08:00

Creating a GaussDB(for MySQL) Custom Policy

Custom policies can be created to supplement the system-defined policies of GaussDB(for MySQL).

You can create a custom policy in either of the following ways:

  • Visual editor: Select cloud services, actions, resources, and request conditions. This does not require knowledge of policy syntax.
  • JSON: Write policies from scratch or based on an existing policy.

For details, see Creating a Custom Policy. This section provides examples of common GaussDB(for MySQL) custom policies.

Example Custom Policies

  • Example 1: Allowing users to create GaussDB(for MySQL) instances
    {
        "Version": "1.1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "gaussdb:instance:create"
                ]
            }
        ]
    }
  • Example 2: Denying GaussDB(for MySQL) instance deletion

    A policy with only "Deny" permissions must be used in conjunction with other policies. If the permissions assigned to a user contain both "Allow" and "Deny", the "Deny" permissions take precedence over the "Allow" permissions.

    The following method can be used if you need to assign permissions of the GaussDB FullAccess policy to a user but you want to prevent the user from deleting GaussDB(for MySQL) instances. Create a custom policy for denying GaussDB(for MySQL) instance deletion, and attach both policies to the group the user belongs to. Then, the user can perform all operations on GaussDB(for MySQL) instances except deleting GaussDB(for MySQL) instances. The following is an example of a deny policy:

    {
        "Version": "1.1",
        "Statement": [
            {
              "Effect": "Deny"
              "Action": [
                    "gaussdb:instance:delete"
                ],
              }
        ]
    }
  • Example 3: Defining permissions for multiple services in a policy

    A custom policy can contain the actions of one or multiple services that are of the same type (global or project-level). The following is an example policy containing actions of multiple services:

    {  
            "Version": "1.1",  
            "Statement": [  
                    {  
                            "Action": [  
                                    "gaussdb:instance:create",  
                                    "gaussdb:instance:modify",  
                                    "gaussdb:instance:delete",  
                     "vpc:publicIps:list",  
                     "vpc:publicIps:update"  
                            ],  
                            "Effect": "Allow"  
                    }  
            ]  
    }
  • Example 4: Allowing users to manage specified instances and some functions of instances

    Assume that your account has multiple instances and you are a database administrator. If you want to allow users to manage specified instances and some functions of instances, you can create the following permission policy.

    {
        "Version": "1.1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "gaussdb:instance:restart",
                    "gaussdb:instance:modify"
                ],
                "Resource": [
                   "GAUSSDB:*:*:instance:test*"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "gaussdb:param:list",
                    "gaussdb:tag:list",
                    "gaussdb:backup:list",
                    "gaussdb:instance:create",
                    "gaussdb:instance:list"
                ]
            }
        ]
    }
    
    • Users granted these permissions can view all instances, but can manage only authorized instances. In addition, the database administrator can still use APIs to directly manage these instances. Users granted the permissions can only reboot and modify all instances under this account.
    • test* is an example of an instance name for fuzzy match and is mandatory in the permission policy. Otherwise, the authorized users cannot view any instance on the console.
    • GaussDB(for MySQL) supports API-level access control. You can use related APIs to perform fine-grained access control on GaussDB(for MySQL). For details, see API Overview.