Skip to content

Terraform module to provision CloudFront Distribtition with Lambda@Edge authorization backed by a private S3 origin

License

Notifications You must be signed in to change notification settings

reyntjensw/terraform-cloudfront-auth

 
 

Repository files navigation

terraform-cloudfront-auth Latest Release License

A Terraform module to provision a Cloudfront distribution to serve private content in an S3 bucket with Lamba@Edge Google/Microsoft/Github/Okta/Auth0/Centrify/AWS Cognito authentication. Based on Widen - Cloudfront Auth


Screenshots

Example Example using GitHub authentication

Introduction

You should use this module if you have a private S3 bucket that you want to guard with Google/Microsoft/Github/Okta/Auth0/Centrify authentication.

The Terraform packages up cloudfront-auth into a Lambda function to be used by Cloudfront's Lambda@Edge. A private S3 bucket and Cloudfront Distribution will also be created.

Usage

NOTE: You will need to create a certificate with AWS Certificate Manager in the us-east-1 region. The example below assumes a certificate for the domain example.com already exists.

module "cloudfront_auth" {
  source                         = "git::https://github.com/scalefactory/terraform-cloudfront-auth.git?ref=master"

  auth_vendor                    = "github"
  cloudfront_distribution        = "private.example.com"
  client_id                      = "CHANGE_ME"
  client_secret                  = "CHANGE_ME"
  redirect_uri                   = "https://private.example.com/callback"
  github_organization            = "exampleorg"

  bucket_name                    = "private.example.com"
  region                         = "eu-west-1"
  cloudfront_acm_certificate_arn = "${data.aws_acm_certificate.example.arn}"
}

data "aws_acm_certificate" "example" {
  domain   = "example.com"
  statuses = ["ISSUED"]
}

Examples

A Full working example can be found in example folder. Please update the cloudfront_auth module parameters. NOTE: The certificate will need validating with email first.

Inputs

Provider specific Inputs

Provider specific inputs marked required are only required for the specific auth vendor. E.g hd is not required if you are using the github auth vendor.

Google

Name Description Type Default Required
hd The hosted domain (e.g example.com) string `` yes
authz The authorization method: (1) Hosted Domain - verify email's domain matches that of the given hosted domain\n (2) HTTP Email Lookup - verify email exists in JSON array located at given HTTP endpoint\n (3) Google Groups Lookup - verify email exists in one of given Google Groups string 1 yes

Microsoft

Name Description Type Default Required
authz The authorization method: (1) Azure AD Login (default)\n (2) JSON Username Lookup string 1 yes

GitHub

Name Description Type Default Required
github_organization The github organization that owns the auth application string `` yes

Standard

Name Description Type Default Required
auth_vendor The vendor to use for authorisation (google, microsoft, github, okta, auth0, centrify) string `` yes
cloudfront_distribution The FQDN of your cloudfront distribution you want to use to serve your private content (e.g www.example.com) string `` yes
client_id The client id of the auth application string `` yes
client_secret The client secret of the auth application string `` yes
session_duration Session duration in hours string 1 no
bucket_name The name of your S3 bucket string `` yes
region Region to launch your bucket in string `` yes
tags Tags to label resources with (e.g map('dev', 'prod')) map <map> no
cloudfront_aliases List of FQDNs to be used as alternative domain names (CNAMES) for Cloudfront list <list> no
cloudfront_price_class Cloudfront price classes: PriceClass_All, PriceClass_200, PriceClass_100 string PriceClass_All no
cloudfront_default_root_object The default root object of the Cloudfront distribution string index.html no
cloudfront_acm_certificate_arn The ARN of the ACM managed Certificate for the Cloudfront distribution (e.g arn:aws:acm:us-east-1:111111111111:certificate/40eae56f-3acf-4009-89a5-3f3e0fdba331). NOTE: The certificate must be created in the us-east-1 region to work with Cloudfront string `` yes

Outputs

Name Description
s3_bucket The name of the S3 Bucket
cloudfront_arn ARN of the Cloudfront Distribution
cloudfront_id ID of the Cloudfront Distribution

References

For additional context, refer to some of these links.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

We welcome all pull requests to our open source projects. We follow "fork-and-pull" Git workflow.

  1. Fork the repository on GitHub
  2. Clone your fork to your local development environment
  3. Commit changes to your own branch in your project
  4. Push your changes back to GitHub
  5. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

Copyrights

Copyright © 2019-2019 The Scale Factory Ltd.

Copyright © 2017-2019 Widen Enterprises

License

License: ISC

ISC License (ISC)

Copyright (c) 2019, The Scale Factory Ltd.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Source: https://opensource.org/licenses/ISC

About

This project is maintained by The Scale Factory. Like it? Please give it a ★.

Scale Factory

We're a DevOps and Cloud Infrastructure Consultancy company based in London, UK. We love empowering teams to deliver more with AWS.

Check out our other projects, follow us on twitter, or hire us to help with your cloud strategy and implementation.

Contributors

Steve Porter
Steve Porter
Markiian Slipets
Markiian Slipets

About

Terraform module to provision CloudFront Distribtition with Lambda@Edge authorization backed by a private S3 origin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 62.7%
  • HCL 33.0%
  • HTML 3.3%
  • Makefile 1.0%