How to create a boundary to restrict access to specific region?

I am trying to create different boundary policies for dev, staging and production restricting each to specific regions. For dev, we’re restricting to “eu-north-1”. I am using a federated user to login and test this, but I am getting errors, and am unsure where I am going wrong.

Dev, for example, I created a role with the following test boundary policy attached :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyAllOutsideRequestedRegions",
            "Effect": "Deny",
            "NotAction": [
                "cloudfront:*",
                "iam:*",
                "route53:*",
                "support:*"
            ],
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:RequestedRegion": [
                        "eu-north-1"
                    ]
                }
            }
        }
    ]
}

I added a test inline policy to the role as follows:

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

The trust relationship is as follows:

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Principal”: {
“AWS”: “arn:aws:iam::<ACCOUNT_ID>:root”
},
“Action”: “sts:AssumeRole”,
“Condition”: {}
}
]
}

I then switch to that role and attempt to go to the IAM dashboard but see API errors :
User: arn:aws:sts::<ACCOUNT_ID>:assumed-role/test-boundary-role/<USER_ID> is not authorized to perform: iam:GetAccountSummary on resource: * because no permissions boundary allows the iam:GetAccountSummary action

What am I missing here?

IAM actions probably fall under us-east-1

it does indeed, however according to this guide which I followed https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_deny-requested-region.html

It states on there: This policy uses the NotAction element with the Deny effect, which explicitly denies access to all of the actions not listed in the statement. Actions in the CloudFront, IAM, Route 53, and AWS Support services should not be denied because these are popular AWS global services with a single endpoint that is physically located in the us-east-1 Region. Because all requests to these services are made to the us-east-1 Region, the requests would be denied without the NotAction element.

The action must be explicitly allowed in its Permission Boundary.

ok, perhaps I am approaching it wrong then… my goal is to have a role which has a boundary only restricted to a specfic region (allowing all actions in that region and allowing some global actions such as iam, etc.) - but then the actual policy attached to that role has the tighter restrictions specifically for that role, eg. create and destroy ec2 instances in specific VPCs

For an action to be allowed, it must be explicitly allowed in both the principal’s Permission Boundary and in either its IAM policy or for some resources (e.g., S3 bucket) a resource-based policy on the target resource without being explicitly denied in any of the applicable policies.

And in the case of a member account in an AWS Org, it must also be explicitly allowed via Org-layer SCPs without being explicitly denied.

So one option is to add a statement to the Permission Boundary that allows all actions on all resources. Your region denial statement would still take precedence, and effective permissions would still be limited by the more granular IAM policies.

Alternatively you could just put the deny statement directly in the IAM policy and not use a boundary. Or if this is a member account in an Org you could enforce region restrictions via SCPs, especially if it should apply to more principals.

Thanks adding the “allow all” has solved my question :slight_smile:

can u share the new policy json with us? thank you