Coder Social home page Coder Social logo

oasys / terraform-aws-cloudfront-auth Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 4.0 429 KB

Terraform module to build a website protected by OpenID authentication provider using a private S3 bucket fronted by Cloudfront and Lambda@Edge.

License: GNU General Public License v3.0

HCL 13.48% JavaScript 85.92% Shell 0.60%
terraform openid okta terraform-cloud cloudfront lambda-edge s3-website

terraform-aws-cloudfront-auth's Introduction

Terraform CloudFront Auth

Version: v1.0.2 License: GPL v3

Introduction

This module will build a website that is protected by an OpenId-compatible authentication provider. It will provision a private S3 bucket, Cloudfront, and deploy a customized Lambda function using Lambda@Edge.

Currently only OKTA is supported, but can easily be extended to support others (Google/Microsoft/GitHub/Auth0/Centrify).

Based on

This project uses the nodejs code from Widen for the Lambda function. Their repository includes a build.js script that interactively prompts for configuration items (client_id, client_secret, etc.) and builds the lambda zip file. This does not lend itself well to automation; this repository replaces that logic with build.tf and local-exec resources create the archive.

The Scale Factory team created the (now hibernating) terraform-cloudfront-auth project to allow passing environment variables to the Widen build.js script. Their project still requires executing the nodejs script, which does not work for environments where those dependencies are not available, such as a Terraform Cloud runner.

Caveats

The archive_file data source is used in this project. Terraform will always generate a plan to modify resources, even when a terraform apply will make no changes. This will generate false positives when terraform plan is run periodically to check for configuration drift.

Usage

data "aws_acm_certificate" "cert" {
  domain = "*.example.com"
}

module "cloudfront_okta" {
  source        = "oasys/cloudfront-auth/aws"
  version       = "1.0.2"
  hostname      = "www.example.com"
  acm_cert_arn  = data.aws_acm_certificate.cert.arn
  auth_provider = "OKTA"
  client_id     = okta_app_oauth.www.client_id
  client_secret = okta_app_oauth.www.client_secret
  redirect_uri  = "https://www.example.com/_callback"
  base_url      = "https://example.okta.com"
  deploy_arn    = var.deploy_arn
}

A more comprehensive example is included in the example/ directory.

Inputs

Name Description Type Default Required
acm_cert_arn ARN of AWS Certificate Manager certificate for website. string n/a yes
aliases List of any aliases (CNAMEs) for the website. list(string) [] no
always_rebuild Always create new lambda zip source directory. Useful for environments, such as Terraform Cloud, where the terraform runner does not preserve local disk contents. bool true no
auth_provider Authentication provider. Currently only 'OKTA' is supported. string "OKTA" no
base_url The base_url or Org URL of the authentication provider. string n/a yes
client_id The client_id from authentication provider. string n/a yes
client_secret The client_secret from authentication provider. string n/a yes
deploy_arn (Optional) IAM user to give permissions to update site (via s3 bucket). string null no
hostname Hostname of the managed website. string n/a yes
redirect_uri The URI to redirect users to after successful login. Defaults to /_callback on hostname. string null no
s3_bucket_name Name of website S3 bucket. Must be globally unique. Defaults to hostname. string null no
session_duration Length of time session will be valid. number 24 no
tags Common tags for created resources map(any) {} no

Outputs

Name Description
cloudfront_distribution CloudFront distribution
lambda_function Lambda function
s3_bucket S3 bucket

License

This project is licensed under the GNU GPLv3. Please use and change to suit your needs.

This repository includes the source from Widen's cloudfront-auth project and its dependencies, compliant with the project's license.


terraform-aws-cloudfront-auth's People

Contributors

oasys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

terraform-aws-cloudfront-auth's Issues

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.