-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Security Headers not returning: Cloudfront Trigger is not being added to Lambda Function #2
Comments
@marcellodesales So this is interesting that your seeing this as well. Initially when writing the first version of this module, I noticed the same thing. That the Lambda was missing the Cloudfront trigger in the Lambda UI. However, as long as the lambda function is configured as an association on the Cloudfront Distribution, the headers are there: I did attempt adding the trigger last night, but this only resulted in 503's being thrown to Cloudfront. |
@skyfox675 Any workaround for that then? I want to incorporate this module and this was my last resort :( |
This is the way I configure Cloudfront triggered lambdas you shouldn't need to make any changes in the lambda console: module "cloudfront_security_headers" {
source = "Lupus-Metallum/cloudfront-security-headers/aws"
version = "2.0.0"
name = "AddSecurityHeaders"
access_control_allow_methods = "POST, GET, OPTIONS"
access_control_allow_origin = "https://example.com"
referrer_policy = "same-origin"
strict_transport_security = "max-age=63072000; includeSubdomains; preload"
x_content_type_options = "nosniff"
x_frame_options = "DENY"
x_xss_protection = "1; mode=block"
feature_policy = ""
}
resource "aws_cloudfront_distribution" "s3_site" {
enabled = true
is_ipv6_enabled = true
comment = "example"
default_root_object = "index.html"
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
viewer_protocol_policy = "redirect-to-https"
cache_policy_id = "658327ea-f89d-4fab-a63d-7e88639e58f6"
min_ttl = 0
default_ttl = 0
max_ttl = 0
compress = true
lambda_function_association {
event_type = "viewer-response"
include_body = false
lambda_arn = module.cloudfront_security_headers.lambda_arn
}
}
... additional cloudfront options
} |
@skyfox675 Is there a way to specify custom headers too? |
Not at this time, curious were the headers you're looking to add more security like headers such as CORS, XSS... or custom for your specific implementation? Happy to add more options on the security front. As for specific headers for your implementation, you can copy the code in src/index.js.tpl and modify for your needs and deploy a published Lambda with a Cloudfront viewer response to add your custom headers as well. |
@skyfox675 In order to validate a deployment, I inject HTTP response headers for Metrics and from the Build system. That way, my automated validators can just do an HTTP HEAD request to the object and retrieve these other HTTP Response headers to be validated... Requirement & DesignI was thinking in something like the following:
variable "luppus_metallum_additional_headers" {
description = "Additional headers to be injected by the lambda cloudfront"
type = map
default = [
{
key = "X-App-Build-Version"
value = "1.2.0-adf349e"
},
{
key = "X-App-env"
attribute = "stg"
},
{
id = "X-App-segment"
attribute = "ppd"
},
{
id = "X-App-type"
attribute = "blc"
}
] |
I hesitate to copy code from libraries as they tend to evolve and impose changes on my seide as well... I just wanted something more concise.... |
🐛 Describe the bug
🩺 To Reproduce
Expected behavior
🎨 Screenshots
CloudFront
Desktop (please complete the following information):
💻 Possible Solution
🔉 Full Logs
The text was updated successfully, but these errors were encountered: