-
Notifications
You must be signed in to change notification settings - Fork 173
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
fix: check public key for signed packages during zarf package pull #3347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,19 @@ package test | |
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/zarf-dev/zarf/src/test/testutil" | ||
"oras.land/oras-go/v2/registry" | ||
) | ||
|
||
type PullInspectTestSuite struct { | ||
suite.Suite | ||
*require.Assertions | ||
Reference registry.Reference | ||
PackagesDir string | ||
Reference registry.Reference | ||
} | ||
|
||
var badPullInspectRef = registry.Reference{ | ||
|
@@ -28,34 +29,38 @@ var badPullInspectRef = registry.Reference{ | |
|
||
func (suite *PullInspectTestSuite) SetupSuite() { | ||
suite.Assertions = require.New(suite.T()) | ||
suite.PackagesDir = "build" | ||
} | ||
|
||
func (suite *PullInspectTestSuite) TearDownSuite() { | ||
local := fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch) | ||
e2e.CleanFiles(suite.T(), local) | ||
suite.Reference.Registry = testutil.SetupInMemoryRegistry(testutil.TestContext(suite.T()), suite.T(), 31888) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's very useful for unit tests as well, once the create refactor is merged, we should be able to make tests for publish and pull with unit tests |
||
} | ||
|
||
func (suite *PullInspectTestSuite) Test_0_Pull() { | ||
suite.T().Log("E2E: Package Pull oci://") | ||
|
||
out := fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch) | ||
privateKeyFlag := "--signing-key=src/test/packages/zarf-test.prv-key" | ||
publicKeyFlag := "--key=src/test/packages/zarf-test.pub" | ||
|
||
// Build the fully qualified reference. | ||
ref := fmt.Sprintf("oci://ghcr.io/zarf-dev/packages/dos-games:1.0.0-%s", e2e.Arch) | ||
outputPath := suite.T().TempDir() | ||
stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "create", "src/test/packages/11-simple-package", "-o", outputPath, privateKeyFlag, "--confirm") | ||
suite.NoError(err, stdOut, stdErr) | ||
|
||
// Pull the package via OCI. | ||
stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "pull", ref) | ||
out := filepath.Join(outputPath, fmt.Sprintf("zarf-package-simple-package-%s-0.0.1.tar.zst", e2e.Arch)) | ||
ref := suite.Reference.String() | ||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "publish", out, "oci://"+ref, "--plain-http", publicKeyFlag) | ||
suite.NoError(err, stdOut, stdErr) | ||
|
||
sbomTmp := suite.T().TempDir() | ||
simplePackageRef := fmt.Sprintf("oci://%s/simple-package:0.0.1", ref) | ||
// fail to pull the package without providing the public key | ||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "pull", simplePackageRef, "--plain-http") | ||
suite.Error(err, stdOut, stdErr) | ||
|
||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "pull", simplePackageRef, "--plain-http", publicKeyFlag) | ||
suite.NoError(err, stdOut, stdErr) | ||
|
||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", simplePackageRef, "--plain-http") | ||
suite.Error(err, stdOut, stdErr) | ||
|
||
// Verify the package was pulled correctly. | ||
suite.FileExists(out) | ||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", out, "--key", "https://raw.githubusercontent.com/zarf-dev/zarf/v0.38.2/cosign.pub", "--sbom-out", sbomTmp) | ||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", simplePackageRef, "--plain-http", publicKeyFlag, "--sbom-out", suite.T().TempDir()) | ||
suite.NoError(err, stdOut, stdErr) | ||
|
||
// Test pull w/ bad ref. | ||
stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+badPullInspectRef.String(), "--plain-http") | ||
suite.Error(err, stdOut, stdErr) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: simple-package | ||
description: simple small package to test pullling, publishing, and inspecting | ||
version: 0.0.1 | ||
|
||
components: | ||
- name: on-deploy-with-template-use-of-variable | ||
required: true | ||
files: | ||
- source: test.txt | ||
target: test.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored this test to create and publish the package to an in memory registry, this way we don't rely on external private keys or external infrastructure. Added a test to ensure pulling the package without a public key fails and verified that it does fail on main.