Skip to content

Add platform generate subcommand that lazy-installs MikeBOM#247

Open
nchelluri wants to merge 6 commits into
mainfrom
nchelluri-sbom-generate
Open

Add platform generate subcommand that lazy-installs MikeBOM#247
nchelluri wants to merge 6 commits into
mainfrom
nchelluri-sbom-generate

Conversation

@nchelluri
Copy link
Copy Markdown
Contributor

kusari platform generate invokes mikebom sbom scan under the hood with defaults --offline and --output project.cdx.json. Either default can be overridden by passing the corresponding flag after -- (e.g. --output other.json, --offline=false).

MikeBOM is downloaded and verified on first use against SHA256 hashes embedded in pkg/mikebom/versions.go, cached at ~/.kusari/bin/mikebom-<version>, and exec'd. Anything after -- is passed verbatim as flags to sbom scan.

When --upload is set, the SBOM is uploaded to the Kusari platform after generation. All kusari platform upload flags except --file-path (derived from --output) are accepted on generate too; flag registration is shared via the new addUploadFlags helper.

KUSARI_MIKEBOM_BIN points at a pre-installed binary (air-gapped envs, local dev). KUSARI_NO_AUTO_INSTALL=1 fails instead of downloading.

scripts/bump-mikebom.sh regenerates versions.go from the upstream release's SHA256SUMS so the pinned version and hash table stay in lockstep.

kusari platform generate invokes "mikebom sbom scan" under the hood
with defaults "--offline" and "--output project.cdx.json". Either
default can be overridden by passing the corresponding flag after "--"
(e.g. "--output other.json", "--offline=false").

MikeBOM is downloaded and verified on first use against SHA256 hashes
embedded in pkg/mikebom/versions.go, cached at
~/.kusari/bin/mikebom-<version>, and exec'd. Anything after "--" is
passed verbatim as flags to "sbom scan".

When --upload is set, the SBOM is uploaded to the Kusari platform
after generation. All "kusari platform upload" flags except
--file-path (derived from --output) are accepted on generate too;
flag registration is shared via the new addUploadFlags helper.

KUSARI_MIKEBOM_BIN points at a pre-installed binary (air-gapped envs,
local dev). KUSARI_NO_AUTO_INSTALL=1 fails instead of downloading.

scripts/bump-mikebom.sh regenerates versions.go from the upstream
release's SHA256SUMS so the pinned version and hash table stay in
lockstep.
pxp928
pxp928 previously approved these changes May 21, 2026
Copy link
Copy Markdown
Member

@pxp928 pxp928 left a comment

Choose a reason for hiding this comment

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

LGTM

funnelfiasco
funnelfiasco previously approved these changes May 21, 2026
Copy link
Copy Markdown
Contributor

@funnelfiasco funnelfiasco left a comment

Choose a reason for hiding this comment

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

LGTM overall. lint is unhappy, but I'm not sure these are the worst things to have (although cleaning that up wouldn't be bad, either) Edit: the lint check is blocking, so I guess you'll have to clean that up first 😄

One thing with this approach is that we'll need to release a new CLI version every time there's a new MikeBOM version that we want to use. That's good for "avoid breaking changes", but it might be a little churn-y in the short term.

The other concern is that we don't seem to be removing unused MikeBOM binaries. This isn't a blocker. The binaries are small and we won't have more than a few over time, probably, but it's conceivable that eventually we'll be leaving a lot of unused files on disk

@nchelluri nchelluri dismissed stale reviews from funnelfiasco and pxp928 via 0ae29bf May 21, 2026 15:24
@nchelluri
Copy link
Copy Markdown
Contributor Author

One thing with this approach is that we'll need to release a new CLI version every time there's a new MikeBOM version that we want to use. That's good for "avoid breaking changes", but it might be a little churn-y in the short term.

Yup... this is intentional. It's got some tradeoffs as you mention, but I think it's good for now.

The other concern is that we don't seem to be removing unused MikeBOM binaries. This isn't a blocker. The binaries are small and we won't have more than a few over time, probably, but it's conceivable that eventually we'll be leaving a lot of unused files on disk

I think this is a good point, but agree it's not a blocker. We can add a cache cleaner at some point that deletes old binaries, maybe.

Also, I fixed the lint errors.

Comment thread pkg/mikebom/mikebom.go
if err != nil {
return "", err
}
resp, err := http.DefaultClient.Do(req)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should add a timeout here in case of any issues and the download hanging indefinitely in CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in f546b5f.

nchelluri added 4 commits May 22, 2026 10:32
viper holds one *pflag.Flag per key, so binding at init() time can
only satisfy whichever command's init runs last. With upload's flags
shared between 'platform upload' and 'platform generate --upload',
the loser's CLI flag values were silently dropped (or env/config
values were ignored entirely on the generate path).

Extract bindUploadFlagsToViper + loadUploadFromViper + a shared
uploadPreRun, and attach the PreRun to both commands. Each command
rebinds to its own flag instances and materializes env/config/CLI
values in correct precedence just before its RunE runs.

Incidental fix: the original upload PreRun was missing
'commit-sha' from its viper.GetString reads, so KUSARI_COMMIT_SHA /
.env values were dropped on the upload path too. Included now.
uploadStringVars and uploadBoolVars now map each viper key to its
backing variable pointer; bindUploadFlagsToViper and loadUploadFromViper
both iterate these maps. Adding a flag is a one-place change, and a
new TestLoadUploadFromViper guards against drift between the maps and
the package-level vars.
- Short-circuit uploadPreRun when --upload is false so the pure-generate
  path doesn't bind+load 17 viper keys it'll never use.
- Hide --openvex from 'platform generate' help; the flag was inherited
  from addUploadFlags but doesn't make sense for an SBOM (would hit
  repo.Upload's OpenVEX validation downstream with a confusing error).
- Factor the deprecated --component-name warning into a helper and
  call it from generate too, so config-sourced component-name values
  surface the same warning on both code paths.
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.

4 participants