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

Adjustments for Lifecycle version 0.13.3 #115

Merged
merged 2 commits into from Feb 2, 2022
Merged

Adjustments for Lifecycle version 0.13.3 #115

merged 2 commits into from Feb 2, 2022

Conversation

dmikusa
Copy link
Contributor

@dmikusa dmikusa commented Jan 31, 2022

Starting with lifecycle 0.13.3, it is permitted to have both the old style label-based BOM information and the new style layer-based BOM information. If the buildpack API is 0.6 or older, label-based BOMs only are OK. If the buildpack API is 0.7, you may have both label-based BOM and layer-based BOM or just layer-based BOM. It is permitted to have just label-based BOM, however, that will generate a warning from the lifecycle.

This PR makes two changes:

  1. It removes two checks that we were using to nil out the label-based BOM and WARN if it was set. This is OK now based on the lifecycle changes so we permit it.
  2. It adds BP_DISABLE_BOM_LABEL which can be used to manually disable the label-based BOM. This is for the case where the label is too large and causes problems with K8s. This defaults to false, so label-based BOM is enabled by default. Setting it to true will result in no label-based BOM being included, even if the buildpacks write that information.

Starting with lifecycle 0.13.3, it is permitted to have both the old style label-based BOM information and the new style layer-based BOM information. If the buildpack API is 0.6 or older, label-based BOMs only is OK. If the buildpack API is 0.7, you may have both label-based BOM and layer-based BOM or just layer-based BOM. It is permitted to have just label-based BOM, however, that will generate a warning from the lifecycle.

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
@dmikusa dmikusa added semver:patch A change requiring a patch version bump type:task A general task labels Jan 31, 2022
build.go Outdated
@@ -313,9 +314,18 @@ func Build(builder Builder, options ...Option) {
}
}

var disableBOMLabel bool
if val, ok := os.LookupEnv("BP_DISABLE_BOM_LABEL"); ok {
Copy link
Member

Choose a reason for hiding this comment

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

@dmikusa-pivotal I think the usage of this env var might be buildpacks/platform specific. I would prefer it if we didn't introduce it in libcnb and just relied on the buildpack to toggle this logic. This might be better placed in libpak for eg. LMK what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not opposed to having a different trigger, but I feel pretty strongly that we should allow for the disabling of the label-based BOM entries. It's known to cause problems.

I went with an env variable because there is some precedent with BP_DEBUG and BP_LOG_LEVEL which are also in libcnb.

Other options that come to mind:

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly about this but in general I agree with @samj1912 that libcnb should avoid being prescriptive about the user->buildpack interface and this might be better in libpack

Copy link
Member

Choose a reason for hiding this comment

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

@dmikusa-pivotal I think the difference between those log level env vars and the SBOM env var is that the log level env var influences the log lines that the build process outputs which cannot be controlled by the users of libcnb (for eg

libcnb/build.go

Line 179 in d3e6e18

logger.Debugf("Layers: %+v", ctx.Layers)
) I think in this case, a buildpack using libcnb can just detect this env var and not choose to populate the bom in launch.toml/build.toml

I am concerned because I would like that env var to be set to a value so that labels are turned off by default completely and I imagine paketo might want something else. Given that we are venturing into buildpack author level opinions on configuration that is exposed to the end user(app dev) I think we should avoid introducing this in libcnb.

I might be fine with introducing this in a way that is exposed to the buildpack author and not an end user (i.e. not an env var)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ , I get where you're coming from.

I removed the env variable, added an option that a buildpack author can set when running libcnb.Build, set this to default to false (i.e. don't write the BOM label).

Let me know what you think.

@ekcasey
Copy link
Member

ekcasey commented Feb 1, 2022

Not strictly related to this PR but it looks like libcnb is providing a helpers to create layer-specific SBOMs but not for generic launch and build SBOMs. Seem like we should probably do both? cc @dmikusa-pivotal @samj1912

@samj1912
Copy link
Member

samj1912 commented Feb 1, 2022

@ekcasey we do have those as well ->

libcnb/layer.go

Lines 216 to 223 in d3e6e18

func (l Layers) BuildSBOMPath(bt SBOMFormat) string {
return filepath.Join(l.Path, fmt.Sprintf("build.sbom.%s", bt))
}
// BOMLaunchPath returns the full path to the launch SBoM file for the buildpack
func (l Layers) LaunchSBOMPath(bt SBOMFormat) string {
return filepath.Join(l.Path, fmt.Sprintf("launch.sbom.%s", bt))
}

In some environments and with some applications, a long enough BOM label may be generated that it will either break Kubernetes or cause your application to fail to start. With the changes in lifecycle 0.13.3, we are enabling the BOM label again, but due to the issue above we also need a way for users to disable it if there are problems.

When running `libcnb.Build` you may now include an `Option` of `WithBOMLabel` that has an argument of either true or false. If not set, it defaults to false. This controls the output of libcnb.BOMEntry items in `launch.toml` and `build.toml`. If true, BOM entries are written. If false, BOM entries are not written, even if they are returned by the buildpack.

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
@@ -122,6 +122,7 @@ type Builder interface {
func Build(builder Builder, options ...Option) {
config := Config{
arguments: os.Args,
bomLabel: false,
Copy link
Member

Choose a reason for hiding this comment

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

Should we instead just call this allowDeprecated ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO, that's not specific enough. There could be other deprecated things to allow.

I'd be OK with allowDeprecatedBOMLabel and WithDeprecatedBOMLabel. I can make that change and resubmit in the morning if you're Ok with that.

For what it's worth, I did flag WithBOMLabel as deprecated, so if it's used it'll show up as deprecated in your IDE. Is that sufficient? or would you still prefer it in the variable name?

@samj1912
Copy link
Member

samj1912 commented Feb 2, 2022

@dmikusa-pivotal merging this for now. Was just a nitpick on the naming side. Hopefully we are getting rid of v1 soon anyway.

@samj1912 samj1912 merged commit 6a941db into buildpacks:main Feb 2, 2022
@dmikusa dmikusa deleted the lifecycle_0_13_3 branch March 5, 2022 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:patch A change requiring a patch version bump type:task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants