Skip to content

Commit 7c17074

Browse files
ci(infra): run tfsec + checkov on Terraform plan in CI (#373)
* ci(infra): run tfsec + checkov on Terraform plan in CI Add IaC security scanning gate that runs tfsec and checkov against all Terraform changes on pull requests and pushes to main. - .github/workflows/terraform-scan.yml: CI workflow with two parallel jobs running tfsec and checkov against infrastructure/terraform/ directory - infrastructure/terraform/.tfsec.yml: tfsec config enforcing HIGH minimum severity Closes #166 * fix(ci): resolve tfsec format error and add checkov baseline - tfsec: change format from 'table' to 'text' (table is not a valid format for aquasecurity/tfsec-action) - checkov: add .checkov.baseline to acknowledge 85 pre-existing findings so CI only fails on new regressions - Workflow: add baseline and quiet params to checkov step * docs(infra): add note about regenerating checkov baseline to README * fix(ci): correct checkov baseline path and suppress tfsec false-positive on ALB - Fix checkov baseline path to be relative to workspace root (infrastructure/terraform/.checkov.baseline) instead of scan dir - Add tfsec:ignore for aws-ec2-no-public-ingress-sgr on ALB security group — ALB must accept public HTTP(S) traffic by design * fix(ci): regenerate checkov baseline to cover new terraform files from upstream merge --------- Co-authored-by: irefavor15-dotcom <irefavor15@gmail.com>
1 parent e37574e commit 7c17074

5 files changed

Lines changed: 1058 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Terraform Security Scan
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- 'infrastructure/terraform/**'
8+
push:
9+
branches: [main]
10+
paths:
11+
- 'infrastructure/terraform/**'
12+
workflow_dispatch:
13+
14+
# Cancel any previous in-progress run for the same ref so superseded
15+
# commits on a PR don't waste runner minutes.
16+
concurrency:
17+
group: terraform-scan-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
contents: read
22+
23+
env:
24+
TF_WORKING_DIR: infrastructure/terraform
25+
26+
jobs:
27+
# -------------------------------------------------------------------------
28+
# tfsec – static analysis of Terraform templates for security
29+
# misconfigurations. Reads .tfsec.yml from the working directory to
30+
# determine minimum severity (HIGH / CRITICAL).
31+
# -------------------------------------------------------------------------
32+
tfsec:
33+
name: tfsec
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Run tfsec
41+
uses: aquasecurity/tfsec-action@v1.0.3
42+
with:
43+
working_directory: ${{ env.TF_WORKING_DIR }}
44+
# soft_fail: false causes the step to exit with code 1 (and fail the
45+
# job) when any finding at or above the configured severity exists.
46+
soft_fail: false
47+
# The .tfsec.yml config in the working directory enforces a
48+
# minimum_severity of HIGH, so only HIGH/CRITICAL issues gate CI.
49+
# Valid formats: default, json, sarif, csv, checkstyle, junit, text.
50+
format: text
51+
52+
# -------------------------------------------------------------------------
53+
# checkov – comprehensive policy-as-code scanner covering CIS benchmarks,
54+
# HIPAA, GDPR, and hundreds of built-in Terraform / K8s rules.
55+
# -------------------------------------------------------------------------
56+
checkov:
57+
name: checkov
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
64+
- name: Run checkov
65+
uses: bridgecrewio/checkov-action@v12
66+
with:
67+
directory: ${{ env.TF_WORKING_DIR }}
68+
framework: terraform
69+
# soft_fail: false causes the step to exit with code 1 when
70+
# checkov finds any FAILED evaluation not already in the
71+
# baseline (skipped / passed checks do not affect the exit code).
72+
soft_fail: false
73+
# Baseline file acknowledges pre-existing findings so CI only
74+
# fails on new regressions, not the 85+ known issues.
75+
# .checkov.baseline is auto-generated via `checkov --create-baseline`
76+
# and committed to the repo so CI compares against known issues.
77+
# Path is relative to the workspace root (checkout directory).
78+
baseline: ${{ env.TF_WORKING_DIR }}/.checkov.baseline
79+
# Only display failed checks in the action log for a cleaner
80+
# scan summary.
81+
quiet: true
82+
# Use CLI output for a human-readable scan summary in the action log.
83+
output_format: cli

0 commit comments

Comments
 (0)