# Generated by tools/hardened.py from ../t1. Edit t1 or the script; this file is regenerated. # # Copy to .github/workflows/ in the repository that contains this folder, and set # FOLDER below if it lives somewhere else. Commit terraform.tfvars beside # main.tf, and fill in the backend block in versions.tf so the plan reads the # real state. # # On a pull request that touches the folder: the security scan, a plan, then # the rules in policy/. Any failure stops the change before anyone can apply. # Every day: plan again. Any change means someone edited the live account by # hand; the job fails and opens an issue. name: guard k8s-audit-logging azure on: pull_request: paths: - "outcomes/k8s-audit-logging/azure/t1/**" - "outcomes/k8s-audit-logging/azure/t2/**" schedule: - cron: "17 6 * * *" workflow_dispatch: permissions: contents: read id-token: write issues: write concurrency: group: guard-k8s-audit-logging-azure cancel-in-progress: false jobs: guard: runs-on: ubuntu-latest timeout-minutes: 30 env: FOLDER: outcomes/k8s-audit-logging/azure/t2 TF_IN_AUTOMATION: "true" # Terraform signs in to Azure with the workflow's own OIDC token. ARM_USE_OIDC: "true" ARM_CLIENT_ID: ${{ vars.AZURE_PLAN_CLIENT_ID }} ARM_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} ARM_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1 with: terraform_wrapper: false - uses: open-policy-agent/setup-opa@b2b258e089860efaadaaf71bf6e3aecb4a3eeff1 # v2.4.0 with: version: 1.21.0 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: "3.12" - name: scan run: | pip install checkov==3.3.19 cd "$FOLDER" checkov -d ../t1 --config-file .checkov.yml --quiet --compact - name: plan id: plan run: | cd "$FOLDER" terraform init -input=false set +e terraform plan -input=false -lock=false -detailed-exitcode -out=plan.out code=$? set -e echo "exitcode=$code" >> "$GITHUB_OUTPUT" [ "$code" -ne 1 ] - name: policy run: | cd "$FOLDER" terraform show -json plan.out > plan.json opa eval --fail-defined --format pretty -d policy -i plan.json 'data.iac.deny[msg]' - name: drift if: github.event_name == 'schedule' && steps.plan.outputs.exitcode == '2' env: GH_TOKEN: ${{ github.token }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | gh issue create --repo "$GITHUB_REPOSITORY" \ --title "Drift: $FOLDER no longer matches the live account" \ --body "The scheduled plan found changes made outside Terraform. Plan output: $RUN_URL" exit 1