49

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?

2
  • 5
    to my future self: WAF is super expensive. lambda@edge is probably the better option for most usecases. list of ips/rules can be stored in s3 to allow for dynamic updates. Aug 13, 2019 at 23:33
  • 1
    Lambda@edge is $0.60/million invocations. WAF is about $0.60/million requests. So they are actually about the same price. I believe WAF price was recently reduced. Sep 5, 2019 at 19:35

3 Answers 3

60

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.

2
29

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!

-1

use cloudfront lambda or function to judge X-Forwarded-For Header

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.