ec 用于验证工件和评估策略的命令行客户端
ec 工具用于评估软件供应链的 Conforma 策略。可以使用各种子命令来断言有关工件的事实,例如:
- 验证容器镜像签名
- 验证容器镜像来源
- 针对容器镜像来源评估 policies
- 获取工件授权
请参阅 documentation 了解可用的子命令、描述和使用示例。
安装
从 latest release 安装预构建的二进制文件, 或从源代码构建:
make build # builds dist/ec for your platform
请参阅文档以获取使用示例。
构建
从根目录运行 make build 并使用 dist/ec 可执行文件,或者
运行 make dist 以构建所有支持的架构。
测试
运行 make test 以运行单元测试,运行 E2E_INSTRUMENTATION=true make acceptance 以运行
验收测试。
E2E_INSTRUMENTATION=true 环境变量的目的是向构建命令传递
额外的标志。这会对生成的二进制文件进行插桩,
从而允许在验收测试运行期间收集覆盖率数据。
(更多信息请参见:https://go.dev/doc/build-cover)。
代码检查
运行 make lint 以检查代码检查问题,运行 make lint-fix 以修复代码检查
问题(格式化、导入顺序等)。
演示
运行 hack/demo.sh 以针对预先构建的镜像评估策略。
若要重新生成这些镜像,例如在证明数据发生更改的情况下,请运行
hack/rebuild.sh。
故障排除
--debug 参数启用调试日志记录。设置 EC_DEBUG 环境变量
可以防止删除临时 ec-work-* 目录,以便
可以检查证明、策略和数据文件。
1. Go 模块校验和不匹配错误
在下载依赖项时,您可能会遇到如下校验和不匹配错误:
go: downloading github.com/googleapis/enterprise-certificate-proxy v0.3.3
verifying github.com/googleapis/enterprise-certificate-proxy@v0.3.3: checksum mismatch
downloaded: h1:G6q7VHBoU74wQHXFsZSLMPl0rFw0ZDrlZ3rt6/aTBII=
go.sum: h1:QRje2j5GZimBzlbhGA2V2QlGNgL8G6e+wGo/+/2bWI0=
可以通过运行以下命令来设置 Go 代理,从而帮助解决校验和不匹配问题:
$ go env -w GOPROXY='https://proxy.golang.org,direct'
2. 验收测试中 Docker 容器启动失败
2.1 各种问题 - podman 作为系统服务运行
Podman 服务和套接字作为系统服务而非用户服务(即 rootful 而非 rootless)运行,可能会导致各种问题。 在尝试任何其他解决方案之前,请确保 Podman 系统服务和套接字已停止并禁用。 在 Red Hat 或 Fedora 系统上,您可以通过执行以下命令来完成此操作(注意:其他系统可能需要修改):
$ systemctl status podman.socket podman.service
$ systemctl disable --now podman.socket podman.service
建议之后执行一次重启。
要为用户启动 Podman:
$ systemctl enable --user --now podman.socket podman.service
2.2. Get localhost:37837: connection reset by peer
在运行验收测试时,您可能会遇到无法启动足够数量的 Docker 容器以成功完成测试的问题。这些问题可能表现为重复的失败,如下所示,以及一次失败的验收测试运行。
time="2024-03-08T09:10:50-05:00" level=warning msg="Failed, retrying in 1s ... (3/3). Error: trying to reuse blob sha256:b5976a979c30628edfeee0a1f1797362b0c84cf6cb4760776aa64ec8e3e4c2b3 at destination: pinging container registry localhost:37837: Get \"http://localhost:37837/v2/\": read tcp 127.0.0.1:34090->127.0.0.1:37837: read: connection reset by peer"
此问题可能通过增加 fs.inotify.max_user_watches 的总数来解决,方法是在以下系统上执行以下操作:Red Hat / Fedora 系统(其他系统可能需要对此进行修改)
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
2.3. 创建密钥环:磁盘配额已超出
FAIL: TestFeatures/valid_policy_URL (1.23s)
suite.go:634: start container: container start: Error response from daemon: crun: create keyring `ab949bcc7a6f13272c70c2252e2843f8fb4376e1446fc330333d571e924feee4`: Disk quota exceeded: OCI runtime error
非 root 用户可拥有的最大密钥数在 kernel.keys.maxkeys 中定义。默认值为 200。
此问题可能通过增加密钥总数来解决,方法是在以下系统上执行以下操作:Red Hat / Fedora 系统(其他系统可能需要对此进行修改)
$ echo kernel.keys.maxkeys=1000 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
2.4. Ryuk reaper 容器启动失败
当 testcontainers 的 ryuk reaper 容器无法访问 Docker socket 时,验收测试可能会失败,并出现类似 No such container 或 unexpected container status "removing" 的错误。要诊断此问题,请在前台手动运行 ryuk:
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock testcontainers/ryuk:0.11.0
如果错误是 permission denied while trying to connect to the Docker daemon socket,请创建或更新 ~/.testcontainers.properties:
ryuk.container.privileged=true
这告诉 testcontainers 使用 --privileged 运行 ryuk 容器,从而授予其访问 Docker socket 的权限。
3. Apiserver 和 Rekor 主机解析失败
在运行验收测试时,您可能会遇到与 apiserver 和 rekor 主机相关的问题,例如:
+ Error: unable to fetch EnterpriseContractPolicy: Get "http://apiserver.localhost:32971/apis/appstudio.redhat.com/v1alpha1/namespaces/acceptance/enterprisecontractpolicies/mismatched-image-digest": dial tcp: lookup apiserver.localhost on 127.0.0.1:53: no such host
Post \"${REKOR}/api/v1/log/entries/retrieve\": POST ${REKOR}/api/v1/log/entries/retrieve giving up after 4 attempt(s): Post \"${REKOR}/api/v1/log/entries/retrieve\": dial tcp: lookup rekor.localhost on 127.0.0.1:53: no such host
此问题可能通过在 /etc/hosts 文件中添加以下条目来解决:
127.0.0.1 apiserver.localhost
127.0.0.1 rekor.localhost
此问题出现是因为验收测试使用了使用 CGO_ENABLED=0 构建的 ec 二进制文件。该设置 为操作系统兼容性而选择,导致程序使用 Go 的原生 DNS 解析器,而不是系统的 libc 解析器(了解更多)。因此,该二进制文件无法解析二级 localhost 域名,例如 apiserver.localhost,因为原生 Go DNS 解析器不支持以与系统解析器相同的方式解析此类名称。