Grant different Resource Access Management (RAM) users permissions to operate functions in different groups

Updated at:

Function Compute supports multi-dimensional classification of functions by using tags for fast resource retrieval, and can also implement fine-grained access control by using tags. By granting different permissions to different RAM users or user groups, you can isolate resources between RAM users and improve security management efficiency.

Common scenarios

An enterprise's Alibaba Cloud account has created multiple functions and needs to authorize different functions to different teams by business group. The enterprise wants each team to view and manage only the functions authorized to it. Unauthorized functions must not be viewable or manageable.

For example:

  • Development team: can manage only the functions related to the development environment

  • Operator team: can manage only the functions related to the production environment

Usage notes

  • To follow the Principle of Least Privilege (PoLP), do not grant access policies with excessively high permission levels, such as AliyunFCFullAccess or AliyunFCReadOnlyAccess, to RAM users. Otherwise, you cannot use the method described in this topic to manage functions in groups by using function tags.

  • RAM users must filter by tag to view and manage the functions authorized to them. Otherwise, RAM users cannot view any functions.

  • Make sure that the region selected by the RAM user is the same as the region where the functions in the resource group reside.

  • RAM users in a RAM user group automatically inherit the permissions of the RAM user group.

  • Sub-resources and configurations under a function, including aliases, triggers, function asynchronous configurations, function concurrency configurations, instances, VPC bindings, and asynchronous tasks, follow the access control of the function. They can be managed only by RAM users who have the corresponding tag.

Workflow overview

  1. Identify the functions of different teams by tag

    Plan two tags: one to identify the developer team and one to identify the operator team.

  2. Group RAM users

    Plan two RAM users, one for the developer team and one for the operator team, and add each RAM user to the corresponding RAM user group.

  3. Grant permissions to RAM user groups based on tag-based authentication

    Plan two custom access policies that use the tag-based authentication Condition to determine the resource scope. Then, grant different access policies to different RAM user groups. RAM users in a RAM user group inherit the permissions of the RAM user group.

The following table describes the detailed plan:

Team

RAM user group

RAM access policy

Tag

developer team

developer

FCPolicyForDevTeam

  • Tag key: team

  • Tag value: dev

operator team

operator

FCPolicyForOpsTeam

  • Tag key: team

  • Tag value: ops

Procedure

  1. Create functions and bind tags.

    Log on to the Function Compute console by using your Alibaba Cloud account, create a function, and bind the tag team:dev to some functions and the tag team:ops to other functions. For more information about how to bind tags, see Configure tags.

  2. Create RAM users.

    Log on to the Resource Access Management (RAM) console by using your Alibaba Cloud account and create two RAM users. For more information, see Create a RAM user.

  3. Create RAM user groups and bind RAM users to them. After binding, RAM users inherit the permissions of the RAM user group.

    Log on to the RAM console by using your Alibaba Cloud account and create two user groups, developer and operator. Add the two created RAM users to the user groups developer and operator respectively. For more information, see Create a RAM user group and Add a RAM user to a user group.

  4. Create custom access policies.

    Access policies are divided into system access policies and custom access policies. Select an appropriate access policy based on your requirements. This topic describes the procedure by using the example of granting a custom access policy to a user group.

    Log on to the RAM console by using your Alibaba Cloud account and create a custom policy.

    • Assume that the name of the custom policy created for the developer team is FCPolicyForDevTeam. The following is a sample policy:

      {
          "Version": "1",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": "fc:*",
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "acs:RequestTag/team": [
                              "dev"
                          ]
                      }
                  }
              },
              {
                  "Effect": "Allow",
                  "Action": "fc:*",
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "acs:ResourceTag/team": [
                              "dev"
                          ]
                      }
                  }
              },
              {
                  "Effect": "Allow",
                  "Action": [
                      "fc:ListTaggedResources",
                      "tag:ListTagKeys",
                      "fc:GetAccountSettings"
                  ],
                  "Resource": "*"
              },
              {
                  "Effect": "Deny",
                  "Action": [
                      "fc:UntagResources",
                      "fc:TagResources"
                  ],
                  "Resource": "*"
              }
          ]
      }
    • Assume that the name of the custom policy created for the operator team is FCPolicyForOpsTeam. The following is a sample policy:

      {
          "Version": "1",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": "fc:*",
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "acs:RequestTag/team": [
                              "ops"
                          ]
                      }
                  }
              },
              {
                  "Effect": "Allow",
                  "Action": "fc:*",
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "acs:ResourceTag/team": [
                              "ops"
                          ]
                      }
                  }
              },
              {
                  "Effect": "Allow",
                  "Action": [
                      "fc:ListTaggedResources",
                      "tag:ListTagKeys",
                      "fc:GetAccountSettings"
                  ],
                  "Resource": "*"
              },
              {
                  "Effect": "Deny",
                  "Action": [
                      "fc:UntagResources",
                      "fc:TagResources"
                  ],
                  "Resource": "*"
              }
          ]
      }

    Expand to view optional policies

    To avoid insufficient permissions when you use Function Compute daily, add the following optional policies:

    {
          "Effect": "Allow",
          "Action": [
            "log:Get*",
            "log:List*",
            "log:Query*",
            "log:CreateProject",
            "log:CreateLogStore",
            "log:CreateIndex"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "fc:GetLayerVersionByArn",
            "fc:ListLayers",
            "fc:PutLayerACL",
            "fc:ListLayerVersions",
            "fc:CreateLayerVersion",
            "fc:DeleteLayerVersion",
            "fc:GetLayerVersion"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": [
            "fc:ListCustomDomains",
            "fc:GetCustomDomain",
            "fc:DeleteCustomDomain",
            "fc:UpdateCustomDomain",
            "fc:CreateCustomDomain"
          ],
          "Resource": "*"
        },
        {
          "Effect": "Allow",
          "Action": "ram:ListRoles",
          "Resource": "*"
        }

    The following table describes the access policies:

    Policy content

    Policy description

    {
    	"Effect": "Allow",
    	"Action": "fc:*",
    	"Resource": "*",
    	"Condition": {
    		"StringEquals": {
    			"acs:RequestTag/team": [
    				"dev"
    			]
    		}
    	}
    }

    Allows RAM users to filter functions by the tag team:dev, and requires RAM users to also specify the tag team:dev when they create functions.

    {
    	"Effect": "Allow",
    	"Action": "fc:*",
    	"Resource": "*",
    	"Condition": {
    		"StringEquals": {
    			"acs:ResourceTag/team": [
    				"dev"
    			]
    		}
    	}
    }

    Restricts RAM users to managing only the functions bound with the tag team:dev.

    {
      "Effect": "Allow",
      "Action": [
        "fc:ListTaggedResources",
        "tag:ListTagKeys",
        "fc:GetAccountSettings"
      ],
      "Resource": "*"  
    },

    Allows you to query the list of all tags of functions in Function Compute and get your own account information.

    {
      "Effect": "Deny",
      "Action": [
        "fc:UntagResources",
        "fc:TagResources"
      ],
      "Resource": "*"
    },

    Does not allow unbinding or binding tags.

    This prevents RAM users from breaking permission isolation by modifying tags.

    {
      "Effect": "Allow",
      "Action": [
        "log:Get*",
        "log:List*",
        "log:Query*",
        "log:CreateProject",
        "log:CreateLogStore",
        "log:CreateIndex"
      ],
      "Resource": "*"
    },

    Allows Function Compute to create and read logs.

    {
      "Effect": "Allow",
      "Action": [
        "fc:GetLayerVersionByArn",
        "fc:ListLayers",
        "fc:PutLayerACL",
        "fc:ListLayerVersions",
        "fc:CreateLayerVersion",
        "fc:DeleteLayerVersion",
        "fc:GetLayerVersion"
      ],
      "Resource": "*"
    },

    Allows the use of layer-related features.

    {
      "Effect": "Allow",
      "Action": [
        "fc:ListCustomDomains",
        "fc:GetCustomDomain",
        "fc:DeleteCustomDomain",
        "fc:UpdateCustomDomain",
        "fc:CreateCustomDomain"
      ],
      "Resource": "*"
    },

    Allows the use of custom domain name-related features.

    {
      "Effect": "Allow",
      "Action": [
        "ram:ListRoles"
      ],
      "Resource": "*"
    },

    Allows you to query the role list when you configure a function role.

    Note

    If you need to configure and use products such as OSS, NAS, and VPC in Function Compute, you must separately add the permissions of the corresponding products. For more information about the specific policy content, see Policies and sample policies.

  5. Grant permissions to RAM user groups.

    1. Grant the custom access policies FCPolicyForDevTeam and FCPolicyForOpsTeam to the user groups developer and operator respectively.

    2. Grant the system access policies AliyunRAMFullAccess and AliyunECSFullAccess to the user groups developer and operator. After the authorization, the RAM users in the RAM user group can create functions with the specified tags. They can also create RAM users and user groups, and create and bind access policies.

    For more information, see Grant permissions to a RAM user group.

    Take the user group developer as an example. The recommended policies to grant are as follows:

    image

Result verification

  1. Log on to the Function Compute console by using each of the two RAM users. In the left-side navigation pane, choose Function Management > Functions.

    For more information, see Log on to the Alibaba Cloud console as a RAM user.

  2. In the top menu bar, select a region. Then, on the Function page, click Filter by Tag and filter by the corresponding Tag Key and Tag Value to query and manage the authorized functions.

    A RAM user can view and manage the functions bound with a tag only if the tag they select is included in the policies granted to their user group. Otherwise, the RAM user cannot view any functions.

    Take a RAM user in the RAM user group developer as an example. The RAM user can use the tag team:dev to filter the authorized functions.

    image

References