Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide initial functionality #6

Merged
merged 50 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7ef247b
Remove unneeded files inherited from skeleton
dav3r Jul 20, 2022
508a2e5
Define initial set of variables and remove unneded variables from ske…
dav3r Jul 20, 2022
901ee32
Define providers
dav3r Jul 20, 2022
3eb46fc
Define Terraform backend
dav3r Jul 20, 2022
f98b238
Define Terraform remote states
dav3r Jul 20, 2022
cc23748
Define useful locals
dav3r Jul 20, 2022
ec85d81
Create S3 bucket where published file(s) will be stored
dav3r Jul 20, 2022
cb836cc
Define Terraform output and remove skeleton outputs
dav3r Jul 20, 2022
d601a21
Add IAM policy and role used by the publish-egress-ip Lambda
dav3r Jul 20, 2022
960c958
Define the Lambda function to publish egress IP addresses
dav3r Jul 20, 2022
945e649
Set up CloudFront distribution and related S3/Lambda resources
dav3r Jul 20, 2022
76f8639
Define DNS records that support CloudFront endpoints
dav3r Jul 20, 2022
58b0dbb
Replace skeleton README with useful documentation
dav3r Jul 21, 2022
4b1e088
Add gitignore entry for default lambda deployment package name
dav3r Jul 21, 2022
3a7ac2a
Add link to relevant issue for TODO comment
dav3r Jul 22, 2022
6cc0dea
Add gitignore entry for "add security headers" lambda zip file
dav3r Jul 22, 2022
afc37a3
Clarify the standard CloudFront Route53 zone ID
dav3r Jul 25, 2022
5b1fd54
Make lambda schedule interval a number instead of a string
dav3r Jul 26, 2022
bf838aa
Correct capitalization and grammar
dav3r Jul 26, 2022
4f581c4
Use more accurate verbiage in a variable description
dav3r Jul 26, 2022
93534a2
Sort some thangs alphabetically
dav3r Jul 26, 2022
3a7a298
Add some helpful backticks to variable descriptions
dav3r Jul 26, 2022
bcea047
Add a missing backslash character
dav3r Jul 26, 2022
d5374f9
Make default lambda schedule interval a number
dav3r Jul 26, 2022
c7979eb
Add a missing period
dav3r Jul 26, 2022
b469160
Add TagSession permission to Lambda assume role
dav3r Jul 26, 2022
af82155
Correct a typo in a variable description
dav3r Jul 26, 2022
fb0a0c1
Add validation to lambda_schedule_interval variable
dav3r Jul 27, 2022
7329447
Improve language, grammar, and capitalization
dav3r Aug 1, 2022
22b9c99
Ensure Lambda schedule_expression uses correct syntax in all cases
dav3r Aug 1, 2022
c0a6718
Improve validation test for lambda_schedule_interval variable
dav3r Aug 1, 2022
101cc1b
Remove unnecessary escaping of underscores
dav3r Aug 3, 2022
b425b54
Make file_header a list of strings, instead of a string
dav3r Aug 3, 2022
460adb9
Enable dependabot ignore directives
dav3r Sep 19, 2022
8c6eac2
Satisfy markdown linter
dav3r May 6, 2024
a24ece3
Alphabetize resource arguments
dav3r May 6, 2024
0e0f8b9
Update README with latest output from terraform-docs
dav3r May 6, 2024
f22ab6d
Remove lifecycle blocks
dav3r May 6, 2024
7bb9d3a
Modify name of expected Lambda deployment file to match our current s…
dav3r May 10, 2024
20a45bb
Remove a file that was inherited from the skeleton
dav3r May 17, 2024
03c176d
Specify the runtime to use for the lambda-at-edge module
dav3r May 17, 2024
82763f1
Update the mechanism for defining public read-only access to the egre…
dav3r May 17, 2024
23f8e69
Increase lambda timeout from 10 to 15 minutes
dav3r May 17, 2024
4f66701
Improve a variable description
dav3r May 20, 2024
bc3338e
Replace bucket "public-read" ACL with a policy that only allows Cloud…
dav3r May 28, 2024
a22e100
Specify hcl formatting in tfvars example
dav3r May 30, 2024
a748918
Remove now-unneeded ACL-related permissions
dav3r May 30, 2024
a9feac5
Move TF configuration blocks to be after TF arguments in resources
dav3r May 30, 2024
333fed7
Alphabetically order TF arguments in a resource
dav3r May 30, 2024
3d297df
Adjust some newlines for readability
dav3r May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,4 @@ updates:
package-ecosystem: terraform
schedule:
interval: weekly

- directory: /examples/basic_usage
ignore:
# Managed by cisagov/skeleton-tf-module
- dependency-name: hashicorp/aws
package-ecosystem: terraform
schedule:
interval: weekly
version: 2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Files already tracked by Git are not affected.
# See: https://git-scm.com/docs/gitignore

## Project Specific ##
add_security_headers.zip
lambda_build.zip

## Python ##
__pycache__
.mypy_cache
Expand Down
169 changes: 123 additions & 46 deletions README.md

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions add_security_headers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
exports.handler = (event, context, callback) => {
/* Get contents of response */
const response = event.Records[0].cf.response;
const headers = response.headers;

/* Add security headers */
headers["strict-transport-security"] = [
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubdomains; preload",
},
];
headers["content-security-policy"] = [
{
key: "Content-Security-Policy",
value:
"default-src 'none'; img-src 'none'; script-src 'none'; style-src 'none'; object-src 'none'",
},
];
headers["x-content-type-options"] = [
{
key: "X-Content-Type-Options",
value: "nosniff",
},
];
headers["x-frame-options"] = [
{
key: "X-Frame-Options",
value: "DENY",
},
];
headers["x-xss-protection"] = [
{
key: "X-XSS-Protection",
value: "1; mode=block",
},
];
headers["referrer-policy"] = [
{
key: "Referrer-Policy",
value: "same-origin",
},
];

/* Return the modified response */
callback(null, response);
};
10 changes: 10 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
backend "s3" {
encrypt = true
bucket = "cisa-cool-terraform-state"
dynamodb_table = "terraform-state-lock"
profile = "cool-terraform-backend"
region = "us-east-1"
key = "publish-egress-ip-terraform/terraform.tfstate"
}
}
145 changes: 145 additions & 0 deletions cloudfront.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# ------------------------------------------------------------------------------
# The CloudFront distribution and related S3/Lambda resources that allow us to
# use an HTTPS endpoint, which S3 websites do not support natively.
# ------------------------------------------------------------------------------

locals {
# bucket origin id
s3_origin_id = "S3-${aws_s3_bucket.egress_info.id}"
}

data "aws_acm_certificate" "rules_cert" {
# This certificate must exist prior to applying this Terraform.
# For an example, see cisagov/cool-dns-cyber.dhs.gov/acm_rules_vm.tf
provider = aws.deploy

domain = var.domain
most_recent = true
statuses = ["ISSUED"]
types = ["AMAZON_ISSUED"]
}

# An S3 bucket where artifacts for the Lambda@Edge can be stored
resource "aws_s3_bucket" "lambda_at_edge" {
provider = aws.deploy

bucket_prefix = "publish-egress-ip-lambda-at-edge-"
}

resource "aws_s3_bucket_server_side_encryption_configuration" "lambda_at_edge" {
provider = aws.deploy

bucket = aws_s3_bucket.lambda_at_edge.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

resource "aws_s3_bucket_versioning" "lambda_at_edge" {
provider = aws.deploy

bucket = aws_s3_bucket.lambda_at_edge.id
versioning_configuration {
status = "Enabled"
}
}

# This blocks ANY public access to the bucket or the objects it
# contains, even if misconfigured to allow public access.
resource "aws_s3_bucket_public_access_block" "lambda_artifact_bucket" {
provider = aws.deploy

block_public_acls = true
block_public_policy = true
bucket = aws_s3_bucket.lambda_at_edge.id
ignore_public_acls = true
restrict_public_buckets = true
}

# A Lambda@Edge for injecting security headers
module "security_header_lambda" {
providers = {
aws = aws.deploy
}

source = "transcend-io/lambda-at-edge/aws"
version = "0.5.0"

description = "Adds HSTS and other security headers to the response."
lambda_code_source_dir = "${path.root}/add_security_headers"
name = "add_security_headers"
# nodejs18.x appears to be the latest supported runtime until we move beyond
# version 4.9 of the Terraform AWS provider.
runtime = "nodejs18.x"
s3_artifact_bucket = aws_s3_bucket.lambda_at_edge.id
}

resource "aws_cloudfront_distribution" "rules_s3_distribution" {
provider = aws.deploy

aliases = [var.domain]
comment = "Created by cisagov/publish-egress-ip-terraform."
default_root_object = var.root_object
enabled = true
is_ipv6_enabled = true
price_class = "PriceClass_100"

custom_error_response {
error_caching_min_ttl = 30
error_code = 403
response_code = 200
response_page_path = "/${var.root_object}"
}

custom_error_response {
error_caching_min_ttl = 30
error_code = 404
response_code = 200
response_page_path = "/${var.root_object}"
}

default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
compress = true
default_ttl = 30
max_ttl = 30
min_ttl = 0
target_origin_id = local.s3_origin_id
viewer_protocol_policy = "redirect-to-https"

forwarded_values {
query_string = false
cookies {
forward = "none"
}
}

lambda_function_association {
# Inject security headers via Lambda@Edge
event_type = "origin-response"
include_body = false
lambda_arn = module.security_header_lambda.arn
}
}

origin {
domain_name = aws_s3_bucket.egress_info.bucket_regional_domain_name
origin_id = local.s3_origin_id
}

restrictions {
geo_restriction {
locations = ["AS", "GU", "MP", "PR", "US", "VI"]
restriction_type = "whitelist"
}
}

viewer_certificate {
acm_certificate_arn = data.aws_acm_certificate.rules_cert.arn
minimum_protocol_version = "TLSv1.1_2016"
ssl_support_method = "sni-only"
}
}
1 change: 0 additions & 1 deletion examples/basic_usage/.terraform-docs.yml

This file was deleted.

57 changes: 0 additions & 57 deletions examples/basic_usage/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions examples/basic_usage/main.tf

This file was deleted.

24 changes: 0 additions & 24 deletions examples/basic_usage/outputs.tf

This file was deleted.

42 changes: 0 additions & 42 deletions examples/basic_usage/variables.tf

This file was deleted.

Loading
Loading