Skip to content

How I can limit my role trust policy to a corporate CIDR range?

0

I have a role defined which is cross account assumed by a central technical user

Account A - techuser

Account B - role2assume

In the trust policy of the role2assume I limit the "sts:AssumeRole" to the user from Account A in conjunction with an external ID. Now I want to further limit the assumption to a specific IP CIDR within our corporate network (only access via VPN). Following Policy returns with the error "No private IP CIDR allowed", where as https://aws.amazon.com/de/blogs/security/establishing-a-data-perimeter-on-aws/ states that SourceIP can contain a corporate Network range.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<ACCOUNTA>:user/techuser"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "sts:ExternalId": "<EXTERNALID>"
                }
            }
        },
	{
            "Effect": "Deny",
            "Action": "*",
            "Resource": "*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "10.0.0.0/16"
                },
                "Bool": {
                    "aws:ViaAWSService": "false"
                }
            }
        }
    ]
}

asked 2 years ago451 views

2 Answers
4

Hello.

"aws:SourceIp" can be controlled using a public IP address, but cannot be controlled using a private IP address.
In other words, you cannot restrict connections from private IP addresses.
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceip

Use this key to compare the requester's IP address with the IP address that you specify in the policy. The aws:SourceIp condition key can only be used for public IP address ranges.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

0

Okay, so the documentation in the link I shared is an way misleading?

Is there any other way to limit access to a private CIDR range? We adopted this approach https://learnaws.cloud/gitlab/securely-deploy-from-gitlab-to-aws-using-iam-assume-roles/ and want to further limit access to the role only to the Gitlab instances running locally.

answered 2 years ago

  • Your private IPs are only visible inside your private network. If you call an AWS API endpoint on the public internet, you won't be sending the request over the internet from your private IP. You'll be sending it from a public NAT address of your corporate firewall, and that's the IP you'll be showing to AWS. As Riku Kobayashi correctly explained, you'll either need to put your internet-facing NAT addresses of your firewall in the aws:SourceIp condition clause, or set up VPC endpoints reachable from your internal network and use aws:SourceVpc or aws:SourceVpce to restrict access.

  • The phrase "corporate address range" in the document is quite correct but it refers to the IP addresses your corporation uses to connect to the relevant AWS service endpoint. Usually, you'll do that over the public internet, and the corporate address range is the public IP or range of them used for NATing on your firewall. You can also do it over an internal network connection, such as over a VPN, to a VPC with the relevant endpoint, but in general, that's a relatively advanced and unusual setup that you'd know about.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.