StepSecurity Harden Runner:检测构建过程中的源代码篡改

介绍 StepSecurity 的 Harden Runner:GitHub Actions 构建过程中检测源代码篡改的解决方案

2020 年 12 月,行业被 SolarWinds, Inc. 遭受供应链攻击的披露所震惊。这种攻击方法专注于在构建过程中植入未经授权的恶意代码,而非在源代码管理系统中修改源代码或在制品库中修改制品 [1]。

这种篡改很难检测。设置分支保护和代码审查等对策在这种攻击中毫无帮助,因为代码并未在源代码管理系统中被篡改(下图框 1)。代码签名也无法解决问题,因为被签名的制品在构建过程中已经被篡改了。例如,在 SolarWinds 供应链攻击中,软件虽然经过了签名,但在签名之前——即构建过程中——已经被篡改(下图框 2)[2]。

SolarWinds 供应链攻击中源代码被篡改位置的简化视图

StepSecurity(https://stepsecurity.io)是一家软件供应链安全公司,已经开发出一种解决方案来检测构建过程中对源代码的此类篡改。目前,该解决方案适用于在使用 GitHub 托管运行器通过 GitHub Actions 构建代码的场景。

GitHub Actions 是一个流行的 CI/CD 平台,允许您自动化构建、测试和部署流程。GitHub 托管运行器是执行 GitHub Actions 工作流中作业的虚拟机(VM),由 GitHub 托管 [3]。

StepSecurity 的 Harden Runner(https://github.com/step-security/harden-runner)是 GitHub 托管运行器(Ubuntu VM)上的一个代理,用于监控构建过程。它使用 Linux 审计框架来审计构建过程中的文件修改。Linux 审计通过提供分析系统活动的能力来帮助增强系统安全性 [4]。

StepSecurity 的解决方案之所以被称为 Harden Runner,是因为它强化了执行构建作业的运行器(即虚拟机)。将 Harden Runner 添加到 GitHub Actions 工作流中非常简单,只需将其作为工作流的第一步即可。

图片展示了如何将 Harden Runner 添加到 GitHub Actions 工作流中

Harden Runner(https://github.com/step-security/harden-runner)可以在构建过程中检测源代码的修改,并将其作为错误注释显示在工作流中(见下方截图)。它还显示了修改文件的系统调用和可执行文件。未来,我们计划在构建服务器上生成的制品上也启用此类检测。我们还计划为此类检测发送通知。

图片展示了 Harden Runner 在构建过程中检测源代码修改

Harden Runner 已被用于超过 500 个代码仓库的 GitHub Actions 工作流,其中超过 300 个是公开仓库。它被用于 Node Version Manager 和 Caffeine 等流行的开源项目,以及 Google、Microsoft 和 Automattic 的开源项目。

Harden Runner 可在 GitHub Actions 市场中获取。如果您想亲自实践本场景的教程,可以使用 Supply Chain Goat 公开仓库的分叉版本按照步骤进行操作。

如需了解新功能发布的最新动态,请在 LinkedIn 和 Twitter 上关注 Step Security。

参考文献:​

[1] SUNSPOT: An Implant in the Build Process — https://www.crowdstrike.com/blog/sunspot-malware-technical-analysis/

[2] Preventing Supply Chain Attacks like SolarWinds https://www.linuxfoundation.org/blog/preventing-supply-chain-attacks-like-solarwinds/

[3] About GitHub-hosted runners — https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners

[4] Linux Audit framework — https://wiki.archlinux.org/title/Audit_framework

StepSecurity Harden Runner GitHub Action — https://github.com/marketplace/actions/harden-runner

Supply Chain Goat — https://github.com/step-security/supply-chain-goat/blob/main/MonitorSourceCode.md