aquasecurity/setup-trivy
GitHub: aquasecurity/setup-trivy
一个 GitHub Action,用于在 GitHub Actions 工作流中安装指定版本的 Trivy 安全扫描器并支持二进制缓存。
Stars: 14 | Forks: 23
# 设置 trivy
为你的 GitHub Actions 工作流设置特定版本的 [Trivy](https://github.com/aquasecurity/trivy)
# 用法
## 安装最新版本的 Trivy
```
# ...
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
```
## 安装特定版本的 Trivy
```
# ...
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
with:
version: v0.68.2
```
## 缓存
`setup-trivy` 在底层使用了 `actions/cache`,但所需的配置项更少。
这会缓存 trivy 二进制文件,这样下次运行时,它会直接从缓存中加载,而不是重新下载。这与 Trivy 的其他产物(例如 `trivy-db` 和 `trivy-java-db`)的缓存*不同*。
cache 输入是可选的,并且默认情况下缓存是关闭的。
**对于空版本和 `latest` 版本,不支持缓存!**
### 启用缓存
如果你想为 Linux 和 MacOS runner 启用缓存,请将 `cache` 输入设置为 `true` 并指定 `version`。
```
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
with:
version: v0.68.2
cache: true
```
### Trivy 二进制文件的自定义路径
要为 Windows runner 启用缓存,或者如果你出于其他原因需要更改 Trivy 的安装目录,请使用 `path` 输入。
**`setup-trivy` 会添加 `trivy-bin` 目录,以避免缓存不必要的文件**
```
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
with:
version: v0.68.2
cache: true
path: "./bins"
```
## 使用非默认 token 安装 Trivy
在某些情况下,`github.token`(`actions/checkout` 的默认值)对于 `http://github.com` 来说包含一个无效的 token。
使用 GitHub Enterprise Server (GHES) 时就是一个典型的例子。
更多信息请参见 https://github.com/aquasecurity/setup-trivy/issues/10
为了正确安装 Trivy,你需要从一个 secret 或另一个步骤(例如来自 https://github.com/actions/create-github-app-token)填充 `token`
```
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
with:
version: v0.68.2
cache: true
token: ${{ secrets.GITHUB_PAT }}
```
## 使用非默认 github-server-url 安装 Trivy
在某些情况下,GHES 部署是隔离的,并且不使用 GitHub Connect。
它使用 actions-sync 流程将允许的 action 镜像同步到 GHES 实例中。
设置 `github-server-url` 以更改 Trivy 仓库的镜像。
```
steps:
- name: Install Trivy
uses: aquasecurity/setup-trivy@e07451d2e059ed86c2870430ea286b3a9e0bf241
with:
version: v0.68.2
github-server-url: 'https://example.com'
```
标签:GitHub Actions, 安全工具配置, 网络调试, 自动化, 自动笔记