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

Add support for a log bucket #104

Merged
merged 9 commits into from
Nov 6, 2021
Merged

Add support for a log bucket #104

merged 9 commits into from
Nov 6, 2021

Conversation

johncblandii
Copy link
Contributor

what

  • Add support for access logs bucket

why

  • Consumers will not be required to create their own buckets anymore

references

N/A

Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

Bridgecrew has found infrastructure configuration errors in this PR ⬇️

@@ -176,8 +197,8 @@ resource "aws_s3_bucket" "default" {
dynamic "logging" {
for_each = var.logging == null ? [] : [1]
content {
target_bucket = var.logging["bucket_name"]
target_prefix = var.logging["prefix"]
target_bucket = local.logging_bucket_name
Copy link

@bridgecrew bridgecrew bot Nov 1, 2021

Choose a reason for hiding this comment

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

LOW   S3 buckets are not encrypted with KMS
    Resource: aws_s3_bucket.default | ID: BC_AWS_GENERAL_56

How to Fix

resource "aws_s3_bucket" "mybucket" {
  ...
  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        kms_master_key_id = aws_kms_key.mykey.arn
 +      sse_algorithm     = "aws:kms"
      }
    }
  }
}

Description

TBA

Dependent Resources



Path Resource Connecting Attribute
/main.tf aws_s3_bucket_public_access_block.default bucket

Copy link
Member

Choose a reason for hiding this comment

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

Not sure why this is being spammed every few hours... we should add kms encryption here as an option or default but maybe in a separate PR

Created this ticket for future ref: #105

main.tf Outdated
@@ -228,7 +249,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
}

resource "aws_dynamodb_table" "without_server_side_encryption" {
count = local.dynamodb_enabled && ! var.enable_server_side_encryption ? 1 : 0
count = local.dynamodb_enabled && !var.enable_server_side_encryption ? 1 : 0
Copy link

@bridgecrew bridgecrew bot Nov 1, 2021

Choose a reason for hiding this comment

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

LOW   Unencrypted DynamoDB Tables
    Resource: aws_dynamodb_table.without_server_side_encryption | ID: BC_AWS_GENERAL_52

How to Fix

resource "aws_dynamodb_table" "basic-dynamodb-table" {
  ...
  server_side_encryption {
+    enabled = true
+    kms_key_arn= aws_kms_key.dynamo.arn
  }
}

Description

Checks if the Amazon DynamoDB tables are encrypted, and in line with AWS best security practice - with a specified non-default KMS key.

main.tf Outdated
@@ -228,7 +249,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
}

resource "aws_dynamodb_table" "without_server_side_encryption" {
count = local.dynamodb_enabled && ! var.enable_server_side_encryption ? 1 : 0
count = local.dynamodb_enabled && !var.enable_server_side_encryption ? 1 : 0
Copy link

@bridgecrew bridgecrew bot Nov 1, 2021

Choose a reason for hiding this comment

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

LOW   DynamoDB Tables do not have Auto Scaling enabled
    Resource: aws_dynamodb_table.without_server_side_encryption | ID: BC_AWS_GENERAL_44

How to Fix

resource "aws_dynamodb_table" "pass" {
  name           = "user"
  hash_key       = "user-id"
  billing_mode   = "PROVISIONED"
  read_capacity  = 10
  write_capacity = 10
  attribute {
    name = "user-id"
    type = "S"
  }
}

resource "aws_appautoscaling_target" "pass" {
  resource_id        = "table/${aws_dynamodb_table.pass.name}"
  scalable_dimension = "dynamodb:table:ReadCapacityUnits"
  service_namespace  = "dynamodb"
  min_capacity       = 1
  max_capacity       = 15
}

resource "aws_appautoscaling_policy" "pass" {
  name               = "rcu-auto-scaling"
  service_namespace  = aws_appautoscaling_target.pass.service_namespace
  scalable_dimension = aws_appautoscaling_target.pass.scalable_dimension
  resource_id        = aws_appautoscaling_target.pass.resource_id
  policy_type        = "TargetTrackingScaling"

  target_tracking_scaling_policy_configuration {
    predefined_metric_specification {
      predefined_metric_type = "RDSReaderAverageCPUUtilization"
      predefined_metric_type = "DynamoDBReadCapacityUtilization"
    }

// or:
    
resource "aws_dynamodb_table" "pass_on_demand" {
  name           = "user"
  hash_key       = "user-id"
  billing_mode   = "PAY_PER_REQUEST"

  attribute {
    name = "user-id"
    type = "S"
  }
}

Description

Checks if DynamoDB tables have autoscaling configuration. Note that for tables with billing_mode = "PAY_PER_REQUEST" such configuration is embedded by default.

main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to 86797e4 - Auto Format - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

main.tf Outdated
acl = "log-delivery-write"
attributes = ["logs"]
access_log_bucket_prefix = try(var.logging["prefix"], "logs/")
standard_transition_days = 30
Copy link
Member

@nitrocode nitrocode Nov 1, 2021

Choose a reason for hiding this comment

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

please expose these as input variables as they meet need to be configured based on design decisions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposed those 3, but further customization would be done outside of this module so we don't copy all vars into it.

See bb20c72.

main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to bb20c72 - chore: add support for log bucket var config - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to 2f34979 - Auto Format - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

@johncblandii
Copy link
Contributor Author

/test all

main.tf Show resolved Hide resolved
main.tf Outdated
@@ -228,7 +252,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
}

resource "aws_dynamodb_table" "without_server_side_encryption" {
count = local.dynamodb_enabled && ! var.enable_server_side_encryption ? 1 : 0
count = local.dynamodb_enabled && !var.enable_server_side_encryption ? 1 : 0
Copy link

@bridgecrew bridgecrew bot Nov 4, 2021

Choose a reason for hiding this comment

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

LOW   Ensure DynamoDB Tables have Auto Scaling enabled
    Resource: aws_dynamodb_table.without_server_side_encryption | ID: BC_AWS_GENERAL_44

How to Fix

resource "aws_dynamodb_table" "pass" {
  name           = "user"
  hash_key       = "user-id"
  billing_mode   = "PROVISIONED"
  read_capacity  = 10
  write_capacity = 10
  attribute {
    name = "user-id"
    type = "S"
  }
}

resource "aws_appautoscaling_target" "pass" {
  resource_id        = "table/${aws_dynamodb_table.pass.name}"
  scalable_dimension = "dynamodb:table:ReadCapacityUnits"
  service_namespace  = "dynamodb"
  min_capacity       = 1
  max_capacity       = 15
}

resource "aws_appautoscaling_policy" "pass" {
  name               = "rcu-auto-scaling"
  service_namespace  = aws_appautoscaling_target.pass.service_namespace
  scalable_dimension = aws_appautoscaling_target.pass.scalable_dimension
  resource_id        = aws_appautoscaling_target.pass.resource_id
  policy_type        = "TargetTrackingScaling"

  target_tracking_scaling_policy_configuration {
    predefined_metric_specification {
      predefined_metric_type = "RDSReaderAverageCPUUtilization"
      predefined_metric_type = "DynamoDBReadCapacityUtilization"
    }

// or:
    
resource "aws_dynamodb_table" "pass_on_demand" {
  name           = "user"
  hash_key       = "user-id"
  billing_mode   = "PAY_PER_REQUEST"

  attribute {
    name = "user-id"
    type = "S"
  }
}

Description

Checks if DynamoDB tables have autoscaling configuration. Note that for tables with billing_mode = "PAY_PER_REQUEST" such configuration is embedded by default.

main.tf Outdated
@@ -228,7 +252,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
}

resource "aws_dynamodb_table" "without_server_side_encryption" {
count = local.dynamodb_enabled && ! var.enable_server_side_encryption ? 1 : 0
count = local.dynamodb_enabled && !var.enable_server_side_encryption ? 1 : 0
Copy link

@bridgecrew bridgecrew bot Nov 4, 2021

Choose a reason for hiding this comment

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

LOW   Ensure DynamoDB tables are encrypted
    Resource: aws_dynamodb_table.without_server_side_encryption | ID: BC_AWS_GENERAL_52

How to Fix

resource "aws_dynamodb_table" "basic-dynamodb-table" {
  ...
  server_side_encryption {
+    enabled = true
+    kms_key_arn= aws_kms_key.dynamo.arn
  }
}

Description

Checks if the Amazon DynamoDB tables are encrypted, and in line with AWS best security practice - with a specified non-default KMS key.

Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to 894cfe2 - chore: tighten up the bucket name integration - 3 new errors were added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default
BC_AWS_GENERAL_44 Added /main.tf aws_dynamodb_table.without_server_side_encryption
BC_AWS_GENERAL_52 Added /main.tf aws_dynamodb_table.without_server_side_encryption

main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to c77c6d0 - Auto Format - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

@johncblandii
Copy link
Contributor Author

/test all

@johncblandii
Copy link
Contributor Author

/test all

main.tf Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to 9e6f25d - chore: fix incorrect local - 3 new errors were added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default
BC_AWS_GENERAL_44 Added /main.tf aws_dynamodb_table.without_server_side_encryption
BC_AWS_GENERAL_52 Added /main.tf aws_dynamodb_table.without_server_side_encryption

main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to 7372db1 - Auto Format - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

max-lobur
max-lobur previously approved these changes Nov 4, 2021
main.tf Outdated Show resolved Hide resolved
main.tf Show resolved Hide resolved
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

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

⚠️   Due to e8aaec4 - chore: consolidate locals - 1 new error was added

Change details

Error ID Change Path Resource
BC_AWS_GENERAL_56 Added /main.tf aws_s3_bucket.default

@johncblandii
Copy link
Contributor Author

/test all

@johncblandii johncblandii merged commit 9fa8fdc into master Nov 6, 2021
@johncblandii johncblandii deleted the feature/access-logs branch November 6, 2021 04:34
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.

4 participants