博客园  :: 首页  :: 管理

关于AWS下IAM-policy的编写规则说明

Posted on 2022-11-24 16:32  520_1351  阅读(337)  评论(0编辑  收藏  举报

aws中policy,也即是策略,可以通过编写策略配置权限,然后将policy附加到【Role,User group ,User】上

因此policy是非常基本的元素,它分为普通policy和inline policy,两种都是可以绑定到如上三种实体中,而且编写规则一样

这里笔者简单以一段policy,展示一下其结构,也好进行理解,如下放开kms和ec2服务相关的全部权限

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "kms:*",
                "ec2:*"
            ],
            "Resource": "*"
        }
    ]
}

一个policy中,始终都会有一个Version和Statement声明,Version一般都是写2012-10-17,目前都是写个,还有就是很早期的2008-10-17,已经很少见了

然后下方可以有多个Statement片段,第一个片段使用{}包含起来,多个片段之间使用逗号隔开

关于Action 和 Resource,都是可以写多个元素的,同样也是以逗号分隔,有些相对复杂的情况下,还可能会在Statement片段内部使用上Condition 条件字段

 

还有关于Sid这里也说明一下,官网解释如下:

You can provide an optional identifier, Sid (statement ID) for the policy statement. You can assign a Sid value to each statement in a statement array. In services that let you specify an ID element, such as SQS and SNS, the Sid value is just a sub-ID of the policy document ID. In IAM, the Sid value must be unique within a JSON policy.

The Sid element supports ASCII uppercase letters (A-Z), lowercase letters (a-z), and numbers (0-9).

IAM does not expose the Sid in the IAM API. You can't retrieve a particular statement based on this ID.

Note:>>>>>>
Some Amazon services (for example, Amazon SQS or Amazon SNS) might require this element and have uniqueness requirements for it. For service-specific information about writing policies, refer to the documentation for the service you work with.

这个元素笔者也测试过,一个policy - Statement 内,就算有多个Statement 片段,sid都可以不写

但是如果写了,就不允许有重复的,而且只能由 大写字母 小写字母 数字 三种字符组成,否则会有报错,无法保存

关于IAM相关的文档,可以参考:https://docs.amazonaws.cn/en_us/IAM/latest/UserGuide/introduction.html

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/16922316.html