For examples of real-world incidents in which files have been tampered during the build and release process in CI/CD pipelines, refer to Tampering of source code or artifacts during build
Learn how to detect file modification on the build server in a GitHub Actions workflow.
-
Browse to the ci.yml workflow. Add the
step-security/harden-runnerGitHub Action as the first step. After the checkout step, add another step to simulate modification of a source code file, and another to simulatesudocall. The updated file should look like this:name: Test and coverage on: [push, pull_request, workflow_dispatch] jobs: build: runs-on: ubuntu-latest steps: - uses: step-security/harden-runner@v2 with: egress-policy: audit disable-sudo: true - uses: actions/checkout@v2 with: fetch-depth: 2 - run: | # simulate modification of source code code='package calc\n\nfunc Add(x, y int) int {\nprintln("code added")\nreturn x + y\n}' printf "$code" > calc1.go mv calc1.go calc.go - uses: actions/setup-go@v2 with: go-version: "1.17" - name: Run coverage run: go test -race -coverprofile=coverage.txt -covermode=atomic - name: Simulate sudo access run: sudo ls - name: Upload coverage to Codecov run: | bash <(curl -s https://codecov.io/bash)
Commit the changes to main branch.
-
The
step-security/harden-runnerGitHub Action installs an agent into the Ubuntu VM that monitors changes to source code. In a typical workflow, source code is checked out from the repository and does not need to be altered. In this case, since it is altered, the change will be detected. -
This change should cause the workflow to run, as it is set to run on push. Click on the
Actionstab and then click on theTest and coverageworkflow run. -
You should see a link to security insights and recommendations for the workflow run under the
Run step-security/harden-runnertab.
-
Click on the link. You should see that the file overwrite has been detected.
-
In the Action steps, notice that the
sudostep failed, sincedisable-sudo: truewas set using harden-runner. -
This shows how
Harden-Runnerprevents malicious steps from callingsudoand detects file overwrites during build. -
You can install the StepSecurity Actions Security GitHub App to get notified via email or Slack when a source code file is overwritten in your workflow.
Actions Runner Controller (ARC) is a Kubernetes operator that orchestrates and scales self-hosted runners for GitHub Actions.
-
Rather than incorporating the HardenRunner GitHub Action into each individual workflow, you'll need to install the ARC-Harden-Runner daemonset on your Kubernetes cluster.
-
Upon deployment, the ARC-Harden-Runner daemonset constantly monitors for any modifications to files during your workflows, detecting any unauthorized changes promptly.
-
Install the StepSecurity Actions Security GitHub App
-
With the app installed:
- You can access security insights and runtime detections under the
Runtime Securitytab in your dashboard - You'll receive notifications via email or Slack whenever a file is overwritten in your workflow.
For a demo of a workflow running on ARC with Harden Runner integrated, please refer to following links:
- Workflow file: https://github.com/step-security/github-actions-goat/blob/main/.github/workflows/arc-solarwinds-simulation.yml
- Example workflow run: https://github.com/step-security/github-actions-goat/actions/runs/5662626777/job/15342926660
- Workflow Insights: https://app.stepsecurity.io/github/step-security/github-actions-goat/actions/runs/5662626777
As demonstrated, detections occur automatically, without the need to add the Harden Runner Action to each workflow.
Even though you do not need to add Harden-Runner Action to detect file modifications in ARC, the insights are exactly the same as with GitHub-hosted runner.