阅读805 返回首页    go 搜狐


自定义权限__授权管理_阿里云物联网套件-阿里云

自定义权限

Action 定义

Action 是 API 的名称,可以根据 Action 设置开放或限制用户可以访问的 API。在创建IOT的授权策略时,每个 Action 都需要添加“iot:”前缀,多个 Action 以逗号分隔,并且支持星号通配符(包括前缀匹配和后缀匹配)。

典型的 Action 定义

下面是一些典型的 Action 定义。

  • 单个 API。
  1. "Action": "iot:CreateProduct"
  • 多个 API。

    1. "Action": [
    2. "iot:UpdateProduct",
    3. "iot:QueryProduct"
    4. ]
  • 所有只读 API。

  1. {
  2. "Version": "1",
  3. "Statement": [
  4. {
  5. "Action": [
  6. "rds:DescribeDBInstances",
  7. "rds:DescribeDatabases",
  8. "rds:DescribeAccounts",
  9. "rds:DescribeDBInstanceNetInfo"
  10. ],
  11. "Resource": "*",
  12. "Effect": "Allow"
  13. },
  14. {
  15. "Action": "ram:ListRoles",
  16. "Effect": "Allow",
  17. "Resource": "*"
  18. },
  19. {
  20. "Action": "mns:ListTopic",
  21. "Resource": "*",
  22. "Effect": "Allow"
  23. },
  24. {
  25. "Action": [
  26. "dhs:ListProject",
  27. "dhs:ListTopic",
  28. "dhs:GetTopic"
  29. ],
  30. "Resource": "*",
  31. "Effect": "Allow"
  32. },
  33. {
  34. "Action": [
  35. "ots:ListInstance",
  36. "ots:ListTable",
  37. "ots:DescribeTable"
  38. ],
  39. "Resource": "*",
  40. "Effect": "Allow"
  41. },
  42. {
  43. "Action": [
  44. "log:ListShards",
  45. "log:ListLogStores",
  46. "log:ListProject"
  47. ],
  48. "Resource": "*",
  49. "Effect": "Allow"
  50. },
  51. {
  52. "Effect": "Allow",
  53. "Action": [
  54. "iot:Query*",
  55. "iot:List*",
  56. "iot:Get*",
  57. "iot:BatchGet*"
  58. ],
  59. "Resource": "*"
  60. }
  61. ]
  62. }
  • 所有读写 API。
    1. {
    2. "Version": "1",
    3. "Statement": [
    4. {
    5. "Action": [
    6. "rds:DescribeDBInstances",
    7. "rds:DescribeDatabases",
    8. "rds:DescribeAccounts",
    9. "rds:DescribeDBInstanceNetInfo"
    10. ],
    11. "Resource": "*",
    12. "Effect": "Allow"
    13. },
    14. {
    15. "Action": "ram:ListRoles",
    16. "Effect": "Allow",
    17. "Resource": "*"
    18. },
    19. {
    20. "Action": "mns:ListTopic",
    21. "Resource": "*",
    22. "Effect": "Allow"
    23. },
    24. {
    25. "Action": [
    26. "dhs:ListProject",
    27. "dhs:ListTopic",
    28. "dhs:GetTopic"
    29. ],
    30. "Resource": "*",
    31. "Effect": "Allow"
    32. },
    33. {
    34. "Action": [
    35. "ots:ListInstance",
    36. "ots:ListTable",
    37. "ots:DescribeTable"
    38. ],
    39. "Resource": "*",
    40. "Effect": "Allow"
    41. },
    42. {
    43. "Action": [
    44. "log:ListShards",
    45. "log:ListLogStores",
    46. "log:ListProject"
    47. ],
    48. "Resource": "*",
    49. "Effect": "Allow"
    50. },
    51. {
    52. "Effect": "Allow",
    53. "Action": "iot:*",
    54. "Resource": "*"
    55. }
    56. ]
    57. }

Condition 定义

目前 Policy 支持访问 IP 限制、是否通过 https 访问、是否通过 MFA(多因素认证)访问和访问时间限制等多种鉴权条件,物联网套件的所有 API 都已经支持这些条件。

访问 IP 限制

访问控制 RAM 可以限制访问表格存储的源 IP 地址,并且支持根据网段进行过滤。下面是一些典型的使用场景。

  • 限制多个 IP 地址。例如,只允许 IP 地址为 10.101.168.111 和 10.101.169.111 的请求访问。
  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Allow",
  5. "Action": "iot:*",
  6. "Resource": "*",
  7. "Condition": {
  8. "IpAddress": {
  9. "acs:SourceIp": [
  10. "10.101.168.111",
  11. "10.101.169.111"
  12. ]
  13. }
  14. }
  15. }
  16. ],
  17. "Version": "1"
  18. }
  • 限制单个 IP 地址和 IP 网段。例如,只允许 IP 地址为 10.101.168.111 或 10.101.169.111/24 网段的请求访问。

    1. {
    2. "Statement": [
    3. {
    4. "Effect": "Allow",
    5. "Action": "iot:*",
    6. "Resource": "*",
    7. "Condition": {
    8. "IpAddress": {
    9. "acs:SourceIp": [
    10. "10.101.168.111",
    11. "10.101.169.111/24"
    12. ]
    13. }
    14. }
    15. }
    16. ],
    17. "Version": "1"
    18. }

https 访问限制

访问控制可以限制是否通过 https 访问,下面是典型的使用场景。

限制请求必须通过 https 访问。

  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Allow",
  5. "Action": "iot:*",
  6. "Resource": "*",
  7. "Condition": {
  8. "Bool": {
  9. "acs:SecureTransport": "true"
  10. }
  11. }
  12. }
  13. ],
  14. "Version": "1"
  15. }

MFA 访问限制

访问控制可以限制是否通过 MFA(多因素认证)访问,下面是典型的使用场景。

限制请求必须通过 MFA 访问。

  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Allow",
  5. "Action": "iot:*",
  6. "Resource": "*",
  7. "Condition": {
  8. "Bool": {
  9. "acs:MFAPresent ": "true"
  10. }
  11. }
  12. }
  13. ],
  14. "Version": "1"
  15. }

访问时间限制

访问控制可以限制请求的访问时间,即只允许或拒绝在某个时间点范围之前的请求。下面是典型的使用场景。

例如,北京时间 2016 年 1 月 1 号凌晨之前用户可以访问,之后就不能再访问。

  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Allow",
  5. "Action": "iot:*",
  6. "Resource": "*",
  7. "Condition": {
  8. "DateLessThan": {
  9. "acs:CurrentTime": "2016-01-01T00:00:00+08:00"
  10. }
  11. }
  12. }
  13. ],
  14. "Version": "1"
  15. }

典型使用场景

结合上面对 Action、Resource 和 Condition 的定义,下面列出一些典型使用场景的 Policy 定义和授权方法。

多种授权条件

对于访问 IP 地址为 10.101.168.111/24 网段的用户,可以访问自定义的权限,且要求只能在 2016-01-01 00:00:00 之前访问和通过 https 访问。

操作步骤

  1. 使用主账号登录访问控制 RAM 的管理控制台。(默认已开通访问控制服务)

  2. 单击页面左侧的策略管理,进入策略管理页面。

  3. 单击页面右侧的新建授权策略按钮,进入创建授权策略的页面。

  4. 选中“空白模板”,进入创建自定义授权策略的页面。

  5. 填写授权策略名称,并将如下内容填写至策略内容栏。

  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Allow",
  5. "Action": "iot:*",
  6. "Resource": "*",
  7. "Condition": {
  8. "IpAddress": {
  9. "acs:SourceIp": [
  10. "10.101.168.111/24"
  11. ]
  12. },
  13. "DateLessThan": {
  14. "acs:CurrentTime": "2016-01-01T00:00:00+08:00"
  15. },
  16. "Bool": {
  17. "acs:SecureTransport": "true"
  18. }
  19. }
  20. }
  21. ],
  22. "Version": "1"
  23. }
  1. 单击新建授权策略,授权策略新建成功,然后单击关闭

  2. 单击页面左侧的用户管理,进入用户管理页面将刚才新建的策略授权给需要的子账号。

  3. 找到需要授权的子账号,单击其右侧操作栏下面的授权按钮,进入“编辑个人授权”页面。

  4. 搜索刚才新建的策略名称,选中后单击 > 以将该权限添加至“已选择授权策略名称”栏中,最后单击确定,完成对该账号的策略授权。

拒绝请求

对于访问 IP 地址为 10.101.169.111 的用户,拒绝对北京域的名称以 online 和 product 开头的 Instance 下面的所有 Table 执行写操作(不包括对 Instance 的操作)。策略内容如下,创建自定义授权策略和给子账号授权的步骤同上。

  1. {
  2. "Statement": [
  3. {
  4. "Effect": "Deny",
  5. "Action": [
  6. "iot:Query*",
  7. "iot:List*",
  8. "iot:Get*",
  9. "iot:BatchGet*"
  10. ],
  11. "Resource": "*",
  12. "Condition": {
  13. "IpAddress": {
  14. "acs:SourceIp": [
  15. "10.101.169.111"
  16. ]
  17. }
  18. }
  19. }
  20. ],
  21. "Version": "1"
  22. }

最后更新:2016-11-24 15:57:38

  上一篇:go 进阶使用 STS__授权管理_阿里云物联网套件-阿里云
  下一篇:go RAM 和 STS 介绍__授权管理_阿里云物联网套件-阿里云