Skip to content
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 SBOM generation inconsistency, take 2 #66

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/gok/overwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func init() {
}

func (r *overwriteImplConfig) run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
fileCfg, err := config.ReadFromFile()
if err != nil {
return err
}

cfg, err := config.ReadFromFile()
if err != nil {
return err
Expand Down Expand Up @@ -121,8 +126,9 @@ func (r *overwriteImplConfig) run(ctx context.Context, args []string, stdout, st
}

pack := &packer.Pack{
Cfg: cfg,
Output: &output,
FileCfg: fileCfg,
Cfg: cfg,
Output: &output,
}

pack.Main("gokrazy gok")
Expand Down
5 changes: 5 additions & 0 deletions internal/gok/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (r *sbomConfig) run(ctx context.Context, args []string, stdout, stderr io.W

updateflag.SetUpdate("yes")

// GenerateSBOM() must be provided with a cfg
// that hasn't been modified by gok at runtime,
// as the SBOM should reflect what’s going into gokrazy,
// not its internal implementation details
// (i.e. cfg.InternalCompatibilityFlags untouched).
sbomMarshaled, sbomWithHash, err := packer.GenerateSBOM(cfg)
if os.IsNotExist(err) {
// Common case, handle with a good error message
Expand Down
8 changes: 7 additions & 1 deletion internal/gok/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func init() {
}

func (r *updateImplConfig) run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
fileCfg, err := config.ReadFromFile()
if err != nil {
return err
}

cfg, err := config.ReadFromFile()
if err != nil {
return err
Expand Down Expand Up @@ -77,7 +82,8 @@ func (r *updateImplConfig) run(ctx context.Context, args []string, stdout, stder
}

pack := &packer.Pack{
Cfg: cfg,
FileCfg: fileCfg,
Cfg: cfg,
}

pack.Main("gokrazy gok")
Expand Down
3 changes: 2 additions & 1 deletion internal/oldpacker/oldpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func logic(instanceDir string) error {
}

pack := &internalpacker.Pack{
Cfg: &cfg,
FileCfg: &cfg,
Cfg: &cfg,
}

pack.Main("gokrazy packer")
Expand Down
7 changes: 6 additions & 1 deletion internal/packer/gaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func (p *Pack) overwriteGaf(root *FileInfo) error {
return err
}

sbomMarshaled, _, err := GenerateSBOM(p.Cfg)
// GenerateSBOM() must be provided with a cfg
// that hasn't been modified by gok at runtime,
// as the SBOM should reflect what’s going into gokrazy,
// not its internal implementation details
// (i.e. cfg.InternalCompatibilityFlags untouched).
sbomMarshaled, _, err := GenerateSBOM(p.FileCfg)
if err != nil {
return err
}
Expand Down
15 changes: 12 additions & 3 deletions internal/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,11 @@ type OutputStruct struct {
type Pack struct {
packer.Pack

Cfg *config.Struct
Output *OutputStruct
// FileCfg holds an untouched copy
// of the config file, as it was read from disk.
FileCfg *config.Struct
Cfg *config.Struct
Output *OutputStruct
}

func filterGoEnv(env []string) []string {
Expand Down Expand Up @@ -1366,10 +1369,16 @@ func (pack *Pack) logic(programName string) error {
FromLiteral: update.HTTPSPort,
})

sbom, _, err := GenerateSBOM(cfg)
// GenerateSBOM() must be provided with a cfg
// that hasn't been modified by gok at runtime,
// as the SBOM should reflect what’s going into gokrazy,
// not its internal implementation details
// (i.e. cfg.InternalCompatibilityFlags untouched).
sbom, _, err := GenerateSBOM(pack.FileCfg)
if err != nil {
return err
}

etcGokrazy := &FileInfo{Filename: "gokrazy"}
etcGokrazy.Dirents = append(etcGokrazy.Dirents, &FileInfo{
Filename: "sbom.json",
Expand Down
4 changes: 4 additions & 0 deletions internal/packer/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type SBOMWithHash struct {

// GenerateSBOM generates a Software Bills Of Material (SBOM) for the
// local gokrazy instance.
// It must be provided with a cfg that hasn't been modified by gok at runtime,
// as the SBOM should reflect what’s going into gokrazy,
// not its internal implementation details
// (i.e. cfg.InternalCompatibilityFlags untouched).
func GenerateSBOM(cfg *config.Struct) ([]byte, SBOMWithHash, error) {
wd, err := os.Getwd()
if err != nil {
Expand Down