Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing SLSA provenance and cosigns, scripts to detect #32207

Open
11 of 51 tasks
scop opened this issue Feb 15, 2025 · 3 comments
Open
11 of 51 tasks

Missing SLSA provenance and cosigns, scripts to detect #32207

scop opened this issue Feb 15, 2025 · 3 comments

Comments

@scop
Copy link
Contributor

scop commented Feb 15, 2025

What

I wrote two ugly and naive scripts to check for missing SLSA provenance and cosign configs.

cosigns.sh

#!/bin/sh

# gh api '/search/code?q="cmd:+cosign"+filename:.goreleaser.yml+filename:.goreleaser.yaml+path:/' -H Accept:application/vnd.github+json -H X-GitHub-Api-Version:2022-11-28 --paginate >cosigns.json

# ^this is naturally just goreleaser things, I'm sure some other useful queries for this could be constructed.
# But it's a start, and already finds a bunch of omissions.

for repo in $(jq -r ".items.[].repository.full_name" <cosigns.json | sort -u); do
    test -f "pkgs/$repo/registry.yaml" || continue
    grep -LF cosign: "pkgs/$repo/registry.yaml"
done

slsas.sh

#!/bin/sh

# gh api /search/code?q=slsa-framework/slsa-github-generator/.github/workflows+path:.github/workflows' -H Accept:application/vnd.github+json -H X-GitHub-Api-Version:2022-11-28 --paginate >slsas.json

for repo in $(jq -r ".items.[].repository.full_name" <slsas.json | sort -u); do
    test -f "pkgs/$repo/registry.yaml" || continue
    grep -LF slsa_provenance: "pkgs/$repo/registry.yaml"
done

Output from gh could naturally be piped directly in instead of asking to be stored in separate files per the comments, but I did this for iterating over the script implementations a bit.

It should also be noted that running the gh commands will drain one's GH REST API rate limit due to --paginate and many results.

Perhaps these would be useful enough to be somehow included in aqua-registry or serve as basis for better implementations. See note below for current output on my system.

Why

Better SLSA and cosign coverage.

Note

$ ./slsas.sh
jq: error (at <stdin>:0): Cannot iterate over null (null) # this is because I exceeded my GH REST API rate limit and the JSON ended up having that error in it
pkgs/argoproj/argo-rollouts/registry.yaml
pkgs/fission/fission/registry.yaml
pkgs/google/go-containerregistry/registry.yaml
pkgs/google/mtail/registry.yaml
pkgs/jreleaser/jreleaser/registry.yaml
pkgs/kptdev/kpt/registry.yaml
pkgs/kyverno/kyverno/registry.yaml
pkgs/restic/restic/registry.yaml
pkgs/slsa-framework/slsa-verifier/registry.yaml
pkgs/xeol-io/xeol/registry.yaml
$ ./cosigns.sh
pkgs/abhimanyu003/sttr/registry.yaml
pkgs/a-h/templ/registry.yaml
pkgs/bitnami-labs/sealed-secrets/registry.yaml
pkgs/carvel-dev/imgpkg/registry.yaml
pkgs/carvel-dev/kapp/registry.yaml
pkgs/carvel-dev/kbld/registry.yaml
pkgs/carvel-dev/vendir/registry.yaml
pkgs/carvel-dev/ytt/registry.yaml
pkgs/cert-manager/cmctl/registry.yaml
pkgs/FairwindsOps/gonogo/registry.yaml
pkgs/FairwindsOps/pluto/registry.yaml
pkgs/FairwindsOps/polaris/registry.yaml
pkgs/FairwindsOps/rbac-lookup/registry.yaml
pkgs/fission/fission/registry.yaml
pkgs/fluxcd/flux2/registry.yaml
pkgs/google/yamlfmt/registry.yaml
pkgs/helm/chart-releaser/registry.yaml
pkgs/helm/chart-testing/registry.yaml
pkgs/kubepug/kubepug/registry.yaml
pkgs/kyverno/kyverno/registry.yaml
pkgs/loft-sh/vcluster/registry.yaml
pkgs/orlangure/gocovsh/registry.yaml
pkgs/purpleclay/dns53/registry.yaml
pkgs/securego/gosec/registry.yaml
pkgs/sigstore/gitsign/registry.yaml
pkgs/sigstore/rekor/registry.yaml
pkgs/smallstep/certificates/registry.yaml
pkgs/smallstep/cli/registry.yaml
pkgs/stacklok/frizbee/registry.yaml
pkgs/stackrox/kube-linter/registry.yaml
pkgs/suzuki-shunsuke/ghalint/registry.yaml
pkgs/suzuki-shunsuke/pinact/registry.yaml
pkgs/suzuki-shunsuke/sort-issue-template/registry.yaml
pkgs/suzuki-shunsuke/tfaction-go/registry.yaml
pkgs/terramate-io/terramate/registry.yaml
pkgs/tofuutils/tenv/registry.yaml
pkgs/Trendyol/kink/registry.yaml
pkgs/trufflesecurity/trufflehog/registry.yaml
pkgs/twpayne/chezmoi/registry.yaml

SLSA

Cosign

@scop scop changed the title Missing SLSA provenance and cosigns, script to detect Missing SLSA provenance and cosigns, scripts to detect Feb 15, 2025
@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Feb 16, 2025

Thank you for your great work!

I'm working on improving the code generation.

The file extension of SLSA Provenance (.intoto.jsonl) is unique, but the extension of Cosign (.sig, .pem) isn't, so I think it's hard to generate cosign setting automatically.
Furthermore, Cosign needs several parameters.

e.g.

cosign:
opts:
- --certificate-identity-regexp
- "https://github\\.com/suzuki-shunsuke/go-release-workflow/\\.github/workflows/release\\.yaml@.*"
- --certificate-oidc-issuer
- "https://token.actions.githubusercontent.com"
- --signature
- https://github.com/suzuki-shunsuke/tfcmt/releases/download/{{.Version}}/tfcmt_{{trimV .Version}}_checksums.txt.sig
- --certificate
- https://github.com/suzuki-shunsuke/tfcmt/releases/download/{{.Version}}/tfcmt_{{trimV .Version}}_checksums.txt.pem

@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Feb 16, 2025

This is still in beta, but I've added new features to cmdx s:

  • cmdx s generates slsa_provenance
  • You can filter versions and assets by configuration file

You can scaffold configuration file by aqua gr -init <package name>.

aqua >= v2.45.0-0 v2.45.0-2 is required: aqua upa v2.45.0-2 aquaproj/aqua#3562 (comment)

e.g.

aqua gr -init fission/fission

aqua-generate-registry.yaml is generated.
Please edit version and asset fields.

e.g.

name: fission/fission
version_filter: Version matches "^v?\\d"
all_assets_filter: not ((Asset matches "\\.json$") or (Asset matches "\\.yaml$")) # Ignore JSON and YAML

About the configuration file, please see aquaproj/aqua#3562 (comment) .

Then you can pass the configuration to cmdx s by -c option:

cmdx s -c aqua-generate-registry.yaml <package name>

Note that configuration file is optional.
Basically you don't need to use configuration files.
Configuration files are useful if you want to exclude some versions and assets.

@scop
Copy link
Contributor Author

scop commented Feb 16, 2025

Nice! I'll give it a try later.

Regarding cosign, sometimes files related to it could be relatively reliably identified from *keyless.sig and/or *keyless.pem on the checksums. Even though it requires more parameters, those are mostly predictable as well. Maybe also making use of that there are both .sig and .pem (with or without "keyless"), and they are on the checksums file could yield few enough false positives for it to be useful, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants