-
Notifications
You must be signed in to change notification settings - Fork 0
add MSI Windows installer support #45
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c1c8c9f
feat: add MSI Windows installer support
gontzess e8e4bc2
fix: address PR review feedback for MSI support
gontzess e371c0e
temp: add MSI install verification step (remove before merge)
gontzess 13ed935
remove temporary MSI install test step
gontzess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "google.golang.org/protobuf/encoding/protojson" | ||
|
|
||
| pb "github.com/ConductorOne/github-workflows/pb/artifacts/v1" | ||
| ) | ||
|
|
||
| const ( | ||
| // AttestationTypeInTotoV1 is the in-toto Statement v1 envelope type | ||
| AttestationTypeInTotoV1 = "https://in-toto.io/Statement/v1" | ||
| // PredicateTypeSLSAProvenanceV1 is the SLSA v1 provenance predicate type | ||
| PredicateTypeSLSAProvenanceV1 = "https://slsa.dev/provenance/v1" | ||
| // PredicateTypeSPDX is the SPDX SBOM predicate type | ||
| PredicateTypeSPDX = "https://spdx.dev/Document" | ||
| ) | ||
|
|
||
| func main() { | ||
| var ( | ||
| distDir string | ||
| cdnBaseURL string | ||
| s3Dir string | ||
| ) | ||
| flag.StringVar(&distDir, "dist-dir", "", "Path to the dist directory containing Windows artifacts") | ||
| flag.StringVar(&cdnBaseURL, "cdn-base-url", "", "CDN base URL for artifact links") | ||
| flag.StringVar(&s3Dir, "s3-directory", "", "S3 directory path for artifacts") | ||
| flag.Parse() | ||
|
|
||
| if distDir == "" || cdnBaseURL == "" || s3Dir == "" { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error: all flags are required\n") | ||
| fmt.Fprintf(os.Stderr, "Usage: generate-windows-manifest -dist-dir <path> -cdn-base-url <url> -s3-directory <dir>\n") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Defense-in-depth: reject path traversal in S3 directory. | ||
| // The workflow's semver validation already prevents this, but validate here too. | ||
| if strings.Contains(s3Dir, "..") { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error: s3-directory must not contain '..': %s\n", s3Dir) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| baseURL := fmt.Sprintf("%s/%s", cdnBaseURL, s3Dir) | ||
| assets := make(map[string]*pb.Asset) | ||
|
|
||
| // Find and process zip files | ||
| zipFiles, err := filepath.Glob(filepath.Join(distDir, "*.zip")) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error finding zip files: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| for _, zipPath := range zipFiles { | ||
| filename := filepath.Base(zipPath) | ||
| if strings.Contains(filename, "checksums") { | ||
| continue | ||
| } | ||
|
|
||
| asset, err := buildAsset(zipPath, filename, "application/zip", baseURL, distDir) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error processing %s: %v\n", filename, err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Windows zip uses key "windows-amd64" | ||
| assets["windows-amd64"] = asset | ||
| fmt.Fprintf(os.Stderr, "✅ Added zip asset: windows-amd64 -> %s\n", filename) | ||
| } | ||
|
|
||
| // Find and process MSI files (flattened to dist root by workflow) | ||
| msiFiles, err := filepath.Glob(filepath.Join(distDir, "*.msi")) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error finding MSI files: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| for _, msiPath := range msiFiles { | ||
| filename := filepath.Base(msiPath) | ||
|
|
||
| asset, err := buildAsset(msiPath, filename, "application/x-msi", baseURL, distDir) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error processing %s: %v\n", filename, err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // MSI uses key "windows-amd64-msi" | ||
| // MSI has cosign signatures and attestations; Azure Trusted Signing (Windows code signing) planned for Stage 2 | ||
| assets["windows-amd64-msi"] = asset | ||
| fmt.Fprintf(os.Stderr, "✅ Added MSI asset: windows-amd64-msi -> %s\n", filename) | ||
| } | ||
|
|
||
| // Marshal assets map to JSON | ||
| // We need to output a map[string]Asset JSON, not a full manifest | ||
| output := make(map[string]json.RawMessage) | ||
| marshalOpts := protojson.MarshalOptions{ | ||
| EmitUnpopulated: true, | ||
| } | ||
|
|
||
| for key, asset := range assets { | ||
| jsonBytes, err := marshalOpts.Marshal(asset) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error marshaling asset %s: %v\n", key, err) | ||
| os.Exit(1) | ||
| } | ||
| output[key] = jsonBytes | ||
| } | ||
|
|
||
| // Output JSON to stdout | ||
| outputBytes, err := json.Marshal(output) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "generate-windows-manifest: error marshaling output: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Println(string(outputBytes)) | ||
| fmt.Fprintf(os.Stderr, "✅ Generated Windows manifest with %d assets\n", len(assets)) | ||
| } | ||
|
|
||
| func buildAsset(filePath, filename, mediaType, baseURL, distDir string) (*pb.Asset, error) { | ||
| // Calculate SHA256 | ||
| hash, err := sha256File(filePath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("calculating hash: %w", err) | ||
| } | ||
|
|
||
| // Get file size | ||
| info, err := os.Stat(filePath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("getting file info: %w", err) | ||
| } | ||
|
|
||
| sizeBytes := info.Size() | ||
| href := fmt.Sprintf("%s/%s", baseURL, filename) | ||
|
|
||
| // Check for signature and certificate files (all in dist root after flatten step) | ||
| var signatureHref, certificateHref *string | ||
| sigPath := filepath.Join(distDir, filename+".sig") | ||
| if _, err := os.Stat(sigPath); err == nil { | ||
| s := fmt.Sprintf("%s/%s.sig", baseURL, filename) | ||
| signatureHref = &s | ||
| } | ||
| certPath := filepath.Join(distDir, filename+".cert") | ||
| if _, err := os.Stat(certPath); err == nil { | ||
| c := fmt.Sprintf("%s/%s.cert", baseURL, filename) | ||
| certificateHref = &c | ||
| } | ||
|
|
||
| // Build attestations array | ||
| var attestations []*pb.AttestationDescriptor | ||
|
|
||
| // Check for provenance attestation | ||
| provenancePath := filepath.Join(distDir, filename+".provenance.sigstore.json") | ||
| if _, err := os.Stat(provenancePath); err == nil { | ||
| attestationType := AttestationTypeInTotoV1 | ||
| predicateType := PredicateTypeSLSAProvenanceV1 | ||
| bundleHref := fmt.Sprintf("%s/%s.provenance.sigstore.json", baseURL, filename) | ||
| attestations = append(attestations, pb.AttestationDescriptor_builder{ | ||
| AttestationType: &attestationType, | ||
| PredicateType: &predicateType, | ||
| BundleHref: &bundleHref, | ||
| }.Build()) | ||
| } | ||
|
|
||
| // Check for SBOM attestation | ||
| sbomPath := filepath.Join(distDir, filename+".sbom.sigstore.json") | ||
| if _, err := os.Stat(sbomPath); err == nil { | ||
| attestationType := AttestationTypeInTotoV1 | ||
| predicateType := PredicateTypeSPDX | ||
| bundleHref := fmt.Sprintf("%s/%s.sbom.sigstore.json", baseURL, filename) | ||
| attestations = append(attestations, pb.AttestationDescriptor_builder{ | ||
| AttestationType: &attestationType, | ||
| PredicateType: &predicateType, | ||
| BundleHref: &bundleHref, | ||
| }.Build()) | ||
| } | ||
|
|
||
| return pb.Asset_builder{ | ||
| Filename: &filename, | ||
| MediaType: &mediaType, | ||
| SizeBytes: &sizeBytes, | ||
| Sha256: &hash, | ||
| Href: &href, | ||
| SignatureHref: signatureHref, | ||
| CertificateHref: certificateHref, | ||
| Attestations: attestations, | ||
| }.Build(), nil | ||
| } | ||
|
|
||
| func sha256File(path string) (string, error) { | ||
| f, err := os.Open(path) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| defer f.Close() | ||
|
|
||
| h := sha256.New() | ||
| if _, err := io.Copy(h, f); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return hex.EncodeToString(h.Sum(nil)), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I wonder if someone could add ~ "../../okta" to a tag to get a build into the wrong bucket.
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.
The tag is already validated by strict semver regex at line 76 in the release.yaml file. The character class [0-9a-zA-Z-] doesn't allow / or . in positions that could form .., so ../../okta is impossible as a tag.
But we can add another check here to be safe, incase that other file ever gets changed.