From 5f100904aaf867bfbcbee392d8702e17ff3d3d8e Mon Sep 17 00:00:00 2001 From: Chad Cottle Date: Mon, 26 Oct 2026 14:50:16 -0400 Subject: [PATCH 1/2] Add GRC evidence pipeline --- .github/workflows/grc-gate.yml | 101 ++++++++++++++++++++++++ terraform/primitives/oidc-trust/main.tf | 47 +++++++++++ 2 files changed, 148 insertions(+) create mode 100644 .github/workflows/grc-gate.yml create mode 100644 terraform/primitives/oidc-trust/main.tf diff --git a/.github/workflows/grc-gate.yml b/.github/workflows/grc-gate.yml new file mode 100644 index 0000000..e8d8bd7 --- /dev/null +++ b/.github/workflows/grc-gate.yml @@ -0,0 +1,101 @@ +# .github/workflows/grc-gate.yml +name: grc-gate + +on: + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + id-token: write # required for AWS OIDC + Cosign keyless (Lab 4.4) + contents: read + pull-requests: write # required to comment on the PR + +env: + AWS_REGION: us-east-1 + TF_WORKING_DIR: terraform/primitives/compliant-s3 + +jobs: + grc-gate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Configure AWS credentials (OIDC) + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.6.6 + terraform_wrapper: false + + - name: Install Conftest + run: | + curl -fsSL https://github.com/open-policy-agent/conftest/releases/download/v0.50.0/conftest_0.50.0_Linux_x86_64.tar.gz \ + | tar -xz -C /usr/local/bin conftest + + - name: Install tfsec + run: | + curl -fsSL https://github.com/aquasecurity/tfsec/releases/download/v1.28.14/tfsec-linux-amd64 \ + -o /usr/local/bin/tfsec && chmod +x /usr/local/bin/tfsec + + - name: Terraform plan + working-directory: ${{ env.TF_WORKING_DIR }} + run: | + terraform init -input=false + terraform validate + # Same vars as Lab 2.3 / 3.4. -input=false means missing vars fail the job + # instead of hanging on an interactive prompt the runner can't answer. + terraform plan -out=tfplan -input=false -no-color \ + -var="project_name=cgep-lab" -var="environment=dev" | tee plan.txt + terraform show -json tfplan > plan.json + + - name: Conftest policy gate + id: conftest + run: | + mkdir -p evidence/lab-4-3 + EXIT=0 + { + echo "[" + FIRST=1 + # AWS namespaces only (same set as scripts/policy-gate.sh from Lab 3.4). + for ns in compliance.sc28_aws compliance.ac3_aws compliance.cm6_aws ; do + [[ $FIRST -eq 1 ]] && FIRST=0 || printf "," + set +e + OUT=$(conftest test --policy policies --namespace "$ns" --output=json "$TF_WORKING_DIR/plan.json") + STATUS=$? + set -e + [[ $STATUS -eq 0 ]] || EXIT=1 + printf '%s' "$OUT" + done + echo + echo "]" + } > evidence/lab-4-3/conftest-results.json + if [[ $EXIT -eq 0 ]]; then echo "conftest: PASS"; else echo "conftest: FAIL"; exit 1; fi + + - name: tfsec scan + id: tfsec + if: always() + run: | + # Write SARIF for the artifact, then re-run with a severity floor so + # tfsec's own exit code is the gate (no JSON parsing required). + tfsec "$TF_WORKING_DIR" --format sarif --out evidence/lab-4-3/tfsec.sarif || true + tfsec "$TF_WORKING_DIR" --minimum-severity HIGH + + - name: Copy plan into evidence + if: always() + run: | + cp "$TF_WORKING_DIR"/plan.json evidence/lab-4-3/plan.json + cp "$TF_WORKING_DIR"/plan.txt evidence/lab-4-3/plan.txt + + - name: Upload evidence artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: grc-evidence-${{ github.run_id }} + path: evidence/lab-4-3/ + retention-days: 90 diff --git a/terraform/primitives/oidc-trust/main.tf b/terraform/primitives/oidc-trust/main.tf new file mode 100644 index 0000000..b9c9c95 --- /dev/null +++ b/terraform/primitives/oidc-trust/main.tf @@ -0,0 +1,47 @@ +# terraform/primitives/oidc-trust/main.tf +terraform { + required_version = ">= 1.6" + required_providers { + aws = { source = "hashicorp/aws", version = "~> 5.0" } + } +} + +provider "aws" { region = "us-east-1" } + +variable "github_org" { type = string } +variable "github_repo" { type = string } + +resource "aws_iam_openid_connect_provider" "github" { + url = "https://token.actions.githubusercontent.com" + client_id_list = ["sts.amazonaws.com"] + thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"] +} + +resource "aws_iam_role" "grc_gate" { + name = "cgep-grc-gate" + + assume_role_policy = jsonencode({ + Version = "2012-10-17" + Statement = [{ + Effect = "Allow" + Principal = { Federated = aws_iam_openid_connect_provider.github.arn } + Action = "sts:AssumeRoleWithWebIdentity" + Condition = { + StringEquals = { "token.actions.githubusercontent.com:aud" = "sts.amazonaws.com" } + StringLike = { + "token.actions.githubusercontent.com:sub" = [ + "repo:${var.github_org}/${var.github_repo}:*", # repos created before Jul 15 2026 + "repo:${var.github_org}@*/${var.github_repo}@*:*", # repos created after: GitHub adds owner + repo IDs + ] + } + } + }] + }) +} + +resource "aws_iam_role_policy_attachment" "readonly" { + role = aws_iam_role.grc_gate.name + policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess" +} + +output "role_arn" { value = aws_iam_role.grc_gate.arn } From e29515ef84b777b7d3d4498d75f225c5c7943b6a Mon Sep 17 00:00:00 2001 From: Chad Cottle Date: Mon, 26 Oct 2026 15:20:21 -0400 Subject: [PATCH 2/2] Add GRC evidence pipeline --- .github/workflows/grc-gate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/grc-gate.yml b/.github/workflows/grc-gate.yml index e8d8bd7..d43b899 100644 --- a/.github/workflows/grc-gate.yml +++ b/.github/workflows/grc-gate.yml @@ -83,7 +83,9 @@ jobs: run: | # Write SARIF for the artifact, then re-run with a severity floor so # tfsec's own exit code is the gate (no JSON parsing required). + echo "****** BREAK 1 ******" tfsec "$TF_WORKING_DIR" --format sarif --out evidence/lab-4-3/tfsec.sarif || true + echo "****** BREAK 2 ******" tfsec "$TF_WORKING_DIR" --minimum-severity HIGH - name: Copy plan into evidence