ALB自定义权限策略示例

本文为您介绍ALB在RAM中的自定义权限策略示例。

背景信息

权限策略包含系统策略和自定义策略。使用RAM对ALB进行权限管理前,请先了解产品的系统策略。

当系统策略不能满足您的需求时,您可以创建自定义策略。具体操作,请参见通过脚本编辑模式创建自定义权限策略

使用RAM对ALB进行权限管理前,请先了解ALB的权限定义。更多信息,请参见RAM鉴权

自定义权限策略示例

  • 示例1:禁止RAM用户创建HTTP协议的监听和HTTP协议的服务器组。

    {
      "Version": "1",
      "Statement": [
        {
          "Effect":"Deny",
          "Action":"alb:CreateListener",
          "Resource":"*",
          "Condition": {
            "StringLike": {
              "alb:ListenerProtocol": [
                "HTTP"
              ]
            }
          }
        },
        {
          "Effect":"Deny",
          "Action":"alb:CreateServerGroup",
          "Resource":"*",
          "Condition": {
            "StringLike": {
              "alb:ServerGroupProtocol": [
                "HTTP"
              ]
            }
          }
        }
      ]
    }
    

  • 示例2:授权RAM用户管理两个指定的ALB实例。

    假设您的账号购买了多个实例,而作为RAM管理员,您希望仅授权其中的两个ALB实例给某个RAM用户。被授权的两个ALB实例ID分别为alb-001、alb-002。

    {
      "Version": "1",
      "Statement": [
        {
          "Effect":"Allow",
          "Action": [
            "alb:*"],
          "Resource": [
            "acs:alb:*:*:loadbalancer/alb-001",
            "acs:alb:*:*:loadbalancer/alb-002"
          ],
          "Condition": {
          }
        },
        {
          "Effect":"Allow",
          "Action": [
            "alb:Get*"],
          "Resource": [
            "*"],
          "Condition": {
          }
        }
      ]
    }
    
  • 示例3:将ECS实例加入服务器组。服务器组ID为sgp-001,ECS实例ID为i-001。

    {
      "Version": "1",
      "Statement": [
        {
          "Effect":"Allow",
          "Action": [
            "alb:AddServersToServerGroup"],
          "Resource": [
            "acs:alb:*:*:servergroup/sgp-001"],
          "Condition": {
          }
        },
        {
          "Effect":"Allow",
          "Action": [
            "alb:AddServersToServerGroup"],
          "Resource": [
            "acs:ecs:*:*:instance/i-001"],
          "Condition": {
          }
        },
        {
          "Effect":"Allow",
          "Action": [
            "alb:ListServerGroups"],
          "Resource": [
            "acs:alb:*:*:servergroup/*"],
          "Condition": {
          }
        }
      ]
    }
  • 示例4:允许在ALB指定服务器组上执行ECS的相关操作。ALB指定的服务器组ID分别为sgp-001、sgp-002。

    {
      "Version": "1",
      "Statement": [
        {
          "Effect":"Allow",
          "Action": [
            "alb:*"],
          "Resource": [
            "acs:alb:*:*:servergroup/sgp-001",
            "acs:alb:*:*:servergroup/sgp-002"
          ],
          "Condition": {
          }
        },
        {
          "Effect":"Allow",
          "Action": [
            "alb:List*"],
          "Resource": [
            "*"],
          "Condition": {
          }
        },
        {
          "Effect": "Allow",
          "Action": [
            "ecs:DescribeInstances"],
          "Resource": [
            "*"],
          "Condition": {
          }
        },
        {
          "Effect":"Allow",
          "Action": [
            "alb:*"],
          "Resource": [
            "acs:ecs:*:*:instance/i-instance001",
            "acs:ecs:*:*:instance/i-instance002"
          ],
          "Condition": {
          }
        }
      ]
    }