datosh/pinned-actions
GitHub: datosh/pinned-actions
该项目批量扫描 GitHub 高星仓库,统计通过哈希值固定(pin-by-hash)GitHub Actions 的比例,以评估 CI/CD 供应链安全实践现状。
Stars: 9 | Forks: 1
# 固定的 Actions
在为一次演讲研究 GitHub Actions 时,我问自己:“有多少仓库通过哈希值固定(pin-by-hash)来使用 GitHub Actions?”。由于找不到能回答这个问题的工具,我决定自己动手构建一个。
结果已发布在:[http://pin-gh-actions.kammel.dev/](http://pin-gh-actions.kammel.dev/)
## 使用方法
```
$ go run . --help
Usage of GH Pinned Actions:
-download-dir string
path to folder where repositories will be downloaded (default "/tmp/pinned")
-max-pages int
maximum number of pages to download (default 1)
-per-page int
number of repositories to download per page (default 100)
```
## 示例
要复现 10,000 个仓库的结果,请运行:
```
go run . -max-pages 100
```
## 架构
关于所选库和 API 的一些说明。
### GitHub 搜索 API
我们使用公开的 GitHub [仓库搜索 API](https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-repositories) 来请求[按 Star 数量排名的最受欢迎仓库](https://github.com/search?q=stars%3A10000..500000&type=repositories&ref=advsearch&s=stars&o=desc)。尽管搜索 API 支持分页,但它有每页最多 100 条结果的限制,此外还有[每次搜索最多 1,000 条结果](https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#about-search)的限制。
为了绕过这一限制,我们在每次请求后修改搜索查询,并且只使用返回的第一页结果。
### git
仓库克隆是通过 `os/exec` 调用原生 `git` 二进制文件来完成的,使用了部分克隆(partial clone)结合稀疏检出(sparse checkout):
```
git clone --depth 1 --filter=blob:none --sparse
git -C sparse-checkout set .github
```
`--filter=blob:none` 指示服务器不要预先发送任何文件 blob;
随后 `sparse-checkout set .github` 仅获取 `.github/` 下的 blob。
Git 的 cone 模式总是会包含根目录级别的文件(例如 `README.md`、`go.mod`),但这些文件大小可以忽略不计。真正大幅节省空间的地方在于跳过了与扫描无关的源代码子目录(`src/`、`lib/`、`packages/` 等)。实际上,对于 10,000 个仓库,这将磁盘占用从约 1.5 TB 减少到远低于 1 GB。
### 解析 Actions
[stacklok/frizbee](https://github.com/stacklok/frizbee/tree/main/pkg/ghactions) 已经提供了所有解析 GitHub Actions 所需的工具。我们使用这个库来解析这些仓库中的 actions。
标签:CI/CD安全, DevSecOps, GitHub Actions, GitHub API, Git克隆, Go语言, Llama, Pin-by-hash, 上游代理, 云安全监控, 代码分析, 凭证管理, 后端开发, 哈希固定, 安全合规, 日志审计, 稀疏检出, 程序破解, 网络代理, 自动笔记, 静态分析