Skip to content

feat: accept version flag for zarf tools download-init #3568

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

Merged
merged 6 commits into from
Mar 14, 2025

Conversation

jbrewer3
Copy link
Contributor

@jbrewer3 jbrewer3 commented Mar 11, 2025

Description

Updates to allow downloading of versioned zarf init packages
...

Related Issue

Fixes #3366

Checklist before merging

Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit c0e2a43
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/67d2ef0243c03c00084f6d1b

Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cmd/zarf_tools.go 9.09% 10 Missing ⚠️
Files with missing lines Coverage Δ
src/cmd/zarf_tools.go 35.28% <9.09%> (-0.71%) ⬇️
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Josh Brewer <[email protected]>
@jbrewer3 jbrewer3 marked this pull request as ready for review March 12, 2025 14:30
@jbrewer3 jbrewer3 requested review from a team as code owners March 12, 2025 14:30
@brandtkeller
Copy link
Member

make docs-and-schema should fix the error - otherwise this looks functional from my local testing.

Signed-off-by: Josh Brewer <[email protected]>
Copy link
Member

@brandtkeller brandtkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a neat capability to the download-init command that many may find useful.

Given the parameters remained the same - I could not find an attack vector that this change might enable.

Arbitrary strings are validated by the OCI logic - if the tag doesn't exist the logs indicate as such. That does not mean there isn't potential for misuse.

Anytime we introduce accepting input from the user - I would prefer we perform input validation. In src/pkg/zoci/utils.go this might look something like:

// GetInitPackageURL returns the URL for the init package for the given version with strict validation.
func GetInitPackageURL(version string) (string, error) {
    // Strict SemVer validation (vMAJOR.MINOR.PATCH with optional pre-release and metadata)
    var validVersion = regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-zA-Z0-9._-]+)?(\+[a-zA-Z0-9._-]+)?$`)

    if !validVersion.MatchString(version) {
        return "", fmt.Errorf("invalid version: must follow SemVer and start with 'v' (e.g., v0.50.0)")
    }

    return fmt.Sprintf("ghcr.io/zarf-dev/packages/init:%s", version), nil
}

This would prevent any unnecessary network calls and provide more explicit errors.

Open to feedback from other maintainers as well.

@AustinAbro321
Copy link
Contributor

@brandtkeller I like that suggestion, and I think it could be made even simpler by using the semver package we already use in Zarf

ver, err := semver.NewVersion(config.CLIVersion)
if err != nil {
  return fmt.Errorf("invalid version %s: %w", version, err)
}

@jbrewer3 jbrewer3 requested a review from brandtkeller March 13, 2025 14:43
@AustinAbro321 AustinAbro321 changed the title initial commit for version flag in download init feat: accept version flag for zarf tools download-init Mar 13, 2025
Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brandtkeller brandtkeller added this pull request to the merge queue Mar 14, 2025
Merged via the queue into zarf-dev:main with commit 340512c Mar 14, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow zarf tools download-init to download a specific zarf version
3 participants