Search code examples
ruby-on-railswebserveramazon-cloudfront

Amazon cloudfront custom origin rails with authentication


As far I understand, custom origin server with cloudfront only works if cloudfront is able to access files from my website url:

eg: www.domain.com/hello.html

However, my website has a login requirement in order to view hello.html. How can I have the login mechanism and still cache my real hello.html page in cloudfront using custom origin server?

I am using Ruby on Rails btw, but this is applicable to other stacks as well.


Solution

  • I'm pretty sure this is not possible. As you said, CloudFront has be to able to access the file to serve and cache it. I never saw an option to tell CloudFront to use a password to access the file.

    An idea: maybe you can check in your Rails app, before you require the user to enter a password, if the request comes from CloudFront (I'm sure there are some headers indicating that) and, if so, bypass the login requirement?

    Edit:

    It says in the docs:

    Do not configure your origin server to request client authentication.
    

    One thing I'm pretty sure set though is the User Agent. Check for user_agent =~ /cloudfront/iand bypass authentication?