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

fix(AWLS2-441): ensure S3 bucket exists before VPC flow log creation #150

Merged
merged 8 commits into from
Dec 13, 2024

Conversation

kirklandnuts
Copy link
Contributor

@kirklandnuts kirklandnuts commented Dec 12, 2024

Summary

Updates log_destination parameter in the vpc_flow_logs resource to directly reference our S3 bucket resource, ensuring Terraform creates resources in the correct order.

This fixes an intermittent "Access Denied" error that occurs when terraform tries to create the flow logs resource before the S3 bucket is fully provisioned.

Please refer to the linked Jira ticket for more details.

How did you test this change?

[WIP] Retried deployment a few times and stopped seeing intermittent failure due to permission error when creating the flow logs resource.

Issue

AWLS2-441

@kirklandnuts kirklandnuts requested review from a team as code owners December 12, 2024 20:09
@kirklandnuts kirklandnuts requested review from marktabry, aneesh-mysore, aclacework and leijin-lw and removed request for a team December 12, 2024 20:09
main.tf Outdated
@@ -911,7 +911,7 @@ resource "aws_flow_log" "agentless_scan_vpc_flow_log" {

# Send logs to manged S3 bucket.
log_destination_type = "s3"
log_destination = "arn:aws:s3:::${local.prefix}-bucket-${local.suffix}/sidekick/flow-logs/"
log_destination = aws_s3_bucket.agentless_scan_bucket[0].arn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably still want to publish this to the sidekick/flow-logs path within the bucket for organization purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch dude — addressed in a7af82d

kirklandnuts and others added 7 commits December 12, 2024 20:19
Adds depends_on to ensure S3 bucket is fully provisioned before flow log
creation, addressing an intermittent "Access Denied" error. The direct
resource reference alone wasn't sufficient to guarantee proper ordering.
- Add s3_bucket_arn to global module outputs
- Add s3_bucket_arn field to global_module_reference variable type
- Use global_module_reference.s3_bucket_arn for flow log destination
…k/terraform-aws-agentless-scanning into fix/AWLS2-441/flow-logs-creation

Signed-off-by: Lei Jin <[email protected]>
Signed-off-by: Lei Jin <[email protected]>
@leijin-lw leijin-lw force-pushed the fix/AWLS2-441/flow-logs-creation branch from 581c807 to 614397f Compare December 12, 2024 23:40
Copy link

(Audit Mode) Lacework IAC found 40 new violations
Violation Severity File Guidelines
Ensure that S3 bucket has a Public Access block High main.tf VIEW
Ensure that S3 bucket has a Public Access block High main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure the default security group of every VPC restricts all traffic Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure VPC flow logging is enabled in all VPCs Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure container insights are enabled on ECS cluster Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure the S3 bucket has access logging enabled Low main.tf VIEW
Ensure IAM policies does not allow write access without constraints Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW
Ensure IAM policies does not allow write access without constraints Medium main.tf VIEW
Ensure that S3 bucket has cross-region replication enabled Medium main.tf VIEW

main.tf Outdated
@@ -911,7 +911,8 @@ resource "aws_flow_log" "agentless_scan_vpc_flow_log" {

# Send logs to manged S3 bucket.
log_destination_type = "s3"
log_destination = "arn:aws:s3:::${local.prefix}-bucket-${local.suffix}/sidekick/flow-logs/"
log_destination = "${aws_s3_bucket.agentless_scan_bucket[0].arn}/sidekick/flow-logs/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work since VPC flow log is a regional resources and aws_s3_bucket.agentless_scan_bucket[0].arn only exists when global = true

@kirklandnuts kirklandnuts merged commit 844913e into main Dec 13, 2024
9 checks passed
@kirklandnuts kirklandnuts deleted the fix/AWLS2-441/flow-logs-creation branch December 13, 2024 01:15
@lacework-releng lacework-releng mentioned this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants