- Newest
- Most votes
- Most comments
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.
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:SourceIpcondition clause, or set up VPC endpoints reachable from your internal network and useaws:SourceVpcoraws:SourceVpceto 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.
Relevant content
asked 3 years ago

There is also a key called "aws:SourceVpce" but it can only be used for communication via a VPC endpoint. Therefore, by connecting the on-premises environment to the VPC using a VPN or similar method, creating VPC endpoints for IAM and STS, and enabling access from GitLab to those VPC endpoints, it should be possible. https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_interface_vpc_endpoints.html