Skip to content

Commit

Permalink
feat: support disabling cosign and SLSA (#2634)
Browse files Browse the repository at this point in the history
* feat: support disabling cosign

* feat: support disabling slsa verification

* fix: support disabling the checksum file verification with cosign

* fix: suppress a lint error
  • Loading branch information
suzuki-shunsuke authored Jan 26, 2024
1 parent 2f795e8 commit 25abbb0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
14 changes: 13 additions & 1 deletion pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func (r *Runner) setParam(c *cli.Context, commandName string, param *config.Para
param.All = c.Bool("all")
param.Detail = c.Bool("detail")
param.Prune = c.Bool("prune")
param.CosignDisabled = c.Bool("disable-cosign")
param.SLSADisabled = c.Bool("disable-slsa")
param.Limit = c.Int("limit")
param.SelectVersion = c.Bool("select-version")
param.ShowVersion = c.Bool("version")
Expand Down Expand Up @@ -128,7 +130,7 @@ func parseTags(tags []string) map[string]struct{} {
return tagsM
}

func (r *Runner) Run(ctx context.Context, args ...string) error {
func (r *Runner) Run(ctx context.Context, args ...string) error { //nolint:funlen
compiledDate, err := time.Parse(time.RFC3339, r.LDFlags.Date)
if err != nil {
compiledDate = time.Now()
Expand All @@ -151,6 +153,16 @@ func (r *Runner) Run(ctx context.Context, args ...string) error {
Usage: "configuration file path",
EnvVars: []string{"AQUA_CONFIG"},
},
&cli.BoolFlag{
Name: "disable-cosign",
Usage: "Disable Cosign verification",
EnvVars: []string{"AQUA_DISABLE_COSIGN"},
},
&cli.BoolFlag{
Name: "disable-slsa",
Usage: "Disable SLSA verification",
EnvVars: []string{"AQUA_DISABLE_SLSA"},
},
&cli.StringFlag{
Name: "trace",
Usage: "trace output file path",
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ type Param struct {
Detail bool
OnlyPackage bool
OnlyRegistry bool
CosignDisabled bool
SLSADisabled bool
PolicyConfigFilePaths []string
Commands []string
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/installpackage/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (is *Installer) dlAndExtractChecksum(ctx context.Context, logE *logrus.Entr
return "", fmt.Errorf("read a checksum file: %w", err)
}

if cos := pkg.PackageInfo.Checksum.GetCosign(); cos.GetEnabled() {
if cos := pkg.PackageInfo.Checksum.GetCosign(); cos.GetEnabled() && !is.cosignDisabled {
f, err := afero.TempFile(is.fs, "", "")
if err != nil {
return "", fmt.Errorf("create a temporal file: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/installpackage/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type Installer struct {
maxParallelism int
progressBar bool
onlyLink bool
cosignDisabled bool
slsaDisabled bool
}

func New(param *config.Param, downloader download.ClientAPI, rt *runtime.Runtime, fs afero.Fs, linker Linker, chkDL download.ChecksumDownloader, chkCalc ChecksumCalculator, unarchiver Unarchiver, cosignVerifier CosignVerifier, slsaVerifier SLSAVerifier, goInstallInstaller GoInstallInstaller, goBuildInstaller GoBuildInstaller, cargoPackageInstaller CargoPackageInstaller) *Installer {
Expand Down Expand Up @@ -73,6 +75,8 @@ func newInstaller(param *config.Param, downloader download.ClientAPI, rt *runtim
linker: linker,
progressBar: param.ProgressBar,
onlyLink: param.OnlyLink,
cosignDisabled: param.CosignDisabled,
slsaDisabled: param.SLSADisabled,
copyDir: param.Dest,
unarchiver: unarchiver,
cosign: cosignVerifier,
Expand Down
5 changes: 5 additions & 0 deletions pkg/installpackage/verify_cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
)

func (is *Installer) verifyWithCosign(ctx context.Context, logE *logrus.Entry, bodyFile *download.DownloadedFile, param *DownloadParam) error {
if is.cosignDisabled {
logE.Debug("cosign is disabled")
return nil
}

ppkg := param.Package

cos := ppkg.PackageInfo.Cosign
Expand Down
4 changes: 4 additions & 0 deletions pkg/installpackage/verify_slsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
)

func (is *Installer) verifyWithSLSA(ctx context.Context, logE *logrus.Entry, bodyFile *download.DownloadedFile, param *DownloadParam) error {
if is.slsaDisabled {
logE.Debug("slsa verification is disabled")
return nil
}
ppkg := param.Package
pkgInfo := param.Package.PackageInfo
sp := ppkg.PackageInfo.SLSAProvenance
Expand Down

0 comments on commit 25abbb0

Please sign in to comment.