Restricting access to CloudFront by IP

39,555

Solution 1

Web Application Firewall is your friend.

http://docs.aws.amazon.com/waf/latest/developerguide/web-acl-ip-conditions.html

Create your rule with your IP Addresses and rest "WAF" will take care.

You need to apply this to the required CloudFront Distribution.

You can restrict your bucket policies to CloudFront and restrict to your required IP's through CloudFront.

Solution 2

I have created the custom rule to whitelist IPs and restrict the application with CloudFront distribution with following steps.

Steps:

  1. Go to AWS WAF.
  2. Create following IP match conditions under IP Addresses.

    1. staging-appname-whitelist-ips
  3. Create following rules under Rules.

    1. staging-appname-ui-stack-whitelisted-ips
      • with condition (similar for production one) enter image description here
  4. Finally create following Web ACLs:
    1. staging-appname-acl
      • Please select the correct CloudFront Distribution, above created Rule and IP Address group. *. enter image description here

AWS Resource here.

Hope it helps!

Share:
39,555
Moshe Shaham
Author by

Moshe Shaham

Node.js, Java Javascript, Angular, Typescript

Updated on July 09, 2022

Comments

  • Moshe Shaham
    Moshe Shaham almost 2 years

    I want to restrict bucket access to certain IPs. I know how to create a bucket policy from Restricting Access to Specific IP Addresses.

    My question: Can this work with CloudFront? How? Can I allow only certain IPs to access CloudFront?