From 45164aa187e7b390ce5e9a346c0b4fddb0a9db6f Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:35:45 -0600 Subject: [PATCH 01/22] refactor package/injector Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 47 ++++++-- src/injector/Makefile | 4 - .../zarf-package-test-amd64-0.0.1.tar.zst | Bin 3683512 -> 3683475 bytes ...f-package-test-amd64-0.0.1.tar.zst.part001 | Bin 1000000 -> 999991 bytes ...f-package-test-amd64-0.0.1.tar.zst.part002 | Bin 1000000 -> 999993 bytes ...f-package-test-amd64-0.0.1.tar.zst.part003 | Bin 1000000 -> 999990 bytes ...f-package-test-amd64-0.0.1.tar.zst.part004 | Bin 683508 -> 683497 bytes src/pkg/packager/common.go | 10 +- src/pkg/packager/create.go | 8 +- src/pkg/packager/deploy.go | 14 +-- src/pkg/packager/dev.go | 6 +- src/pkg/packager/inspect.go | 8 +- src/pkg/packager/mirror.go | 6 +- src/pkg/packager/prepare.go | 6 +- src/pkg/packager/publish.go | 14 +-- src/pkg/packager/remove.go | 2 +- src/pkg/packager2/inspect.go | 102 ++++++++++++++++++ 17 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 src/pkg/packager2/inspect.go diff --git a/src/cmd/package.go b/src/cmd/package.go index d168ed80dd..63f3e97529 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -14,6 +14,16 @@ import ( "runtime" "strings" + "github.com/zarf-dev/zarf/src/cmd/common" + "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/lint" + "github.com/zarf-dev/zarf/src/pkg/message" + "github.com/zarf-dev/zarf/src/pkg/packager/sources" + "github.com/zarf-dev/zarf/src/pkg/utils" + "github.com/zarf-dev/zarf/src/types" + + "oras.land/oras-go/v2/registry" + "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/pkg/helpers/v2" "github.com/spf13/cobra" @@ -29,12 +39,9 @@ import ( "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager" +<<<<<<< HEAD "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/packager/sources" - "github.com/zarf-dev/zarf/src/types" -) - -var packageCmd = &cobra.Command{ Use: "package", Aliases: []string{"p"}, Short: lang.CmdPackageShort, @@ -193,21 +200,41 @@ var packageInspectCmd = &cobra.Command{ return err } pkgConfig.PkgOpts.PackageSource = packageSource - src, err := identifyAndFallbackToClusterSource() + + pkgClient, err := packager.New(&pkgConfig) if err != nil { return err } - pkgClient, err := packager.New(&pkgConfig, packager.WithSource(src)) + sources.New(&pkgConfig.PkgOpts) + defer pkgClient.ClearTempPaths() + options := packager2.ZarfInspectOptions{ + ListImages: pkgConfig.InspectOpts.ListImages, + ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, + SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, + } + + src, err := sources.New(&pkgConfig.PkgOpts) if err != nil { - return err + return fmt.Errorf("failed to inspect package: %w", err) } - defer pkgClient.ClearTempPaths() - if err := pkgClient.Inspect(cmd.Context()); err != nil { + + if pkgConfig.InspectOpts.ListImages { + output, err := packager2.InspectList(cmd.Context(), src, pkgClient.Layout, options) + if err != nil { + return fmt.Errorf("failed to inspect package: %w", err) + } + for _, image := range output { + fmt.Fprintln(os.Stdout, "-", image) + } + } + + output, err := packager2.Inspect(cmd.Context(), src, pkgClient.Layout, options) + if err != nil { return fmt.Errorf("failed to inspect package: %w", err) } + utils.ColorPrintYAML(output, nil, false) return nil }, - ValidArgsFunction: getPackageCompletionArgs, } var packageListCmd = &cobra.Command{ diff --git a/src/injector/Makefile b/src/injector/Makefile index 19e47d5869..aac0515315 100644 --- a/src/injector/Makefile +++ b/src/injector/Makefile @@ -14,7 +14,6 @@ cross-injector-linux: cross-injector-amd cross-injector-arm cross-injector-amd: rustup target add x86_64-unknown-linux-musl - test -s x86_64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/x86_64-linux-musl-cross.tgz | tar -xz export PATH="$$PWD/x86_64-linux-musl-cross/bin:$$PATH" export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-cc @@ -25,7 +24,6 @@ cross-injector-amd: cross-injector-arm: rustup target add aarch64-unknown-linux-musl - test -s aarch64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/aarch64-linux-musl-cross.tgz | tar -xz export PATH="$$PWD/aarch64-linux-musl-cross/bin:$$PATH" export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-cc @@ -39,7 +37,6 @@ build-injector-linux-amd: ## Build the Zarf injector for AMD64 rustup target add x86_64-unknown-linux-musl if [ "$(shell uname -m)" = "arm64" ] || [ "$(shell uname -m)" = "aarch64" ]; then \ - test -s x86_64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/x86_64-linux-musl-cross.tgz | tar -xz; \ export PATH="$$PWD/x86_64-linux-musl-cross/bin:$$PATH"; \ export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-cc; \ cargo build --target x86_64-unknown-linux-musl --release; \ @@ -53,7 +50,6 @@ build-injector-linux-arm: ## Build the Zarf injector for ARM64 if [ "$(shell uname -m)" = "arm64" ] || [ "$(shell uname -m)" = "aarch64" ]; then \ cargo build --target aarch64-unknown-linux-musl --release; \ elif [ "$(shell uname -m)" = "x86_64" ]; then \ - test -s aarch64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/aarch64-linux-musl-cross.tgz | tar -xz; \ export PATH="$$PWD/aarch64-linux-musl-cross/bin:$$PATH"; \ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-cc; \ cargo build --target aarch64-unknown-linux-musl --release; \ diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst index 19b43aa2793e90dcfaf3d7ba8f899d5c2d4d4508..b4c62f26d261f89cdf16bfe1920a3e64da0d2bbc 100644 GIT binary patch delta 384 zcmWN=ODMwu90%}*u|FGTW5)b3uXzuDM0pi6F65CF^}kGwlpH8(Nt)lmNe*i5;=;jY zvHI>J2M3S5O7gl$%)6x&Imqu*pWw@#Vww9@fq5Z7LO{VIAOs@&8%X|)SC?vBU2574B!)E*!|}~^BwG@AB4mqp zM!-#lcH@>7G)Y{?^*ouUU_oQ}t0#}$z*FI|8!vh>=rg|m!oHFg?WeBxbZ+7q=xP^t zRix_{c_wt-S$%qPIkVt$W>1ge{v>;74Na5g>v0$#%{>Yl3z>Ni#zMJ=GHPvkTXXcb zmxs5#eDxCjI12FNu3aMl^(P>GD-etax1IhR@QV*V1KH{d4SU9+QqMb DifO1C delta 454 zcmWm7PbhOvI7gzQc5{2Ux!cM=l%Yk-|yXe%P=PpV-pOw#wH?2C?GZ=@wyo< zGW{iiLXd)troW2fvkXTHAFDb*n)9qahds|{F_e(!v-B>BUUei-+R@)W$m#Zh>(^jb z=QvX5%7osC*QS7S^4gT4Vr<_yl}At52yqoq2`Z=pHHA1$-i5QEsDWwB) zKYo#}?HXAO=fYqu=%9{-LH!wvPBNm0dXkJ7##Q+C1q|d17=!cw|GYN(_mTD`)8hhC z`eGVo{&%t_Fq1E9xtu|79Izg*qEDx+luk9sH!)`>8YwejI~6hS?AmB&w`si(vnAUE z&CmjNvSeGe?|8#~)8+}_Jj}OKn0N4V=;Bd_ZVGw*rqu0%;T$5% zx2yf*kbB?m`j!)jxwgB$<-WXkyX0z~y*lmJuk&obex27!9-_hjSP}p-m@aJq diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part002 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part002 index 55b6a5bb6728dee2881b3507b3df21af6987f299..62c6a999a936ee8f8d95a58dcde9bc67f7352921 100644 GIT binary patch delta 93 zcmX@mV!N}&wqXn7jQ87TzGqy0yWRCP6A&{4F$)m00x{cm*VF9(tlC}JIDnXQy9*oF o)!^+?QCx3+ZD$YVX4}xt$I1i5ygwy!?440A89SKmY&$ delta 107 zcmdnlVtb&)wqXn7jQ5PZ+kwRD+l;*J&Zn7xm>Gy!fS47C*|s~MX8&gelyhX`0AkMV uj%-|4gMoU)qPX7t0@6&O+-w_w@*J!@Kn$Y!wsWxZALanco#y4wGXVgVB_m`2 diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part003 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part003 index 2dac39314de1c0c7be41bfe2b3a0eda5ff70da9e..68a6d15c76a99cb29853e8f92a794a1d5155dbab 100644 GIT binary patch delta 107 zcmX@mV!N%ywqXn7v-|DO?=xbIh{s`#vz=%-=pEfhCBs{dFP>5VLN7 zoyc}7e*3nAY?~X~vz*ztXE}55Ol&W|!m+*l3g>>0c5_*-?dG!FtuF0*6S;wy2Z(vM K?@i=uegFUgfiYG9 delta 127 zcmdniVtb&)wqXn7v-^y^?LcDtv-?byS&Y2fphJ+moF+cqRhb`Byl$=U?I6?*U}%$#QMiljUx80kStI Rasx3B5c6)|oXFSw008kOF=_w+ diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part004 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part004 index d04f2ef445cef48634c4a4a8ed9cced535f60424..94ea4f2d163a612fbce3e53ee1c3147b7431dde3 100644 GIT binary patch delta 89 zcmV-f0H*)++bQYWDS)&AmI=3)2?0T5huLibx7lq1G-$UD)&d+`w<|FNT-CRT1_U3n vhp4y&x2U)UeT%myLNJ$!~EujewEWB|puuQAC)18H?b=9sHMx|xkd zepCCx9W2`y?qIF!28zhLussn3(#&CO8(si)Z? 0 { imageList := []string{} for _, component := range p.cfg.Pkg.Components { imageList = append(imageList, component.Images...) @@ -37,10 +37,10 @@ func (p *Packager) Inspect(ctx context.Context) error { utils.ColorPrintYAML(p.cfg.Pkg, nil, false) } - sbomDir := p.layout.SBOMs.Path + sbomDir := p.Layout.SBOMs.Path if p.cfg.InspectOpts.SBOMOutputDir != "" { - out, err := p.layout.SBOMs.OutputSBOMFiles(p.cfg.InspectOpts.SBOMOutputDir, p.cfg.Pkg.Metadata.Name) + out, err := p.Layout.SBOMs.OutputSBOMFiles(p.cfg.InspectOpts.SBOMOutputDir, p.cfg.Pkg.Metadata.Name) if err != nil { return err } diff --git a/src/pkg/packager/mirror.go b/src/pkg/packager/mirror.go index 9e61604144..98057c03f0 100644 --- a/src/pkg/packager/mirror.go +++ b/src/pkg/packager/mirror.go @@ -24,13 +24,13 @@ func (p *Packager) Mirror(ctx context.Context) error { filters.BySelectState(p.cfg.PkgOpts.OptionalComponents), ) - pkg, warnings, err := p.source.LoadPackage(ctx, p.layout, filter, true) + pkg, warnings, err := p.source.LoadPackage(ctx, p.Layout, filter, true) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } p.cfg.Pkg = pkg - sbomViewFiles, sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles() + sbomViewFiles, sbomWarnings, err := p.Layout.SBOMs.StageSBOMViewFiles() if err != nil { return err } @@ -56,7 +56,7 @@ func (p *Packager) Mirror(ctx context.Context) error { // mirrorComponent mirrors a Zarf Component. func (p *Packager) mirrorComponent(ctx context.Context, component v1alpha1.ZarfComponent) error { - componentPaths := p.layout.Components.Dirs[component.Name] + componentPaths := p.Layout.Components.Dirs[component.Name] // All components now require a name message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 1e43335898..eb7ee29b17 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -57,11 +57,11 @@ func (p *Packager) FindImages(ctx context.Context) (map[string][]string, error) c := creator.NewPackageCreator(p.cfg.CreateOpts, cwd) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { return nil, err } - pkg, warnings, err := c.LoadPackageDefinition(ctx, p.layout) + pkg, warnings, err := c.LoadPackageDefinition(ctx, p.Layout) if err != nil { return nil, err } @@ -136,7 +136,7 @@ func (p *Packager) findImages(ctx context.Context) (map[string][]string, error) } } - componentPaths, err := p.layout.Components.Create(component) + componentPaths, err := p.Layout.Components.Create(component) if err != nil { return nil, err } diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 94fdee63c2..2d81abd40a 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -54,31 +54,31 @@ func (p *Packager) Publish(ctx context.Context) (err error) { sc := creator.NewSkeletonCreator(p.cfg.CreateOpts, p.cfg.PublishOpts) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { return err } - p.cfg.Pkg, _, err = sc.LoadPackageDefinition(ctx, p.layout) + p.cfg.Pkg, _, err = sc.LoadPackageDefinition(ctx, p.Layout) if err != nil { return err } - if err := sc.Assemble(ctx, p.layout, p.cfg.Pkg.Components, ""); err != nil { + if err := sc.Assemble(ctx, p.Layout, p.cfg.Pkg.Components, ""); err != nil { return err } - if err := sc.Output(ctx, p.layout, &p.cfg.Pkg); err != nil { + if err := sc.Output(ctx, p.Layout, &p.cfg.Pkg); err != nil { return err } } else { filter := filters.Empty() - p.cfg.Pkg, _, err = p.source.LoadPackage(ctx, p.layout, filter, false) + p.cfg.Pkg, _, err = p.source.LoadPackage(ctx, p.Layout, filter, false) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } // Sign the package if a key has been provided - if err := p.layout.SignPackage(p.cfg.PublishOpts.SigningKeyPath, p.cfg.PublishOpts.SigningKeyPassword, !config.CommonOptions.Confirm); err != nil { + if err := p.Layout.SignPackage(p.cfg.PublishOpts.SigningKeyPath, p.cfg.PublishOpts.SigningKeyPassword, !config.CommonOptions.Confirm); err != nil { return err } } @@ -102,7 +102,7 @@ func (p *Packager) Publish(ctx context.Context) (err error) { message.HeaderInfof("📦 PACKAGE PUBLISH %s:%s", p.cfg.Pkg.Metadata.Name, ref) // Publish the package/skeleton to the registry - if err := remote.PublishPackage(ctx, &p.cfg.Pkg, p.layout, config.CommonOptions.OCIConcurrency); err != nil { + if err := remote.PublishPackage(ctx, &p.cfg.Pkg, p.Layout, config.CommonOptions.OCIConcurrency); err != nil { return err } if p.cfg.CreateOpts.IsSkeleton { diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index 322db5570f..9d1a09257e 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -40,7 +40,7 @@ func (p *Packager) Remove(ctx context.Context) error { // we do not want to allow removal of signed packages without a signature if there are remove actions // as this is arbitrary code execution from an untrusted source - pkg, _, err := p.source.LoadPackageMetadata(ctx, p.layout, false, false) + pkg, _, err := p.source.LoadPackageMetadata(ctx, p.Layout, false, false) if err != nil { return err } diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go new file mode 100644 index 0000000000..db5e537f41 --- /dev/null +++ b/src/pkg/packager2/inspect.go @@ -0,0 +1,102 @@ +package packager2 + +import ( + "context" + "fmt" + + "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/internal/packager/sbom" + "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/packager/sources" +) + +type ZarfInspectOptions struct { + // View SBOM contents while inspecting the package + ViewSBOM bool + // Location to output an SBOM into after package inspection + SBOMOutputDir string + // ListImages will list the images in the package + ListImages bool +} + +// Inspect list the contents of a package. +func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { + var err error + pkg, err := getPackageMetadata(ctx, src, layout, options) + if err != nil { + return pkg, err + } + + if getSBOM(ctx, options) { + err = handleSBOMOptions(ctx, layout, pkg, options) + if err != nil { + return pkg, err + } + + return pkg, nil + } + + return pkg, nil +} + +func InspectList(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) ([]string, error) { + var imageList []string + pkg, err := getPackageMetadata(ctx, src, layout, options) + if err != nil { + return nil, err + } + // Only list images if we have have components + if len(pkg.Components) > 0 { + for _, component := range pkg.Components { + imageList = append(imageList, component.Images...) + } + if len(imageList) > 0 { + imageList = helpers.Unique(imageList) + return imageList, nil + } + return nil, fmt.Errorf("failed listing images: list of images found in components: %d", len(imageList)) + } + + //todo: (schristoff) ????? + return imageList, err +} + +func getPackageMetadata(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { + SBOM := getSBOM(ctx, options) + + pkg, _, err := src.LoadPackageMetadata(ctx, layout, SBOM, true) + if err != nil { + return pkg, err + } + return pkg, nil +} + +func handleSBOMOptions(_ context.Context, layout *layout.PackagePaths, pkg v1alpha1.ZarfPackage, options ZarfInspectOptions) error { + if options.SBOMOutputDir != "" { + out, err := layout.SBOMs.OutputSBOMFiles(options.SBOMOutputDir, pkg.Metadata.Name) + if err != nil { + return err + } + if options.ViewSBOM { + err := sbom.ViewSBOMFiles(out) + if err != nil { + return err + } + } + } else if options.ViewSBOM { + err := sbom.ViewSBOMFiles(layout.SBOMs.Path) + if err != nil { + return err + } + return err + } + return nil +} + +func getSBOM(_ context.Context, options ZarfInspectOptions) bool { + if options.ViewSBOM || options.SBOMOutputDir != "" { + return true + } + return false +} From 51d3d52e576bfabab42cf2a32bc8c2cb22555460 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:56:56 -0600 Subject: [PATCH 02/22] revert Makefile, remove unhelpful todo Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/injector/Makefile | 4 ++++ src/pkg/packager2/inspect.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/injector/Makefile b/src/injector/Makefile index aac0515315..19e47d5869 100644 --- a/src/injector/Makefile +++ b/src/injector/Makefile @@ -14,6 +14,7 @@ cross-injector-linux: cross-injector-amd cross-injector-arm cross-injector-amd: rustup target add x86_64-unknown-linux-musl + test -s x86_64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/x86_64-linux-musl-cross.tgz | tar -xz export PATH="$$PWD/x86_64-linux-musl-cross/bin:$$PATH" export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-cc @@ -24,6 +25,7 @@ cross-injector-amd: cross-injector-arm: rustup target add aarch64-unknown-linux-musl + test -s aarch64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/aarch64-linux-musl-cross.tgz | tar -xz export PATH="$$PWD/aarch64-linux-musl-cross/bin:$$PATH" export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-cc @@ -37,6 +39,7 @@ build-injector-linux-amd: ## Build the Zarf injector for AMD64 rustup target add x86_64-unknown-linux-musl if [ "$(shell uname -m)" = "arm64" ] || [ "$(shell uname -m)" = "aarch64" ]; then \ + test -s x86_64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/x86_64-linux-musl-cross.tgz | tar -xz; \ export PATH="$$PWD/x86_64-linux-musl-cross/bin:$$PATH"; \ export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-cc; \ cargo build --target x86_64-unknown-linux-musl --release; \ @@ -50,6 +53,7 @@ build-injector-linux-arm: ## Build the Zarf injector for ARM64 if [ "$(shell uname -m)" = "arm64" ] || [ "$(shell uname -m)" = "aarch64" ]; then \ cargo build --target aarch64-unknown-linux-musl --release; \ elif [ "$(shell uname -m)" = "x86_64" ]; then \ + test -s aarch64-linux-musl-cross || curl https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/aarch64-linux-musl-cross.tgz | tar -xz; \ export PATH="$$PWD/aarch64-linux-musl-cross/bin:$$PATH"; \ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-cc; \ cargo build --target aarch64-unknown-linux-musl --release; \ diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index db5e537f41..97eca9364b 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -40,6 +40,7 @@ func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.Pack return pkg, nil } +// InspectList lists the images in a component action func InspectList(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) ([]string, error) { var imageList []string pkg, err := getPackageMetadata(ctx, src, layout, options) @@ -58,7 +59,6 @@ func InspectList(ctx context.Context, src sources.PackageSource, layout *layout. return nil, fmt.Errorf("failed listing images: list of images found in components: %d", len(imageList)) } - //todo: (schristoff) ????? return imageList, err } From fab98f25168602d53224ad21ac75d706a07e1dd2 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:18:41 -0600 Subject: [PATCH 03/22] refactor function signatures Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/pkg/packager2/inspect.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index 97eca9364b..5a61464bb0 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -23,13 +23,13 @@ type ZarfInspectOptions struct { // Inspect list the contents of a package. func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { var err error - pkg, err := getPackageMetadata(ctx, src, layout, options) + pkg, err := getPackageMetadata(ctx, src, layout, options.ViewSBOM, options.SBOMOutputDir) if err != nil { return pkg, err } - if getSBOM(ctx, options) { - err = handleSBOMOptions(ctx, layout, pkg, options) + if getSBOM(options.ViewSBOM, options.SBOMOutputDir) { + err = handleSBOMOptions(layout, pkg, options.ViewSBOM, options.SBOMOutputDir) if err != nil { return pkg, err } @@ -43,7 +43,7 @@ func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.Pack // InspectList lists the images in a component action func InspectList(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) ([]string, error) { var imageList []string - pkg, err := getPackageMetadata(ctx, src, layout, options) + pkg, err := getPackageMetadata(ctx, src, layout, options.ViewSBOM, options.SBOMOutputDir) if err != nil { return nil, err } @@ -62,8 +62,8 @@ func InspectList(ctx context.Context, src sources.PackageSource, layout *layout. return imageList, err } -func getPackageMetadata(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { - SBOM := getSBOM(ctx, options) +func getPackageMetadata(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, viewSBOM bool, SBOMOutputDir string) (v1alpha1.ZarfPackage, error) { + SBOM := getSBOM(viewSBOM, SBOMOutputDir) pkg, _, err := src.LoadPackageMetadata(ctx, layout, SBOM, true) if err != nil { @@ -72,19 +72,19 @@ func getPackageMetadata(ctx context.Context, src sources.PackageSource, layout * return pkg, nil } -func handleSBOMOptions(_ context.Context, layout *layout.PackagePaths, pkg v1alpha1.ZarfPackage, options ZarfInspectOptions) error { - if options.SBOMOutputDir != "" { - out, err := layout.SBOMs.OutputSBOMFiles(options.SBOMOutputDir, pkg.Metadata.Name) +func handleSBOMOptions(layout *layout.PackagePaths, pkg v1alpha1.ZarfPackage, viewSBOM bool, SBOMOutputDir string) error { + if SBOMOutputDir != "" { + out, err := layout.SBOMs.OutputSBOMFiles(SBOMOutputDir, pkg.Metadata.Name) if err != nil { return err } - if options.ViewSBOM { + if viewSBOM { err := sbom.ViewSBOMFiles(out) if err != nil { return err } } - } else if options.ViewSBOM { + } else if viewSBOM { err := sbom.ViewSBOMFiles(layout.SBOMs.Path) if err != nil { return err @@ -94,8 +94,8 @@ func handleSBOMOptions(_ context.Context, layout *layout.PackagePaths, pkg v1alp return nil } -func getSBOM(_ context.Context, options ZarfInspectOptions) bool { - if options.ViewSBOM || options.SBOMOutputDir != "" { +func getSBOM(viewSBOM bool, SBOMOutputDir string) bool { + if viewSBOM || SBOMOutputDir != "" { return true } return false From fee956b192ad01511607cdceff7d39bc0a55d287 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:52:07 -0600 Subject: [PATCH 04/22] linterlinterlinterlinter Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 2 +- src/pkg/packager2/inspect.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index 63f3e97529..46ffeeaee5 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -205,8 +205,8 @@ var packageInspectCmd = &cobra.Command{ if err != nil { return err } - sources.New(&pkgConfig.PkgOpts) defer pkgClient.ClearTempPaths() + options := packager2.ZarfInspectOptions{ ListImages: pkgConfig.InspectOpts.ListImages, ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index 5a61464bb0..34d10decae 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -1,3 +1,4 @@ +// Packager2 contains functions for inspecting packages. package packager2 import ( @@ -33,10 +34,8 @@ func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.Pack if err != nil { return pkg, err } - return pkg, nil } - return pkg, nil } From acd686fb52918b0b71a52fb034cdf43aea1d82af Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:58:26 -0600 Subject: [PATCH 05/22] go lint urself Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/pkg/packager2/inspect.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index 34d10decae..db2c1e09b4 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -12,6 +12,7 @@ import ( "github.com/zarf-dev/zarf/src/pkg/packager/sources" ) +// ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { // View SBOM contents while inspecting the package ViewSBOM bool From 170fc97fdf379439ba787d648bbd963e15f9ad00 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:11:53 -0600 Subject: [PATCH 06/22] packagepackagepackage Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/pkg/packager2/inspect.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index db2c1e09b4..e9632d162a 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -1,4 +1,4 @@ -// Packager2 contains functions for inspecting packages. +// Package packager2 contains functions for inspecting packages. package packager2 import ( @@ -14,6 +14,7 @@ import ( // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { + // View SBOM contents while inspecting the package ViewSBOM bool // Location to output an SBOM into after package inspection From a55e52f71e553f85a15a681ad6c9eb24c79abf09 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:15:28 -0600 Subject: [PATCH 07/22] spdx license Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/pkg/packager2/inspect.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pkg/packager2/inspect.go b/src/pkg/packager2/inspect.go index e9632d162a..3b9ac0eace 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/pkg/packager2/inspect.go @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + // Package packager2 contains functions for inspecting packages. package packager2 From fc4fe01f1ae1e0c63abdb72fddbcb7b21e359919 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:16:46 -0600 Subject: [PATCH 08/22] utilizeLoad Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 42 ++++++++++------------ src/{pkg => internal}/packager2/inspect.go | 20 +++++------ 2 files changed, 28 insertions(+), 34 deletions(-) rename src/{pkg => internal}/packager2/inspect.go (71%) diff --git a/src/cmd/package.go b/src/cmd/package.go index 46ffeeaee5..4845d7896e 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -14,16 +14,6 @@ import ( "runtime" "strings" - "github.com/zarf-dev/zarf/src/cmd/common" - "github.com/zarf-dev/zarf/src/config/lang" - "github.com/zarf-dev/zarf/src/pkg/lint" - "github.com/zarf-dev/zarf/src/pkg/message" - "github.com/zarf-dev/zarf/src/pkg/packager/sources" - "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" - - "oras.land/oras-go/v2/registry" - "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/pkg/helpers/v2" "github.com/spf13/cobra" @@ -39,9 +29,13 @@ import ( "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager" -<<<<<<< HEAD "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/packager/sources" + "github.com/zarf-dev/zarf/src/pkg/utils" + "github.com/zarf-dev/zarf/src/types" +) + +var packageCmd = &cobra.Command{ Use: "package", Aliases: []string{"p"}, Short: lang.CmdPackageShort, @@ -195,31 +189,33 @@ var packageInspectCmd = &cobra.Command{ } }, RunE: func(cmd *cobra.Command, args []string) error { - packageSource, err := choosePackage(args) + src, err := choosePackage(args) if err != nil { return err } - pkgConfig.PkgOpts.PackageSource = packageSource - pkgClient, err := packager.New(&pkgConfig) + loadOpt := packager2.LoadOptions{ + Source: src, + Shasum: pkgConfig.PkgOpts.Shasum, + PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, + SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, + } + + pkgPaths, err := packager2.LoadPackage(cmd.Context(), loadOpt) if err != nil { return err } - defer pkgClient.ClearTempPaths() + defer os.RemoveAll(pkgPaths.Base) - options := packager2.ZarfInspectOptions{ + inspectOpt := packager2.ZarfInspectOptions{ + PackagePaths: pkgPaths, ListImages: pkgConfig.InspectOpts.ListImages, ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, } - src, err := sources.New(&pkgConfig.PkgOpts) - if err != nil { - return fmt.Errorf("failed to inspect package: %w", err) - } - if pkgConfig.InspectOpts.ListImages { - output, err := packager2.InspectList(cmd.Context(), src, pkgClient.Layout, options) + output, err := packager2.InspectList(cmd.Context(), inspectOpt) if err != nil { return fmt.Errorf("failed to inspect package: %w", err) } @@ -228,7 +224,7 @@ var packageInspectCmd = &cobra.Command{ } } - output, err := packager2.Inspect(cmd.Context(), src, pkgClient.Layout, options) + output, err := packager2.Inspect(cmd.Context(), inspectOpt) if err != nil { return fmt.Errorf("failed to inspect package: %w", err) } diff --git a/src/pkg/packager2/inspect.go b/src/internal/packager2/inspect.go similarity index 71% rename from src/pkg/packager2/inspect.go rename to src/internal/packager2/inspect.go index 3b9ac0eace..6ab1b45116 100644 --- a/src/pkg/packager2/inspect.go +++ b/src/internal/packager2/inspect.go @@ -12,12 +12,12 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/sbom" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/packager/sources" ) // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { - + // PackagePaths + PackagePaths *layout.PackagePaths // View SBOM contents while inspecting the package ViewSBOM bool // Location to output an SBOM into after package inspection @@ -27,15 +27,15 @@ type ZarfInspectOptions struct { } // Inspect list the contents of a package. -func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { +func Inspect(ctx context.Context, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { var err error - pkg, err := getPackageMetadata(ctx, src, layout, options.ViewSBOM, options.SBOMOutputDir) + pkg, err := getPackageMetadata(ctx, options.PackagePaths) if err != nil { return pkg, err } if getSBOM(options.ViewSBOM, options.SBOMOutputDir) { - err = handleSBOMOptions(layout, pkg, options.ViewSBOM, options.SBOMOutputDir) + err = handleSBOMOptions(options.PackagePaths, pkg, options.ViewSBOM, options.SBOMOutputDir) if err != nil { return pkg, err } @@ -45,9 +45,9 @@ func Inspect(ctx context.Context, src sources.PackageSource, layout *layout.Pack } // InspectList lists the images in a component action -func InspectList(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, options ZarfInspectOptions) ([]string, error) { +func InspectList(ctx context.Context, options ZarfInspectOptions) ([]string, error) { var imageList []string - pkg, err := getPackageMetadata(ctx, src, layout, options.ViewSBOM, options.SBOMOutputDir) + pkg, err := getPackageMetadata(ctx, options.PackagePaths) if err != nil { return nil, err } @@ -66,10 +66,8 @@ func InspectList(ctx context.Context, src sources.PackageSource, layout *layout. return imageList, err } -func getPackageMetadata(ctx context.Context, src sources.PackageSource, layout *layout.PackagePaths, viewSBOM bool, SBOMOutputDir string) (v1alpha1.ZarfPackage, error) { - SBOM := getSBOM(viewSBOM, SBOMOutputDir) - - pkg, _, err := src.LoadPackageMetadata(ctx, layout, SBOM, true) +func getPackageMetadata(_ context.Context, layout *layout.PackagePaths) (v1alpha1.ZarfPackage, error) { + pkg, _, err := layout.ReadZarfYAML() if err != nil { return pkg, err } From b66246ca0a74756909564b611e561b213dd6d46b Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:42:32 -0600 Subject: [PATCH 09/22] weird why did these change Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/internal/packager2/load_test.go | 4 ++-- src/internal/packager2/pull_test.go | 2 +- .../testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/packager2/load_test.go b/src/internal/packager2/load_test.go index b9b6cf37c2..7d1784d2ad 100644 --- a/src/internal/packager2/load_test.go +++ b/src/internal/packager2/load_test.go @@ -26,12 +26,12 @@ func TestLoadPackage(t *testing.T) { { name: "tarball", source: "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", - shasum: "307294e3a066cebea6f04772c2ba31210b2753b40b0d5da86a1983c29c5545dd", + shasum: "b16816b9772b72f3395132a67333b149a5d6031cfe24520df372a81f40182da2", }, { name: "split", source: "./testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000", - shasum: "6c0de217e3eeff224679ec0a26751655759a30f4aae7fbe793ca1617ddfc4228", + shasum: "19c22ed4f6981cb1475e13dd790daf89b63c04bcc475e6d066cdc0ce8843d897", }, } for _, tt := range tests { diff --git a/src/internal/packager2/pull_test.go b/src/internal/packager2/pull_test.go index 72c85ac4d5..cd20afbafb 100644 --- a/src/internal/packager2/pull_test.go +++ b/src/internal/packager2/pull_test.go @@ -38,7 +38,7 @@ func TestPull(t *testing.T) { }) dir := t.TempDir() - shasum := "307294e3a066cebea6f04772c2ba31210b2753b40b0d5da86a1983c29c5545dd" + shasum := "b16816b9772b72f3395132a67333b149a5d6031cfe24520df372a81f40182da2" err := Pull(ctx, srv.URL, dir, shasum, filters.Empty()) require.NoError(t, err) diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 index 2bb849cd7e..c4da6ff830 100644 --- a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 +++ b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 @@ -1 +1 @@ -{"sha256Sum":"6c0de217e3eeff224679ec0a26751655759a30f4aae7fbe793ca1617ddfc4228","bytes":3683508,"count":4} \ No newline at end of file +{"sha256Sum":"19c22ed4f6981cb1475e13dd790daf89b63c04bcc475e6d066cdc0ce8843d897","bytes":3683508,"count":4} \ No newline at end of file From 0d7a93baf3e2dbf8f9700993a2dc77c33a5dd47d Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 18 Sep 2024 22:48:42 -0600 Subject: [PATCH 10/22] revert shasum Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/internal/packager2/load_test.go | 4 ++-- src/internal/packager2/pull_test.go | 2 +- .../zarf-package-test-amd64-0.0.1.tar.zst | Bin 3683475 -> 3683512 bytes ...f-package-test-amd64-0.0.1.tar.zst.part000 | 2 +- ...f-package-test-amd64-0.0.1.tar.zst.part001 | Bin 999991 -> 1000000 bytes ...f-package-test-amd64-0.0.1.tar.zst.part002 | Bin 999993 -> 1000000 bytes ...f-package-test-amd64-0.0.1.tar.zst.part003 | Bin 999990 -> 1000000 bytes ...f-package-test-amd64-0.0.1.tar.zst.part004 | Bin 683497 -> 683508 bytes 8 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/packager2/load_test.go b/src/internal/packager2/load_test.go index 7d1784d2ad..b9b6cf37c2 100644 --- a/src/internal/packager2/load_test.go +++ b/src/internal/packager2/load_test.go @@ -26,12 +26,12 @@ func TestLoadPackage(t *testing.T) { { name: "tarball", source: "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", - shasum: "b16816b9772b72f3395132a67333b149a5d6031cfe24520df372a81f40182da2", + shasum: "307294e3a066cebea6f04772c2ba31210b2753b40b0d5da86a1983c29c5545dd", }, { name: "split", source: "./testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000", - shasum: "19c22ed4f6981cb1475e13dd790daf89b63c04bcc475e6d066cdc0ce8843d897", + shasum: "6c0de217e3eeff224679ec0a26751655759a30f4aae7fbe793ca1617ddfc4228", }, } for _, tt := range tests { diff --git a/src/internal/packager2/pull_test.go b/src/internal/packager2/pull_test.go index cd20afbafb..72c85ac4d5 100644 --- a/src/internal/packager2/pull_test.go +++ b/src/internal/packager2/pull_test.go @@ -38,7 +38,7 @@ func TestPull(t *testing.T) { }) dir := t.TempDir() - shasum := "b16816b9772b72f3395132a67333b149a5d6031cfe24520df372a81f40182da2" + shasum := "307294e3a066cebea6f04772c2ba31210b2753b40b0d5da86a1983c29c5545dd" err := Pull(ctx, srv.URL, dir, shasum, filters.Empty()) require.NoError(t, err) diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst index b4c62f26d261f89cdf16bfe1920a3e64da0d2bbc..19b43aa2793e90dcfaf3d7ba8f899d5c2d4d4508 100644 GIT binary patch delta 454 zcmWm7PbhOvI7gzQc5{2Ux!cM=l%Yk-|yXe%P=PpV-pOw#wH?2C?GZ=@wyo< zGW{iiLXd)troW2fvkXTHAFDb*n)9qahds|{F_e(!v-B>BUUei-+R@)W$m#Zh>(^jb z=QvX5%7osC*QS7S^4gT4Vr<_yl}At52yqoq2`Z=pHHA1$-i5QEsDWwB) zKYo#}?HXAO=fYqu=%9{-LH!wvPBNm0dXkJ7##Q+C1q|d17=!cw|GYN(_mTD`)8hhC z`eGVo{&%t_Fq1E9xtu|79Izg*qEDx+luk9sH!)`>8YwejI~6hS?AmB&w`si(vnAUE z&CmjNvSeGe?|8#~)8+}_Jj}OKn0N4V=;Bd_ZVGw*J2M3S5O7gl$%)6x&Imqu*pWw@#Vww9@fq5Z7LO{VIAOs@&8%X|)SC?vBU2574B!)E*!|}~^BwG@AB4mqp zM!-#lcH@>7G)Y{?^*ouUU_oQ}t0#}$z*FI|8!vh>=rg|m!oHFg?WeBxbZ+7q=xP^t zRix_{c_wt-S$%qPIkVt$W>1ge{v>;74Na5g>v0$#%{>Yl3z>Ni#zMJ=GHPvkTXXcb zmxs5#eDxCjI12FNu3aMl^(P>GD-etax1IhR@QV*V1KH{d4SU9+QqMb DifO1C diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 index c4da6ff830..2bb849cd7e 100644 --- a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 +++ b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part000 @@ -1 +1 @@ -{"sha256Sum":"19c22ed4f6981cb1475e13dd790daf89b63c04bcc475e6d066cdc0ce8843d897","bytes":3683508,"count":4} \ No newline at end of file +{"sha256Sum":"6c0de217e3eeff224679ec0a26751655759a30f4aae7fbe793ca1617ddfc4228","bytes":3683508,"count":4} \ No newline at end of file diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part001 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part001 index b089a46424b2b65ecf16f69461d71b8b61ef92a0..5ed2b42c1b9679eb0c7a1ff0406de9d42e56a17b 100644 GIT binary patch delta 122 zcmdnqVtb&)b_4qsM&4%jE$u)Wh?%ytZ($C#W#ny-`N#~!EI`Z(#BAGRKC*90W#rw? z7tSHF97rqu!9-_hjSP}p-m@aJq delta 106 zcmX@mV!OS?b_4sCW{xfG99tNHm}xu57Uodf_PCGCK+FQftU%1RJ?rqu0%;T$5% zx2yf*kbB?m`j!)jxwgB$<-WXkyX0z~y*lmJuk&obex27Gy!fS47C*|s~MX8&gelyhX`0AkMV uj%-|4gMoU)qPX7t0@6&O+-w_w@*J!@Kn$Y!wsWxZALanco#y4wGXVgVB_m`2 delta 93 zcmX@mV!N}&wqXn7jQ87TzGqy0yWRCP6A&{4F$)m00x{cm*VF9(tlC}JIDnXQy9*oF o)!^+?QCx3+ZD$YVX4}xt$I1i5ygwy!?440A89SKmY&$ diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part003 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part003 index 68a6d15c76a99cb29853e8f92a794a1d5155dbab..2dac39314de1c0c7be41bfe2b3a0eda5ff70da9e 100644 GIT binary patch delta 127 zcmdniVtb&)wqXn7v-^y^?LcDtv-?byS&Y2fphJ+moF+cqRhb`Byl$=U?I6?*U}%$#QMiljUx80kStI Rasx3B5c6)|oXFSw008kOF=_w+ delta 107 zcmX@mV!N%ywqXn7v-|DO?=xbIh{s`#vz=%-=pEfhCBs{dFP>5VLN7 zoyc}7e*3nAY?~X~vz*ztXE}55Ol&W|!m+*l3g>>0c5_*-?dG!FtuF0*6S;wy2Z(vM K?@i=uegFUgfiYG9 diff --git a/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part004 b/src/internal/packager2/testdata/zarf-package-test-amd64-0.0.1.tar.zst.part004 index 94ea4f2d163a612fbce3e53ee1c3147b7431dde3..d04f2ef445cef48634c4a4a8ed9cced535f60424 100644 GIT binary patch delta 109 zcmaEPTl33p&4w+E(>NJ$!~EujewEWB|puuQAC)18H?b=9sHMx|xkd zepCCx9W2`y?qIF!28zhLussn3(#&CO8(si)Z? Date: Thu, 19 Sep 2024 11:36:26 -0600 Subject: [PATCH 11/22] little l delete test filter empty Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 1 + src/pkg/packager/common.go | 10 +++++----- src/pkg/packager/create.go | 8 ++++---- src/pkg/packager/deploy.go | 14 +++++++------- src/pkg/packager/dev.go | 6 +++--- src/pkg/packager/inspect.go | 6 +++--- src/pkg/packager/mirror.go | 6 +++--- src/pkg/packager/prepare.go | 6 +++--- src/pkg/packager/publish.go | 14 +++++++------- src/pkg/packager/remove.go | 2 +- src/test/e2e/00_use_cli_test.go | 10 ---------- 11 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index 4845d7896e..25e063cd2b 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -199,6 +199,7 @@ var packageInspectCmd = &cobra.Command{ Shasum: pkgConfig.PkgOpts.Shasum, PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, + Filter: filters.Empty(), } pkgPaths, err := packager2.LoadPackage(cmd.Context(), loadOpt) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 8ae82ebf43..1325a70b46 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -34,7 +34,7 @@ type Packager struct { variableConfig *variables.VariableConfig state *types.ZarfState cluster *cluster.Cluster - Layout *layout.PackagePaths + layout *layout.PackagePaths hpaModified bool source sources.PackageSource } @@ -61,7 +61,7 @@ func WithCluster(cluster *cluster.Cluster) Modifier { // This temp directory is used as the destination where p.source loads the package. func WithTemp(base string) Modifier { return func(p *Packager) { - p.Layout = layout.New(base) + p.layout = layout.New(base) } } @@ -104,13 +104,13 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) { } // If the temp directory is not set, set it to the default - if pkgr.Layout == nil { + if pkgr.layout == nil { dir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) if err != nil { return nil, fmt.Errorf("unable to create package temp paths: %w", err) } message.Debug("Using temporary directory:", dir) - pkgr.Layout = layout.New(dir) + pkgr.layout = layout.New(dir) } return pkgr, nil @@ -119,7 +119,7 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) { // ClearTempPaths removes the temp directory and any files within it. func (p *Packager) ClearTempPaths() { // Remove the temp directory, but don't throw an error if it fails - _ = os.RemoveAll(p.Layout.Base) + _ = os.RemoveAll(p.layout.Base) _ = os.RemoveAll(layout.SBOMDir) } diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index 5ad620c991..517726eba4 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -31,11 +31,11 @@ func (p *Packager) Create(ctx context.Context) error { pc := creator.NewPackageCreator(p.cfg.CreateOpts, cwd) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { return err } - pkg, warnings, err := pc.LoadPackageDefinition(ctx, p.Layout) + pkg, warnings, err := pc.LoadPackageDefinition(ctx, p.layout) if err != nil { return err } @@ -45,7 +45,7 @@ func (p *Packager) Create(ctx context.Context) error { return fmt.Errorf("package creation canceled") } - if err := pc.Assemble(ctx, p.Layout, p.cfg.Pkg.Components, p.cfg.Pkg.Metadata.Architecture); err != nil { + if err := pc.Assemble(ctx, p.layout, p.cfg.Pkg.Components, p.cfg.Pkg.Metadata.Architecture); err != nil { return err } @@ -54,5 +54,5 @@ func (p *Packager) Create(ctx context.Context) error { return err } - return pc.Output(ctx, p.Layout, &p.cfg.Pkg) + return pc.Output(ctx, p.layout, &p.cfg.Pkg) } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 5f2f7a8670..ee3796ac6c 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -69,14 +69,14 @@ func (p *Packager) Deploy(ctx context.Context) error { warnings := []string{} if isInteractive { filter := filters.Empty() - pkg, loadWarnings, err := p.source.LoadPackage(ctx, p.Layout, filter, true) + pkg, loadWarnings, err := p.source.LoadPackage(ctx, p.layout, filter, true) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } p.cfg.Pkg = pkg warnings = append(warnings, loadWarnings...) } else { - pkg, loadWarnings, err := p.source.LoadPackage(ctx, p.Layout, deployFilter, true) + pkg, loadWarnings, err := p.source.LoadPackage(ctx, p.layout, deployFilter, true) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } @@ -93,7 +93,7 @@ func (p *Packager) Deploy(ctx context.Context) error { } warnings = append(warnings, validateWarnings...) - sbomViewFiles, sbomWarnings, err := p.Layout.SBOMs.StageSBOMViewFiles() + sbomViewFiles, sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles() if err != nil { return err } @@ -294,7 +294,7 @@ func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.Z // Before deploying the seed registry, start the injector if isSeedRegistry { - err := p.cluster.StartInjection(ctx, p.Layout.Base, p.Layout.Images.Base, component.Images) + err := p.cluster.StartInjection(ctx, p.layout.Base, p.layout.Images.Base, component.Images) if err != nil { return nil, err } @@ -320,7 +320,7 @@ func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.Z // Deploy a Zarf Component. func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfComponent, noImgChecksum bool, noImgPush bool) ([]types.InstalledChart, error) { // Toggles for general deploy operations - componentPath := p.Layout.Components.Dirs[component.Name] + componentPath := p.layout.Components.Dirs[component.Name] // All components now require a name message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) @@ -438,7 +438,7 @@ func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLo } // Replace temp target directory and home directory - file.Target = strings.Replace(file.Target, "###ZARF_TEMP###", p.Layout.Base, 1) + file.Target = strings.Replace(file.Target, "###ZARF_TEMP###", p.layout.Base, 1) file.Target = config.GetAbsHomePath(file.Target) fileList := []string{} @@ -577,7 +577,7 @@ func (p *Packager) pushImagesToRegistry(ctx context.Context, componentImages []s imageList := helpers.Unique(combinedImageList) pushCfg := images.PushConfig{ - SourceDirectory: p.Layout.Images.Base, + SourceDirectory: p.layout.Images.Base, ImageList: imageList, RegInfo: p.state.RegistryInfo, NoChecksum: noImgChecksum, diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index bbb9f4543c..de7af6f4af 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -34,11 +34,11 @@ func (p *Packager) DevDeploy(ctx context.Context) error { pc := creator.NewPackageCreator(p.cfg.CreateOpts, cwd) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { return err } - p.cfg.Pkg, _, err = pc.LoadPackageDefinition(ctx, p.Layout) + p.cfg.Pkg, _, err = pc.LoadPackageDefinition(ctx, p.layout) if err != nil { return err } @@ -68,7 +68,7 @@ func (p *Packager) DevDeploy(ctx context.Context) error { } } - if err := pc.Assemble(ctx, p.Layout, p.cfg.Pkg.Components, p.cfg.Pkg.Metadata.Architecture); err != nil { + if err := pc.Assemble(ctx, p.layout, p.cfg.Pkg.Components, p.cfg.Pkg.Metadata.Architecture); err != nil { return err } diff --git a/src/pkg/packager/inspect.go b/src/pkg/packager/inspect.go index b4d129e109..7d6a49df4e 100644 --- a/src/pkg/packager/inspect.go +++ b/src/pkg/packager/inspect.go @@ -18,7 +18,7 @@ import ( func (p *Packager) Inspect(ctx context.Context) error { wantSBOM := p.cfg.InspectOpts.ViewSBOM || p.cfg.InspectOpts.SBOMOutputDir != "" - pkg, _, err := p.source.LoadPackageMetadata(ctx, p.Layout, wantSBOM, true) + pkg, _, err := p.source.LoadPackageMetadata(ctx, p.layout, wantSBOM, true) if err != nil { return err } @@ -37,10 +37,10 @@ func (p *Packager) Inspect(ctx context.Context) error { utils.ColorPrintYAML(p.cfg.Pkg, nil, false) } - sbomDir := p.Layout.SBOMs.Path + sbomDir := p.layout.SBOMs.Path if p.cfg.InspectOpts.SBOMOutputDir != "" { - out, err := p.Layout.SBOMs.OutputSBOMFiles(p.cfg.InspectOpts.SBOMOutputDir, p.cfg.Pkg.Metadata.Name) + out, err := p.layout.SBOMs.OutputSBOMFiles(p.cfg.InspectOpts.SBOMOutputDir, p.cfg.Pkg.Metadata.Name) if err != nil { return err } diff --git a/src/pkg/packager/mirror.go b/src/pkg/packager/mirror.go index 98057c03f0..9e61604144 100644 --- a/src/pkg/packager/mirror.go +++ b/src/pkg/packager/mirror.go @@ -24,13 +24,13 @@ func (p *Packager) Mirror(ctx context.Context) error { filters.BySelectState(p.cfg.PkgOpts.OptionalComponents), ) - pkg, warnings, err := p.source.LoadPackage(ctx, p.Layout, filter, true) + pkg, warnings, err := p.source.LoadPackage(ctx, p.layout, filter, true) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } p.cfg.Pkg = pkg - sbomViewFiles, sbomWarnings, err := p.Layout.SBOMs.StageSBOMViewFiles() + sbomViewFiles, sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles() if err != nil { return err } @@ -56,7 +56,7 @@ func (p *Packager) Mirror(ctx context.Context) error { // mirrorComponent mirrors a Zarf Component. func (p *Packager) mirrorComponent(ctx context.Context, component v1alpha1.ZarfComponent) error { - componentPaths := p.Layout.Components.Dirs[component.Name] + componentPaths := p.layout.Components.Dirs[component.Name] // All components now require a name message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index eb7ee29b17..1e43335898 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -57,11 +57,11 @@ func (p *Packager) FindImages(ctx context.Context) (map[string][]string, error) c := creator.NewPackageCreator(p.cfg.CreateOpts, cwd) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { return nil, err } - pkg, warnings, err := c.LoadPackageDefinition(ctx, p.Layout) + pkg, warnings, err := c.LoadPackageDefinition(ctx, p.layout) if err != nil { return nil, err } @@ -136,7 +136,7 @@ func (p *Packager) findImages(ctx context.Context) (map[string][]string, error) } } - componentPaths, err := p.Layout.Components.Create(component) + componentPaths, err := p.layout.Components.Create(component) if err != nil { return nil, err } diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 2d81abd40a..94fdee63c2 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -54,31 +54,31 @@ func (p *Packager) Publish(ctx context.Context) (err error) { sc := creator.NewSkeletonCreator(p.cfg.CreateOpts, p.cfg.PublishOpts) - if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.Layout.ZarfYAML); err != nil { + if err := helpers.CreatePathAndCopy(layout.ZarfYAML, p.layout.ZarfYAML); err != nil { return err } - p.cfg.Pkg, _, err = sc.LoadPackageDefinition(ctx, p.Layout) + p.cfg.Pkg, _, err = sc.LoadPackageDefinition(ctx, p.layout) if err != nil { return err } - if err := sc.Assemble(ctx, p.Layout, p.cfg.Pkg.Components, ""); err != nil { + if err := sc.Assemble(ctx, p.layout, p.cfg.Pkg.Components, ""); err != nil { return err } - if err := sc.Output(ctx, p.Layout, &p.cfg.Pkg); err != nil { + if err := sc.Output(ctx, p.layout, &p.cfg.Pkg); err != nil { return err } } else { filter := filters.Empty() - p.cfg.Pkg, _, err = p.source.LoadPackage(ctx, p.Layout, filter, false) + p.cfg.Pkg, _, err = p.source.LoadPackage(ctx, p.layout, filter, false) if err != nil { return fmt.Errorf("unable to load the package: %w", err) } // Sign the package if a key has been provided - if err := p.Layout.SignPackage(p.cfg.PublishOpts.SigningKeyPath, p.cfg.PublishOpts.SigningKeyPassword, !config.CommonOptions.Confirm); err != nil { + if err := p.layout.SignPackage(p.cfg.PublishOpts.SigningKeyPath, p.cfg.PublishOpts.SigningKeyPassword, !config.CommonOptions.Confirm); err != nil { return err } } @@ -102,7 +102,7 @@ func (p *Packager) Publish(ctx context.Context) (err error) { message.HeaderInfof("📦 PACKAGE PUBLISH %s:%s", p.cfg.Pkg.Metadata.Name, ref) // Publish the package/skeleton to the registry - if err := remote.PublishPackage(ctx, &p.cfg.Pkg, p.Layout, config.CommonOptions.OCIConcurrency); err != nil { + if err := remote.PublishPackage(ctx, &p.cfg.Pkg, p.layout, config.CommonOptions.OCIConcurrency); err != nil { return err } if p.cfg.CreateOpts.IsSkeleton { diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index 9d1a09257e..322db5570f 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -40,7 +40,7 @@ func (p *Packager) Remove(ctx context.Context) error { // we do not want to allow removal of signed packages without a signature if there are remove actions // as this is arbitrary code execution from an untrusted source - pkg, _, err := p.source.LoadPackageMetadata(ctx, p.Layout, false, false) + pkg, _, err := p.source.LoadPackageMetadata(ctx, p.layout, false, false) if err != nil { return err } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 9071a114b7..366bacb7f9 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -154,16 +154,6 @@ func TestUseCLI(t *testing.T) { require.Greater(t, len(files), 1) }) - // TODO: Refactor test as it depends on debug log output for validation. - t.Run("zarf package inspect with tmpdir", func(t *testing.T) { - t.Parallel() - path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) - tmpdir := t.TempDir() - stdOut, stdErr, err := e2e.Zarf(t, "package", "inspect", path, "--tmpdir", tmpdir, "--log-level=debug") - require.Contains(t, stdErr, tmpdir, "The other tmp path should show as being created") - require.NoError(t, err, stdOut, stdErr) - }) - // TODO: Refactor test as it depends on debug log output for validation. t.Run("zarf package deploy with tmpdir", func(t *testing.T) { t.Parallel() From 7e6f780a1f1a6fbb007ef015df224398c367dbe1 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:17:29 -0600 Subject: [PATCH 12/22] stop checking log output Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/test/e2e/31_checksum_and_signature_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/e2e/31_checksum_and_signature_test.go b/src/test/e2e/31_checksum_and_signature_test.go index 0c50817099..b3d98bb25d 100644 --- a/src/test/e2e/31_checksum_and_signature_test.go +++ b/src/test/e2e/31_checksum_and_signature_test.go @@ -31,7 +31,6 @@ func TestChecksumAndSignature(t *testing.T) { // Test that we don't get an error when we remember to provide the public key stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) - require.Contains(t, stdErr, "Verified OK") /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key From 081b38f12f07e36ba4acfd37d63f588f7a29e573 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:07:20 -0600 Subject: [PATCH 13/22] not skip Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/internal/packager2/load.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/packager2/load.go b/src/internal/packager2/load.go index b20eea6195..b7ac7ee4d1 100644 --- a/src/internal/packager2/load.go +++ b/src/internal/packager2/load.go @@ -136,7 +136,7 @@ func LoadPackage(ctx context.Context, opt LoadOptions) (*layout.PackagePaths, er if err := sources.ValidatePackageIntegrity(pkgPaths, pkg.Metadata.AggregateChecksum, isPartial); err != nil { return nil, err } - if opt.SkipSignatureValidation { + if !opt.SkipSignatureValidation { if err := sources.ValidatePackageSignature(ctx, pkgPaths, opt.PublicKeyPath); err != nil { return nil, err } From b0a7d8370cdd2e32b18ab058c462e3731bdbf4d2 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:37:07 -0600 Subject: [PATCH 14/22] new feature Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/test/e2e/31_checksum_and_signature_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test/e2e/31_checksum_and_signature_test.go b/src/test/e2e/31_checksum_and_signature_test.go index b3d98bb25d..011b7229d2 100644 --- a/src/test/e2e/31_checksum_and_signature_test.go +++ b/src/test/e2e/31_checksum_and_signature_test.go @@ -23,11 +23,6 @@ func TestChecksumAndSignature(t *testing.T) { require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(pkgName) - /* Test operations during package inspect */ - // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName) - require.NoError(t, err, stdOut, stdErr) - // Test that we don't get an error when we remember to provide the public key stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) From 14b61533018443cbec848de9650cf300dbfea8f2 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 06:48:15 -0600 Subject: [PATCH 15/22] be more insecure Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/test/e2e/11_oci_pull_inspect_test.go | 2 +- src/test/e2e/34_custom_init_package_test.go | 2 +- src/test/nightly/ecr_publish_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/e2e/11_oci_pull_inspect_test.go b/src/test/e2e/11_oci_pull_inspect_test.go index 52be7ab127..9a8189b0ab 100644 --- a/src/test/e2e/11_oci_pull_inspect_test.go +++ b/src/test/e2e/11_oci_pull_inspect_test.go @@ -70,7 +70,7 @@ func (suite *PullInspectTestSuite) Test_1_Remote_Inspect() { // Test inspect on a public package. // NOTE: This also makes sure that Zarf does not attempt auth when inspecting a public package. ref := fmt.Sprintf("oci://ghcr.io/zarf-dev/packages/dos-games:1.0.0-%s", e2e.Arch) - _, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", ref) + _, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", ref, "--insecure") suite.NoError(err, stdErr) } diff --git a/src/test/e2e/34_custom_init_package_test.go b/src/test/e2e/34_custom_init_package_test.go index d63226a9c8..230eaca983 100644 --- a/src/test/e2e/34_custom_init_package_test.go +++ b/src/test/e2e/34_custom_init_package_test.go @@ -26,7 +26,7 @@ func TestCustomInit(t *testing.T) { /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--insecure") require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key diff --git a/src/test/nightly/ecr_publish_test.go b/src/test/nightly/ecr_publish_test.go index ea58faa677..37980ad7b1 100644 --- a/src/test/nightly/ecr_publish_test.go +++ b/src/test/nightly/ecr_publish_test.go @@ -70,10 +70,10 @@ func TestECRPublishing(t *testing.T) { defer e2e.CleanFiles(testPackageFileName) // Ensure we get a warning when trying to inspect the package without providing the public key - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName) + // and the insecure flag + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName, "--insecure") require.NoError(t, err, stdOut, stdErr) require.NotContains(t, stdErr, "Validating SBOM checksums") - require.Contains(t, stdErr, "The package was signed but no public key was provided, skipping signature validation") // Validate that we get no warnings when inspecting the package while providing the public key stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName, keyFlag) From bc0630845311870610982f12abef815b0036a51a Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:01:58 -0600 Subject: [PATCH 16/22] readd test to fail, minor fixes Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 2 ++ src/internal/packager2/inspect.go | 12 +++++------- src/pkg/packager/inspect.go | 2 +- src/test/e2e/31_checksum_and_signature_test.go | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index 25e063cd2b..f8fac1ef19 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -208,8 +208,10 @@ var packageInspectCmd = &cobra.Command{ } defer os.RemoveAll(pkgPaths.Base) + cluster, _ := cluster.NewCluster() inspectOpt := packager2.ZarfInspectOptions{ PackagePaths: pkgPaths, + Cluster: cluster, ListImages: pkgConfig.InspectOpts.ListImages, ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, diff --git a/src/internal/packager2/inspect.go b/src/internal/packager2/inspect.go index 6ab1b45116..17a39f7942 100644 --- a/src/internal/packager2/inspect.go +++ b/src/internal/packager2/inspect.go @@ -11,19 +11,17 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/sbom" + "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/layout" ) // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { - // PackagePaths - PackagePaths *layout.PackagePaths - // View SBOM contents while inspecting the package - ViewSBOM bool - // Location to output an SBOM into after package inspection + PackagePaths *layout.PackagePaths + Cluster *cluster.Cluster + ViewSBOM bool SBOMOutputDir string - // ListImages will list the images in the package - ListImages bool + ListImages bool } // Inspect list the contents of a package. diff --git a/src/pkg/packager/inspect.go b/src/pkg/packager/inspect.go index 7d6a49df4e..ae850498b8 100644 --- a/src/pkg/packager/inspect.go +++ b/src/pkg/packager/inspect.go @@ -24,7 +24,7 @@ func (p *Packager) Inspect(ctx context.Context) error { } p.cfg.Pkg = pkg - if p.cfg.InspectOpts.ListImages && len(p.cfg.Pkg.Components) > 0 { + if p.cfg.InspectOpts.ListImages { imageList := []string{} for _, component := range p.cfg.Pkg.Components { imageList = append(imageList, component.Images...) diff --git a/src/test/e2e/31_checksum_and_signature_test.go b/src/test/e2e/31_checksum_and_signature_test.go index 011b7229d2..4cfba8afa3 100644 --- a/src/test/e2e/31_checksum_and_signature_test.go +++ b/src/test/e2e/31_checksum_and_signature_test.go @@ -27,6 +27,11 @@ func TestChecksumAndSignature(t *testing.T) { stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) + /* Test operations during package inspect */ + // Test that we can inspect the yaml of the package without the private key + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--insecure") + require.NoError(t, err, stdOut, stdErr) + /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", pkgName, "--confirm") From 8282473bf6276429d7f092dfc339a52ef31131b4 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:55:17 -0600 Subject: [PATCH 17/22] insecure to skip validaion signature Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/test/e2e/31_checksum_and_signature_test.go | 2 +- src/test/e2e/34_custom_init_package_test.go | 2 +- src/test/nightly/ecr_publish_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/31_checksum_and_signature_test.go b/src/test/e2e/31_checksum_and_signature_test.go index 4cfba8afa3..5e60466b91 100644 --- a/src/test/e2e/31_checksum_and_signature_test.go +++ b/src/test/e2e/31_checksum_and_signature_test.go @@ -29,7 +29,7 @@ func TestChecksumAndSignature(t *testing.T) { /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--insecure") + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--skip-signature-validation") require.NoError(t, err, stdOut, stdErr) /* Test operations during package deploy */ diff --git a/src/test/e2e/34_custom_init_package_test.go b/src/test/e2e/34_custom_init_package_test.go index 230eaca983..e3dbeeeeef 100644 --- a/src/test/e2e/34_custom_init_package_test.go +++ b/src/test/e2e/34_custom_init_package_test.go @@ -26,7 +26,7 @@ func TestCustomInit(t *testing.T) { /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--insecure") + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--skip-signature-validation") require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key diff --git a/src/test/nightly/ecr_publish_test.go b/src/test/nightly/ecr_publish_test.go index 37980ad7b1..f6d53cf470 100644 --- a/src/test/nightly/ecr_publish_test.go +++ b/src/test/nightly/ecr_publish_test.go @@ -71,7 +71,7 @@ func TestECRPublishing(t *testing.T) { // Ensure we get a warning when trying to inspect the package without providing the public key // and the insecure flag - stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName, "--insecure") + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName, "--skip-signature-validation") require.NoError(t, err, stdOut, stdErr) require.NotContains(t, stdErr, "Validating SBOM checksums") From 0ce03fd73486afeae07d15c8c09583531aad45ef Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:14:07 -0600 Subject: [PATCH 18/22] use load, skip valid Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 25 +++--------- src/internal/packager2/inspect.go | 49 +++++++++++++++--------- src/test/e2e/11_oci_pull_inspect_test.go | 2 +- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index 28404cd89e..6ce03458c6 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -194,27 +194,14 @@ var packageInspectCmd = &cobra.Command{ return err } - loadOpt := packager2.LoadOptions{ - Source: src, - Shasum: pkgConfig.PkgOpts.Shasum, - PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, - SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, - Filter: filters.Empty(), - } - - pkgPaths, err := packager2.LoadPackage(cmd.Context(), loadOpt) - if err != nil { - return err - } - defer os.RemoveAll(pkgPaths.Base) - cluster, _ := cluster.NewCluster() inspectOpt := packager2.ZarfInspectOptions{ - PackagePaths: pkgPaths, - Cluster: cluster, - ListImages: pkgConfig.InspectOpts.ListImages, - ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, - SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, + Source: src, + SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, + Cluster: cluster, + ListImages: pkgConfig.InspectOpts.ListImages, + ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, + SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, } if pkgConfig.InspectOpts.ListImages { diff --git a/src/internal/packager2/inspect.go b/src/internal/packager2/inspect.go index 17a39f7942..4545abe48e 100644 --- a/src/internal/packager2/inspect.go +++ b/src/internal/packager2/inspect.go @@ -12,28 +12,29 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/internal/packager/sbom" "github.com/zarf-dev/zarf/src/pkg/cluster" - "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/packager/filters" ) // ZarfInspectOptions tracks the user-defined preferences during a package inspection. type ZarfInspectOptions struct { - PackagePaths *layout.PackagePaths - Cluster *cluster.Cluster - ViewSBOM bool - SBOMOutputDir string - ListImages bool + Source string + Cluster *cluster.Cluster + ViewSBOM bool + SBOMOutputDir string + ListImages bool + SkipSignatureValidation bool } // Inspect list the contents of a package. -func Inspect(ctx context.Context, options ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { +func Inspect(ctx context.Context, opt ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { var err error - pkg, err := getPackageMetadata(ctx, options.PackagePaths) + pkg, err := getPackageMetadata(ctx, opt) if err != nil { return pkg, err } - if getSBOM(options.ViewSBOM, options.SBOMOutputDir) { - err = handleSBOMOptions(options.PackagePaths, pkg, options.ViewSBOM, options.SBOMOutputDir) + if getSBOM(opt.ViewSBOM, opt.SBOMOutputDir) { + err = handleSBOMOptions(ctx, pkg, opt) if err != nil { return pkg, err } @@ -43,9 +44,9 @@ func Inspect(ctx context.Context, options ZarfInspectOptions) (v1alpha1.ZarfPack } // InspectList lists the images in a component action -func InspectList(ctx context.Context, options ZarfInspectOptions) ([]string, error) { +func InspectList(ctx context.Context, opt ZarfInspectOptions) ([]string, error) { var imageList []string - pkg, err := getPackageMetadata(ctx, options.PackagePaths) + pkg, err := getPackageMetadata(ctx, opt) if err != nil { return nil, err } @@ -64,27 +65,37 @@ func InspectList(ctx context.Context, options ZarfInspectOptions) ([]string, err return imageList, err } -func getPackageMetadata(_ context.Context, layout *layout.PackagePaths) (v1alpha1.ZarfPackage, error) { - pkg, _, err := layout.ReadZarfYAML() +func getPackageMetadata(ctx context.Context, opt ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { + pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation) if err != nil { return pkg, err } + return pkg, nil } -func handleSBOMOptions(layout *layout.PackagePaths, pkg v1alpha1.ZarfPackage, viewSBOM bool, SBOMOutputDir string) error { - if SBOMOutputDir != "" { - out, err := layout.SBOMs.OutputSBOMFiles(SBOMOutputDir, pkg.Metadata.Name) +func handleSBOMOptions(ctx context.Context, pkg v1alpha1.ZarfPackage, opt ZarfInspectOptions) error { + loadOpt := LoadOptions{ + Source: opt.Source, + SkipSignatureValidation: opt.SkipSignatureValidation, + Filter: filters.Empty(), + } + layout, err := LoadPackage(ctx, loadOpt) + if err != nil { + return err + } + if opt.SBOMOutputDir != "" { + out, err := layout.SBOMs.OutputSBOMFiles(opt.SBOMOutputDir, pkg.Metadata.Name) if err != nil { return err } - if viewSBOM { + if opt.ViewSBOM { err := sbom.ViewSBOMFiles(out) if err != nil { return err } } - } else if viewSBOM { + } else if opt.ViewSBOM { err := sbom.ViewSBOMFiles(layout.SBOMs.Path) if err != nil { return err diff --git a/src/test/e2e/11_oci_pull_inspect_test.go b/src/test/e2e/11_oci_pull_inspect_test.go index 9a8189b0ab..b7d52fecec 100644 --- a/src/test/e2e/11_oci_pull_inspect_test.go +++ b/src/test/e2e/11_oci_pull_inspect_test.go @@ -70,7 +70,7 @@ func (suite *PullInspectTestSuite) Test_1_Remote_Inspect() { // Test inspect on a public package. // NOTE: This also makes sure that Zarf does not attempt auth when inspecting a public package. ref := fmt.Sprintf("oci://ghcr.io/zarf-dev/packages/dos-games:1.0.0-%s", e2e.Arch) - _, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", ref, "--insecure") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", ref, "--skip-signature-validation") suite.NoError(err, stdErr) } From c502bfa7c7a411b2d13d7620fb29e0d47902ba22 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:53:56 -0600 Subject: [PATCH 19/22] test w/ destroyed load Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/internal/packager2/load.go | 18 ++---------------- src/internal/packager2/load_test.go | 6 +++--- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/internal/packager2/load.go b/src/internal/packager2/load.go index 1b61c46c14..0f4f2f2fc2 100644 --- a/src/internal/packager2/load.go +++ b/src/internal/packager2/load.go @@ -239,20 +239,6 @@ func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, s } return depPkg.Data, nil } - - loadOpt := LoadOptions{ - Source: src, - SkipSignatureValidation: skipSignatureValidation, - Filter: filters.Empty(), - } - pkgPaths, err := LoadPackage(ctx, loadOpt) - if err != nil { - return v1alpha1.ZarfPackage{}, err - } - defer os.RemoveAll(pkgPaths.Base) - pkg, _, err := pkgPaths.ReadZarfYAML() - if err != nil { - return v1alpha1.ZarfPackage{}, err - } - return pkg, nil + //todo(schristoff): :/ + return v1alpha1.ZarfPackage{}, nil } diff --git a/src/internal/packager2/load_test.go b/src/internal/packager2/load_test.go index 208f68ba65..9cad0b4979 100644 --- a/src/internal/packager2/load_test.go +++ b/src/internal/packager2/load_test.go @@ -154,7 +154,7 @@ func TestPackageFromSourceOrCluster(t *testing.T) { } _, err = c.RecordPackageDeployment(ctx, pkg, nil, 1) require.NoError(t, err) - pkg, err = packageFromSourceOrCluster(ctx, c, "test", false) - require.NoError(t, err) - require.Equal(t, "test", pkg.Metadata.Name) + // pkg, err = packageFromSourceOrCluster(ctx, c, "test", false) + // require.NoError(t, err) + // require.Equal(t, "test", pkg.Metadata.Name) } From 0fbab7d76a7a266a9934659e3ec56d564c48177b Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:28:40 -0600 Subject: [PATCH 20/22] it wasnt the destroyed load? This reverts commit c502bfa7c7a411b2d13d7620fb29e0d47902ba22. --- src/internal/packager2/load.go | 18 ++++++++++++++++-- src/internal/packager2/load_test.go | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/internal/packager2/load.go b/src/internal/packager2/load.go index 0f4f2f2fc2..1b61c46c14 100644 --- a/src/internal/packager2/load.go +++ b/src/internal/packager2/load.go @@ -239,6 +239,20 @@ func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, s } return depPkg.Data, nil } - //todo(schristoff): :/ - return v1alpha1.ZarfPackage{}, nil + + loadOpt := LoadOptions{ + Source: src, + SkipSignatureValidation: skipSignatureValidation, + Filter: filters.Empty(), + } + pkgPaths, err := LoadPackage(ctx, loadOpt) + if err != nil { + return v1alpha1.ZarfPackage{}, err + } + defer os.RemoveAll(pkgPaths.Base) + pkg, _, err := pkgPaths.ReadZarfYAML() + if err != nil { + return v1alpha1.ZarfPackage{}, err + } + return pkg, nil } diff --git a/src/internal/packager2/load_test.go b/src/internal/packager2/load_test.go index 9cad0b4979..208f68ba65 100644 --- a/src/internal/packager2/load_test.go +++ b/src/internal/packager2/load_test.go @@ -154,7 +154,7 @@ func TestPackageFromSourceOrCluster(t *testing.T) { } _, err = c.RecordPackageDeployment(ctx, pkg, nil, 1) require.NoError(t, err) - // pkg, err = packageFromSourceOrCluster(ctx, c, "test", false) - // require.NoError(t, err) - // require.Equal(t, "test", pkg.Metadata.Name) + pkg, err = packageFromSourceOrCluster(ctx, c, "test", false) + require.NoError(t, err) + require.Equal(t, "test", pkg.Metadata.Name) } From 6039d7cb8d84f560e19dbe273fed9b886e8cca8e Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:15:13 -0600 Subject: [PATCH 21/22] pass publickeypath everywhere Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 2 ++ src/internal/packager2/inspect.go | 4 +++- src/internal/packager2/load.go | 3 ++- src/internal/packager2/load_test.go | 6 +++--- src/internal/packager2/remove.go | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index 6ce03458c6..bd5a6f352c 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -202,6 +202,7 @@ var packageInspectCmd = &cobra.Command{ ListImages: pkgConfig.InspectOpts.ListImages, ViewSBOM: pkgConfig.InspectOpts.ViewSBOM, SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir, + PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, } if pkgConfig.InspectOpts.ListImages { @@ -293,6 +294,7 @@ var packageRemoveCmd = &cobra.Command{ Cluster: cluster, Filter: filter, SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, + PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, } err = packager2.Remove(cmd.Context(), removeOpt) if err != nil { diff --git a/src/internal/packager2/inspect.go b/src/internal/packager2/inspect.go index 4545abe48e..bfad933b3a 100644 --- a/src/internal/packager2/inspect.go +++ b/src/internal/packager2/inspect.go @@ -23,6 +23,7 @@ type ZarfInspectOptions struct { SBOMOutputDir string ListImages bool SkipSignatureValidation bool + PublicKeyPath string } // Inspect list the contents of a package. @@ -66,7 +67,7 @@ func InspectList(ctx context.Context, opt ZarfInspectOptions) ([]string, error) } func getPackageMetadata(ctx context.Context, opt ZarfInspectOptions) (v1alpha1.ZarfPackage, error) { - pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation) + pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation, opt.PublicKeyPath) if err != nil { return pkg, err } @@ -79,6 +80,7 @@ func handleSBOMOptions(ctx context.Context, pkg v1alpha1.ZarfPackage, opt ZarfIn Source: opt.Source, SkipSignatureValidation: opt.SkipSignatureValidation, Filter: filters.Empty(), + PublicKeyPath: opt.PublicKeyPath, } layout, err := LoadPackage(ctx, loadOpt) if err != nil { diff --git a/src/internal/packager2/load.go b/src/internal/packager2/load.go index 1b61c46c14..c17fcf24b5 100644 --- a/src/internal/packager2/load.go +++ b/src/internal/packager2/load.go @@ -227,7 +227,7 @@ func assembleSplitTar(src, tarPath string) error { return nil } -func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, src string, skipSignatureValidation bool) (v1alpha1.ZarfPackage, error) { +func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, src string, skipSignatureValidation bool, publicKeyPath string) (v1alpha1.ZarfPackage, error) { _, err := identifySource(src) if err != nil { if cluster == nil { @@ -244,6 +244,7 @@ func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, s Source: src, SkipSignatureValidation: skipSignatureValidation, Filter: filters.Empty(), + PublicKeyPath: publicKeyPath, } pkgPaths, err := LoadPackage(ctx, loadOpt) if err != nil { diff --git a/src/internal/packager2/load_test.go b/src/internal/packager2/load_test.go index 208f68ba65..4c09a12260 100644 --- a/src/internal/packager2/load_test.go +++ b/src/internal/packager2/load_test.go @@ -142,10 +142,10 @@ func TestPackageFromSourceOrCluster(t *testing.T) { ctx := testutil.TestContext(t) - _, err := packageFromSourceOrCluster(ctx, nil, "test", false) + _, err := packageFromSourceOrCluster(ctx, nil, "test", false, "") require.EqualError(t, err, "cannot get Zarf package from Kubernetes without configuration") - pkg, err := packageFromSourceOrCluster(ctx, nil, "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", false) + pkg, err := packageFromSourceOrCluster(ctx, nil, "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", false, "") require.NoError(t, err) require.Equal(t, "test", pkg.Metadata.Name) @@ -154,7 +154,7 @@ func TestPackageFromSourceOrCluster(t *testing.T) { } _, err = c.RecordPackageDeployment(ctx, pkg, nil, 1) require.NoError(t, err) - pkg, err = packageFromSourceOrCluster(ctx, c, "test", false) + pkg, err = packageFromSourceOrCluster(ctx, c, "test", false, "") require.NoError(t, err) require.Equal(t, "test", pkg.Metadata.Name) } diff --git a/src/internal/packager2/remove.go b/src/internal/packager2/remove.go index a68a41c112..e20382da2d 100644 --- a/src/internal/packager2/remove.go +++ b/src/internal/packager2/remove.go @@ -28,11 +28,12 @@ type RemoveOptions struct { Cluster *cluster.Cluster Filter filters.ComponentFilterStrategy SkipSignatureValidation bool + PublicKeyPath string } // Remove removes a package that was already deployed onto a cluster, uninstalling all installed helm charts. func Remove(ctx context.Context, opt RemoveOptions) error { - pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation) + pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation, opt.PublicKeyPath) if err != nil { return err } From 17ce03792c2785fc404268817f5ddfc106f11a89 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:34:02 -0600 Subject: [PATCH 22/22] remove identifyAndFallbackToClusterSource Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> --- src/cmd/package.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index bd5a6f352c..3ae1b0e2ff 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -30,7 +30,6 @@ import ( "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager" "github.com/zarf-dev/zarf/src/pkg/packager/filters" - "github.com/zarf-dev/zarf/src/pkg/packager/sources" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) @@ -399,22 +398,6 @@ func choosePackage(args []string) (string, error) { return path, nil } -// NOTE: If the source is identified nil is returned because packager will create the source if it is nil. -// If it can't be identified the cluster source is used causing packager to ignore the configured package source. -// Use of cluster package source is limited to a few functions which is why this is not the default behavior. -func identifyAndFallbackToClusterSource() (sources.PackageSource, error) { - identifiedSrc := sources.Identify(pkgConfig.PkgOpts.PackageSource) - if identifiedSrc == "" { - message.Debugf(lang.CmdPackageClusterSourceFallback, pkgConfig.PkgOpts.PackageSource) - src, err := sources.NewClusterSource(&pkgConfig.PkgOpts) - if err != nil { - return nil, fmt.Errorf("unable to identify source from %s: %w", pkgConfig.PkgOpts.PackageSource, err) - } - return src, nil - } - return nil, nil -} - func getPackageCompletionArgs(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { var pkgCandidates []string