S3存储桶策略有多种条件

时间:2017-08-22 18:05:58

标签: amazon-s3

我希望授予对存储桶的访问权限,该存储桶允许我的VPC中的实例通过我们的数据中心与机器一起完全访问它。如果没有aws:SouceIp行,我可以限制对VPC在线计算机的访问。

我需要使用该策略,以便只能从VPC内的计算机和办公室访问该存储桶。

{
    "Version": "2012-10-17",
    "Id": "Policy1496253408968",
    "Statement": [
        {
            "Sid": "Stmt1496253402061",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::xyz-sam-test/*",
                "arn:aws:s3:::xyz-sam-test"
            ],
            "Condition": {
                "StringLike": {
                    "aws:sourceVpc": "vpc-dcb634bf",
                    "aws:SourceIp": "<MY PUBLIC IP>"                                  
                }
            }
        }
    ]
}

2 个答案:

答案 0 :(得分:0)

当两个密钥的条件Effect与那些特定的通配符匹配时,您可以生成一个策略,其Deny用于StringNotLike访问存储桶。

{
    "Version": "2012-10-17",
    "Id": "Policy1496253408968",
    "Statement": [
        {
            "Sid": "Stmt1496253402061",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::xyz-sam-test/*",
                "arn:aws:s3:::xyz-sam-test"
            ],
            "Condition": {
                "StringNotLike": {
                    "aws:sourceVpc": "vpc-dcb634bf",
                    "aws:SourceIp": "<MY PUBLIC IP>"                                  
                }
            }
        }
    ]
}

第二个条件也可以分隔为自己的语句。 AWS在语句之间应用逻辑或。 1

{
    "Version": "2012-10-17",
    "Id": "Policy1496253408968",
    "Statement": [
        {
            "Sid": "Stmt1496253402061",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::xyz-sam-test/*",
                "arn:aws:s3:::xyz-sam-test"
            ],
            "Condition": {
                "StringLike": {
                    "aws:sourceVpc": "vpc-dcb634bf",                                
                }
            }
        },
        {
            "Sid": "Stmt1496253402062",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::xyz-sam-test/*",
                "arn:aws:s3:::xyz-sam-test"
            ],
            "Condition": {
                "StringLike": {
                    "aws:SourceIp": "<MY PUBLIC IP>"                                  
                }
            }
        }
    ]
}

答案 1 :(得分:0)

AWS 有预定义的条件运算符和键(如 aws:CurrentTime)。各个 AWS 服务还定义了特定于服务的密钥。

例如,假设您希望在以下条件下让用户 John 访问您的 Amazon SQS 队列:

时间是下午12:00以后。 2019/7/16

时间是下午3:00之前2019/7/16

请求来自 192.0.2.0 到 192.0.2.255 或 203.0.113.0 到 203.0.113.255 范围内的 IP 地址。

您的条件块具有三个独立的条件运算符,必​​须满足所有三个条件,John 才能访问您的队列、主题或资源。

以下显示了您的策略中条件块的外观。 aws:SourceIp 的两个值使用 OR 进行评估。三个独立的条件运算符使用 AND 求值。

"Condition" :  {
      "DateGreaterThan" : {
         "aws:CurrentTime" : "2019-07-16T12:00:00Z"
       },
      "DateLessThan": {
         "aws:CurrentTime" : "2019-07-16T15:00:00Z"
       },
       "IpAddress" : {
          "aws:SourceIp" : ["192.0.2.0/24", "203.0.113.0/24"]
      }
}

参考:https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_multi-value-conditions.html

相关问题