Skip to content

Commit

Permalink
Merge pull request #16 from rtkmhart/add.security.scanning
Browse files Browse the repository at this point in the history
Add checkov scanning, force IMDSv2, update resources to pass scans
  • Loading branch information
RaJiska authored Feb 25, 2024
2 parents 977e822 + aade7b6 commit 79983a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ jobs:

- name: Terraform Validate
id: validate
run: terraform validate -no-color
run: terraform validate -no-color

- name: Set up Python 3.8 for Checkov
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Test with Checkov
id: checkov
uses: bridgecrewio/checkov-action@master
with:
framework: terraform
skip_path: ./examples
8 changes: 8 additions & 0 deletions ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data "aws_arn" "ssm_param" {
}

resource "aws_launch_template" "main" {
#checkov:skip=CKV_AWS_88:NAT instances must have a public IP.
name = var.name
image_id = local.ami_id
instance_type = var.instance_type
Expand Down Expand Up @@ -85,10 +86,17 @@ resource "aws_launch_template" "main" {
TERRAFORM_CWAGENT_CFG_PARAM_NAME = local.cwagent_param_name != null ? local.cwagent_param_name : ""
}))

# Enforce IMDSv2
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
}

tags = var.tags
}

resource "aws_instance" "main" {
#checkov:skip=CKV2_AWS_41:False positive, IAM role is attached via the launch template.
count = var.ha_mode ? 0 : 1

launch_template {
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ resource "aws_ssm_parameter" "cloudwatch_agent_config" {

name = "${var.name}-cloudwatch-agent-config"
key_id = var.kms_key_id
type = "String"
type = "SecureString"
value = templatefile("${path.module}/templates/cwagent.json", {
METRICS_COLLECTION_INTERVAL = var.cloudwatch_agent_configuration.collection_interval,
METRICS_NAMESPACE = var.cloudwatch_agent_configuration.namespace
Expand Down

0 comments on commit 79983a3

Please sign in to comment.