【问题标题】:How to restrict AWS access based on region?如何根据区域限制 AWS 访问?
【发布时间】:2021-11-24 21:25:32
【问题描述】:

我正在关注此 AWS 文档,了解如何根据区域拒绝访问 AWS 资源:https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_deny-requested-region.html

这是我的 IAM 政策,当我尝试访问该帐户时,我什至看不到下面“条件”中描述的区域资源。访问“eu-central-1”的 EC2 控制台时出错:You are not authorized to perform this operation

我的目标是限制对条件中不存在的区域的任何资源的访问。例如,我想对“eu-central-1”拥有完全访问权限,但对“ap-northeast-1”没有访问权限

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyAccessNotListedRegions",
            "Effect": "Deny",
            "NotAction": [
                "cloudfront:*",
                "iam:*",
                "route53:*"
            ],
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:RequestedRegion": [
                        "eu-central-1",
                        "eu-west-3",
                        "eu-west-2",
                        "eu-west-1"
                    ]
                }
            }
        }
    ]
}

【问题讨论】:

  • 看到您创建了一个有效的策略。我可以建议您将其发布为答案吗?我已经删除了我的,因为它走错了方向。
  • 是的,我会这么做的。

标签: amazon-web-services amazon-iam


【解决方案1】:

这是我找到的解决方案:

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Sid":"AllowAccessAllRegionListed",
         "Effect":"Allow",
         "Action":"*",
         "Resource":"*",
         "Condition":{
            "StringEquals":{
               "aws:RequestedRegion":[
                  "eu-central-1",
                  "eu-west-3",
                  "eu-west-2",
                  "eu-west-1"
               ]
            }
         }
      },
      {
         "Sid":"AllowAccessGlobalServices",
         "Effect":"Allow",
         "Action":[
            "cloudfront:*",
            "iam:*",
            "route53:*"
         ],
         "Resource":"*"
      },
      {
         "Sid":"DenyAccessNotListedRegionsExceptGlobalServices",
         "Effect":"Deny",
         "NotAction":[
            "cloudfront:*",
            "iam:*",
            "route53:*"
         ],
         "Resource":"*",
         "Condition":{
            "StringNotEquals":{
               "aws:RequestedRegion":[
                  "eu-central-1",
                  "eu-west-3",
                  "eu-west-2",
                  "eu-west-1"
               ]
            }
         }
      }
   ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 2011-11-03
    相关资源
    最近更新 更多