-
-
Notifications
You must be signed in to change notification settings - Fork 968
fix(sbom): mix projectPath into deterministic UUID seed #15614
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
Changes from 4 commits
d6a80e0
462b2f8
4d1a78f
23f586d
1144b74
0453de0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,12 @@ shadowJarTask.configure { ShadowJar it -> | |
|
|
||
| it.exclude( | ||
| 'META-INF/DEPENDENCIES', // until we publish our own SBOM, this won't be correct so exclude | ||
| // This module does not apply org.apache.grails.buildsrc.sbom (it's an intermediate build | ||
| // artifact, not published). Without this exclude, shadow's first-wins merge picks one of | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont need such a long comment: this is an intermediate build, exclude conflicting filed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 1144b74 - shortened to a single inline note on the exclude line: |
||
| // the bundled transitive META-INF/sbom.json files (typically grails-shell-cli's), | ||
| // producing a fat jar whose SBOM describes the wrong module and shares its serialNumber | ||
| // with whichever sibling jar happens to win the merge - violating CycloneDX 1.6. | ||
| 'META-INF/sbom.json', | ||
| 'about.html' // restatement of the Eclipse Distribution License - Version 1.0 for jakarta | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | |
| import org.apache.grails.forge.buildlogic.shadowjar.GrailsGroovyExtensionTransformer | ||
| import org.apache.grails.forge.buildlogic.shadowjar.GrailsShadowLicenseTransform | ||
| import org.apache.grails.forge.buildlogic.shadowjar.GrailsShadowNoticeTransform | ||
| import org.cyclonedx.gradle.CyclonedxDirectTask | ||
|
|
||
| plugins { | ||
| id 'groovy' | ||
|
|
@@ -92,6 +93,16 @@ jarTask.configure { Jar it -> | |
| } | ||
| } | ||
|
|
||
| // The shadowJar merges multiple jars (including transitive ones from grails-shell-cli, grails-forge-cli, | ||
| // etc.) into a single fat jar. Each of those source jars carries its own META-INF/sbom.json published by | ||
| // the org.apache.grails.buildsrc.sbom convention plugin, and shadow's first-wins merge would otherwise | ||
| // pick a transitive sbom.json (typically grails-shell-cli's) and produce a fat jar whose SBOM describes | ||
| // the wrong module. We exclude any incoming META-INF/sbom.json during the merge and then re-introduce | ||
| // this project's own SBOM (whose serialNumber is project-path-seeded and unique). This keeps fat-jar | ||
| // packaging concerns local to this project rather than leaking shadow knowledge into the generic | ||
| // org.apache.grails.buildsrc.sbom plugin. See: https://cyclonedx.org/docs/1.6/json/#serialNumber | ||
| TaskProvider<CyclonedxDirectTask> cyclonedxDirectBomTask = tasks.named('cyclonedxDirectBom', CyclonedxDirectTask) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this into the configure since it doesn't appear to be used outside of it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 1144b74 - moved the cyclonedxDirectBomTask declaration inside the shadowJarTask.configure { ... } block (and inside the skipJavaComponent guard, since that is its only caller). |
||
|
|
||
| TaskProvider<Jar> shadowJarTask = tasks.named('shadowJar', ShadowJar) | ||
| shadowJarTask.configure { ShadowJar it -> | ||
| it.archiveClassifier = 'all' | ||
|
|
@@ -122,8 +133,27 @@ shadowJarTask.configure { ShadowJar it -> | |
| 'META-INF/DEPENDENCIES', // until we publish our own SBOM, this won't be correct so exclude | ||
| 'META-INF/grails-plugin.xml', // we do not start or compile a grails application so these files are not needed (grails-core, url mappings, etc plugins) | ||
| 'META-INF/grails-plugin.xml.asc', // avoid signing artifacts | ||
| // Drop any incoming sbom.json that arrives via transitive jars during the shadow merge; | ||
| // re-introduced below from this project's own cyclonedxDirectBom output. | ||
| 'META-INF/sbom.json', | ||
| 'about.html' // restatement of the Eclipse Distribution License - Version 1.0 for jakarta | ||
| ) | ||
|
|
||
| // Re-introduce this project's own SBOM after the merge (mirrors the regular jar wiring done by | ||
| // the org.apache.grails.buildsrc.sbom plugin). Mirrored only when skipJavaComponent is unset to | ||
| // match the convention used elsewhere in the build for projects that opt out of jar publication. | ||
| if (!project.findProperty('skipJavaComponent')) { | ||
| it.from(cyclonedxDirectBomTask.flatMap { CyclonedxDirectTask t -> t.jsonOutput }) { CopySpec spec -> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flatMap is non lazy; isnt the json output the only output? If so just pass the task here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 1144b74 - swapped to passing the task provider directly:
Verified (Minor nit on the original phrasing: |
||
| spec.into('META-INF') | ||
| spec.rename { | ||
| 'sbom.json' | ||
| } | ||
| } | ||
| it.manifest { Manifest manifest -> | ||
| manifest.attributes('Sbom-Location': 'META-INF/sbom.json') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this added by the cyclonedx plugin already? Did you check the manifest files? Do we do this anywhere else?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked all three:
Left the manifest block in place; the entries are validated to appear in the output. |
||
| manifest.attributes('Sbom-Format': 'CycloneDX') | ||
| } | ||
| } | ||
| } | ||
| // Make shadow jar a direct dependency of assemble instead of using deprecated archives configuration | ||
| tasks.named('assemble').configure { | ||
|
|
||
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.
We should restore the original comment and remove this verbosity
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.
Done in 1144b74 - restored the original one-line // sboms are only published to Grails jar files at this time comment. Now that the shadow-jar wiring lives entirely in grails-cli/build.gradle, the verbose explanation in the generic plugin is unnecessary.