Coder Social home page Coder Social logo

chrisfinne / aws-s3-basic-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sjakthol/aws-s3-basic-auth

0.0 1.0 0.0 6 KB

Enforce HTTP Basic Authentication for S3 buckets with CloudFront and Lambda@Edge.

License: MIT License

JavaScript 19.49% Python 55.64% Makefile 24.88%

aws-s3-basic-auth's Introduction

Enforce HTTP Basic Authentication for S3 buckets with CloudFront and Lambda@Edge.

How It Works?

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:

  • If the request doesn't have an Authorization header, it returns a 401 Unauthorized response to the client with a WWW-Authenticate: Basic header to trigger Basic Auth prompt the client browser.
  • If the request contains an Authorization header, the token is compared against pre-configured credentials. If the credentials match, the request is approved. If the credentials are invalid, a 403 Forbidden response is sent to the client.

The setup also includes a custom CloudFront Origin Access Identity that is used to access the origin bucket in S3. It creates a bucket policy for the target bucket that allows access from this custom OAI only. That is, the bucket cannot be accessed directly but all requests must go through the CloudFront distribution.

Deployment

The deployment of this setup is fully automated via CloudFormation. The stacks/ directory contains a CloudFormation template (s3-basic-auth.yaml) that sets everything up. It takes the following parameters:

  • AuthorizationCredentials - base64 encoded credentials that grant access to the bucket
  • OriginBucketName - the name of the S3 bucket to provide protected access to
  • UpdateTime - current timestamp (value is not important; should be different from previous oneex)

AuthorizationCredentials can be generated as follows (replace username and password with the respective values):

echo -n "username:password" | base64

Deploying the Stack

To deploy the stack, run the following:

make create-basic-auth AUTHORIZATION_CREDENTIALS=<base64 credentials> ORIGIN_BUCKET_NAME=<your bucket>

To update the stack, run the following:

make update-basic-auth AUTHORIZATION_CREDENTIALS=<base64 credentials> ORIGIN_BUCKET_NAME=<your bucket>

You can also deploy the stack directly with the AWS CLI or Console.

aws-s3-basic-auth's People

Contributors

sjakthol avatar chrisfinne avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.