Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic HTTP Auth for AWS S3 hosted site, similar to .htaccess

I have a static HTML site hosted on Amazon S3.

Ideally I want to be able to limit access to a staging site in the same way as with a .htaccess/.htpasswd file.

I understand that bucket policies can be used to limit access (I have already used one to make the bucket contents publicly accessible), but I can't see any way to limit access.

In an ideal situation I would like an auth prompt - but appending a token to a URL would also work.

like image 834
Leon Barrett Avatar asked Nov 15 '12 13:11

Leon Barrett


People also ask

How to implement basic authentication for Amazon S3 bucket?

The implementation relies on AWS CloudFront and Lambda@Edge functions to implement basic authentication for Amazon S3 bucket. CloudFront is used as a frontend to S3 access. A custom lambda function intercepts all requests to the CloudFront distribution and checks them for valid basic auth credentials as follows:

How is a HTTP request processed in Amazon S3?

HTTP request is processed by the service and then re-translated to Amazon S3 internal authentication scheme: This architecture diagram explains how the project is implemented. The PNG picture is loaded from Amazon S3 bucket maven.s3auth.com, which is not readable anonymously. Full URL of this image is Show activity on this post.

How do I create a basic HTTP authorization rule in AWS?

By layering multiple AWS services you can achieve something close to Basic HTTP Authorisation. Create a s3 static site. Use AWS WAF to create a rule which only allows requests with the correct http Authorization header. This will be a sting match rule on the contents of the Authorization header.

What S3 bucket do I need for a static website?

First, you’ll need two S3 buckets, both should match your custom domain name with the second including the www subdomain. The first bucket (mywebsite.com) is the main bucket for your site. This contains all your files and assets for your static website.


2 Answers

Yes, this is possible: checkout s3auth (no affiliation).

like image 135
J0hnG4lt Avatar answered Sep 26 '22 22:09

J0hnG4lt


I think the AWS SDK for Javascript is what you're looking for. It allows you to login with Facebook, Google or Amazon. Here's another resource using AWS login.

like image 24
Ryan Shillington Avatar answered Sep 24 '22 22:09

Ryan Shillington