Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Cloudfront and .htaccess

I'm testing out Amazon Cloudfront in our dev environment, which is protected by .htaccess/.htpasswd. The password protection on the dev server is causing all of the cloudfront.net assets to be password protected as well. And no username/password combination works.

What I need to do is allow cloudfront to access the dev server by poking some holes in the .htaccess protection.

I can get a list of IP addresses here but since they are subject to change, I was wondering if anyone knew of a better way.

I cannot remove the password protection unfortunately.

like image 504
Scott Joudry Avatar asked Oct 20 '22 04:10

Scott Joudry


1 Answers

Here's what I've been using:

SetEnvIf User-Agent ^Amazon Cloudfront$ cdn
SetEnvIf Host ^static.dev.website.com$ cdn # This could also be a cloudfront.net host

AuthType Basic
AuthName "Dev Site"
AuthUserFile /directory/location/.htpasswd
Require valid-user

Order Deny,Allow
Deny from all
Allow from env=cdn
Satisfy Any

Essentially, you need you exclude CloudFront-related requests, which the first two lines handle, in conjunction with the Allow from env=cdn line.

like image 147
Melissa Avery-Weir Avatar answered Oct 24 '22 13:10

Melissa Avery-Weir