Harden-Runner 开源项目使用教程
1. 项目介绍
Harden-Runner 是一个用于 GitHub-hosted 和 self-hosted runners 的网络出口过滤和运行时安全工具。它通过强化运行器来增强 GitHub Actions 工作流的运行时安全性。Harden-Runner 的主要功能包括监控和过滤出站网络流量、检测源代码篡改、监控文件和进程活动等。
2. 项目快速启动
2.1 安装步骤
首先,将 Harden-Runner GitHub Action 添加到你的 GitHub Actions 工作流文件中。以下是一个示例配置:
name: Example Workflow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: step-security/harden-runner@v2.10.0
with:
egress-policy: audit
- run: echo "Hello, World!"
2.2 配置说明
uses: step-security/harden-runner@v2.10.0
: 使用 Harden-Runner 的最新版本。egress-policy: audit
: 设置为审计模式,记录所有出站网络流量。
2.3 查看日志
在 GitHub Actions 的日志中,你可以看到 Harden-Runner 生成的安全洞察和建议链接。点击链接可以查看详细的网络和文件事件监控报告。
3. 应用案例和最佳实践
3.1 案例研究
- Google 开源项目 Flank: Harden-Runner 成功检测到 Google 开源项目 Flank 中的供应链攻击。
- Kapiche: Kapiche 使用 Harden-Runner 强化其 GitHub Actions 软件供应链安全。
- Arcjet: Arcjet 通过 Harden-Runner 增强了其 CI/CD 安全性。
3.2 最佳实践
- 监控网络流量: 使用 Harden-Runner 监控和过滤出站网络流量,防止代码和 CI/CD 凭证的泄露。
- 检测源代码篡改: 通过 Harden-Runner 检测源代码是否在构建过程中被篡改,防止后门注入。
- 最小权限原则: 使用 Harden-Runner 确定并设置最小的 GITHUB_TOKEN 权限,减少泄露风险。
4. 典型生态项目
4.1 GitHub Actions Runner Controller (ARC)
ARC 是一个 Kubernetes 操作符,用于编排 GitHub Actions 的自托管运行器。Harden-Runner 可以与 ARC 结合使用,通过安装 ARC Harden-Runner daemonset 来监控所有在 Kubernetes 集群上运行的作业。
4.2 自托管 VM 运行器
对于在 EC2 等虚拟机上运行的自托管运行器,可以通过安装 Harden-Runner 代理来监控所有在 VM 上运行的作业。Harden-Runner 支持临时和持久运行器。
通过以上步骤,你可以快速上手并安全地使用 Harden-Runner 来强化你的 GitHub Actions 工作流。