1
votes

I have a web server behind a load balancer which is behind a cloudfront distribution. The idea for the cloudfront distribution with load balancer as origin was to restrict requests to the load balancer to only come from a front end web app. I followed this tutorial https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/restrict-access-to-load-balancer.html ensuring that

  1. the elb origin cloudfront distribution puts in an origin header with a secret key value pair and
  2. the load balancer has a rule to check for the http header with the correct key and value.

Hitting the loadbalancer directly with its DNS gives the expected 403 as desired. However, with postman when I make requests to the Cloudfront dns I get a 403.

Cloudfront ELB Origin Configuration:

enter image description here

Load Balancer Rule:

enter image description here

Error Message from Postman:

enter image description here

UPDATE:

I've added an error response action so that it redirects to the 'root' of my api. After doing this, requests with Postman no longer returns the 403 error from Cloudfront but returns the fixed 403 response message configured in the loadbalancer listener rule. It seems this way the request at least makes it through to the load balancer. Does this mean that the origin header is not being passed by Cloudfront? Also when I make a GET request to one of my endpoints pointing to the Cloudfront DNS with curl in the terminal it returns a good response, while the same request fails with Postman. Any other endpoint fails whether with curl or Postman with the 403 message of the listener rule.

enter image description here

1
What header name and value are you using? Feel free to post it after you change it to something that's not confidential. - jellycsc
x-cloudfrontHeader, cloudfrontValue123 - minh ly
Are you using the default dns name of the ELB as the CF origin? - jellycsc
What's the security group associated with the ELB? - jellycsc
my ELB security group accepts global ingress http requests and egress is TCP connection out to port 8080 on which my server is listening with my ec2 security group as destination. And yes, the ELB DNS is origin for CF. - minh ly

1 Answers

0
votes

I could not reproduce the issue that you are having. Here is my working ELB and CF config:

CF

ELB