自定义权限

您可以创建自定义权限策略,实现精细化权限管理。

背景信息

权限指在特定条件下 ,允许(Allow)或拒绝(Deny)对指定资源执行的相关操作。权限的载体是授权策略。自定义权限,即在自定义授权策略时定义某些权限。

创建自定义权限策略方式,请参见创建方式。本文介绍通过脚本编辑模式创建自定义权限策略的操作步骤。

操作步骤

  1. 使用RAM管理员登录RAM控制台

  2. 在左侧导航栏,选择权限管理 > 权限策略

  3. 权限策略页面,单击创建权限策略

  4. 创建权限策略页面,单击脚本编辑页签。

  5. 输入权限策略内容,然后单击继续编辑基本信息

    关于权限策略语法结构的详情,请参见权限策略语法和结构

    权限策略中包含参数如下:

    • Action:表示要授权的操作。IoT操作都以iot:开头。定义方式和示例,请参见本文档中Action定义。

    • Effect : 表示授权类型,取值:Allow(允许)、Deny(拒绝)。

    • Resource :表示要授权的资源。

      如果为RAM用户授予访问您的所有物联网平台资源的权限,取值为*

    • Condition :表示鉴权条件。IoT不支持Condition定义。

    关于权限策略元素的详情,请参见权限策略基本元素

  6. 输入权限策略名称备注

  7. 检查并优化权限策略内容。

    • 基础权限策略优化

      系统会对您添加的权限策略语句自动进行基础优化。基础权限策略优化会完成以下任务:

      • 删除不必要的条件。

      • 删除不必要的数组。

    • 可选:高级权限策略优化

      您可以将鼠标悬浮在可选:高级策略优化上,单击执行,对权限策略内容进行高级优化。高级权限策略优化功能会完成以下任务:

      • 拆分不兼容操作的资源或条件。

      • 收缩资源到更小范围。

      • 去重或合并语句。

  8. 单击确定

Action 定义

Action是API的名称。在创建IoT授权策略时,每个Action前缀均为iot:,多个Action以英文逗号(,)分隔,支持使用星号(*)通配符。IoT API名称定义,请参见IoT授权映射表

下面介绍一些典型的Action定义示例。

  • 定义单个API。

    "Action": "iot:CreateProduct"
  • 定义多个API。

    "Action": [
    "iot:UpdateProduct",
    "iot:QueryProduct"
    ]
  • 定义所有只读API,包含规则引擎数据流转目标产品的权限。

    {
      "Version": "1", 
      "Statement": [
        {
          "Action": [
            "iot:Query*", 
            "iot:List*", 
            "iot:Get*", 
            "iot:BatchGet*", 
            "iot:Check*"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "rds:DescribeDBInstances", 
            "rds:DescribeDatabases", 
            "rds:DescribeAccounts", 
            "rds:DescribeDBInstanceNetInfo"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": "ram:ListRoles", 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "mns:ListTopic", 
            "mns:GetTopicRef"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "dhs:ListProject", 
            "dhs:GetProject", 
            "dhs:ListTopic", 
            "dhs:GetTopic"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "ots:ListInstance", 
            "ots:GetInstance", 
            "ots:ListTable", 
            "ots:DescribeTable"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "ons:OnsRegionList", 
            "ons:OnsInstanceInServiceList", 
            "ons:OnsTopicList", 
            "ons:OnsTopicGet"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "hitsdb:DescribeRegions", 
            "hitsdb:DescribeHiTSDBInstanceList", 
            "hitsdb:DescribeHiTSDBInstance"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "fc:ListServices", 
            "fc:GetService", 
            "fc:GetFunction", 
            "fc:ListFunctions"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "log:ListShards", 
            "log:ListLogStores", 
            "log:ListProject"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "cms:QueryMetricList"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }
      ]
    }
  • 定义所有读写API,包含规则引擎数据流转目标产品的权限。

    {
      "Version": "1", 
      "Statement": [
        {
          "Action": "iot:*", 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "rds:DescribeDBInstances", 
            "rds:DescribeDatabases", 
            "rds:DescribeAccounts", 
            "rds:DescribeDBInstanceNetInfo", 
            "rds:ModifySecurityIps"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": "ram:ListRoles", 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "mns:ListTopic", 
            "mns:GetTopicRef"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "dhs:ListProject", 
            "dhs:ListTopic", 
            "dhs:GetProject", 
            "dhs:GetTopic"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "ots:ListInstance", 
            "ots:ListTable", 
            "ots:DescribeTable", 
            "ots:GetInstance"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "ons:OnsRegionList", 
            "ons:OnsInstanceInServiceList", 
            "ons:OnsTopicList", 
            "ons:OnsTopicGet"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "hitsdb:DescribeRegions", 
            "hitsdb:DescribeHiTSDBInstanceList", 
            "hitsdb:DescribeHiTSDBInstance", 
            "hitsdb:ModifyHiTSDBInstanceSecurityIpList"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "fc:ListServices", 
            "fc:GetService", 
            "fc:GetFunction", 
            "fc:ListFunctions"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": [
            "log:ListShards", 
            "log:ListLogStores", 
            "log:ListProject"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }, 
        {
          "Action": "ram:PassRole", 
          "Resource": "*", 
          "Effect": "Allow", 
          "Condition": {
            "StringEquals": {
              "acs:Service": "iot.aliyuncs.com"
            }
          }
        }, 
        {
          "Action": [
            "cms:QueryMetricList"
          ], 
          "Resource": "*", 
          "Effect": "Allow"
        }
      ]
    }

典型使用场景

结合以上对Action、Resource和Condition的定义,下面介绍一些典型使用场景的授权策略定义和授权方法。

  • 允许访问的授权策略示例。

    场景:定义访问IP地址为192.0.2.1/24网段的用户访问IoT的权限,且要求只能在2019-01-01 00:00:00之前访问和通过HTTPS访问。

    {
      "Statement": [
        {
          "Effect": "Allow", 
          "Action": "iot:*", 
          "Resource": "*", 
          "Condition": {
            "IpAddress": {
              "acs:SourceIp": [
                "192.0.2.1/24"
              ]
            }, 
            "DateLessThan": {
              "acs:CurrentTime": "2019-01-01T00:00:00+08:00"
            }, 
            "Bool": {
              "acs:SecureTransport": "true"
            }
          }
        }
      ], 
      "Version": "1"
    }
  • 拒绝访问的授权策略示例。

    场景:拒绝访问IP地址为198.51.100.1的用户对IoT执行读操作。

    {
      "Statement": [
        {
          "Effect": "Deny", 
          "Action": [
            "iot:Query*", 
            "iot:List*", 
            "iot:Get*", 
            "iot:BatchGet*"
          ], 
          "Resource": "*", 
          "Condition": {
            "IpAddress": {
              "acs:SourceIp": [
                "198.51.100.1"
              ]
            }
          }
        }
      ], 
      "Version": "1"
    }

授权策略创建成功后,将此权限授予RAM用户,获得授权的RAM用户就可以进行权限中定义的操作。创建RAM用户和授权操作,请参见RAM用户访问