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

CycloneDX SBOM in artifacts #24

Merged
merged 7 commits into from
May 7, 2024

Conversation

SebastianSchildt
Copy link
Contributor

@SebastianSchildt SebastianSchildt commented May 5, 2024

Ported and improved version of from eclipse/kuksa.val#756

Main change in generated artifacts:

Creates and includes CycloneDX Software Bill of Materials (SBOM) for the databroker. This helps with compliance using kuksa in a commercial context, and is generally also one of the accepted formats fulfilling EU CRA SBOM requirements

"Collateral improvements"

  • Unified the way databroker and cli is buit locally with Github action builds while retaining workflow parallelism (added parallel integration tests)
  • Using the canonical way to determine dash dependencies for Rust
  • Split the SBOM and license generation, now a CycloneDX SBOM input is required to collect license files. This step has been split out to a Python package in kuksa-common: https://github.com/eclipse-kuksa/kuksa-common/tree/main/sbom-tools , so it can later be reused for non-rust components as well
  • get rid of the createbom python code in this repo -> less code, better

@SebastianSchildt SebastianSchildt force-pushed the feature/cyclonedx-sbom branch 5 times, most recently from a308488 to 008d5c7 Compare May 5, 2024 07:28
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.57%. Comparing base (e628c46) to head (008d5c7).
Report is 13 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
- Coverage   48.61%   48.57%   -0.05%     
==========================================
  Files          31       31              
  Lines       10879    10866      -13     
==========================================
- Hits         5289     5278      -11     
+ Misses       5590     5588       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SebastianSchildt SebastianSchildt force-pushed the feature/cyclonedx-sbom branch 8 times, most recently from 14547da to d29f409 Compare May 5, 2024 13:30
@SebastianSchildt SebastianSchildt changed the title WIP: CycloneDX SBOM CycloneDX SBOM in artifacts May 5, 2024
@SebastianSchildt SebastianSchildt marked this pull request as ready for review May 5, 2024 13:50
@@ -126,26 +115,28 @@ jobs:
working-directory: ${{github.workspace}}/
run: |
which cross || cargo install cross
cargo install cargo-license cargo-cyclonedx
pip install "git+https://github.com/eclipse-kuksa/kuksa-common.git@6f3d7627760582d8ba83cc8a0f7449d00fffee84#subdirectory=sbom-tools"
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be a nice to long term ambition to publish "kuksa-sbom-tools" as pypi package ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. Or at least tag it. But for now, it being an internal tools that might still change, I think using hash is ok

Dockerfile-cli Outdated Show resolved Hide resolved
build-databroker-cli.sh Outdated Show resolved Hide resolved
build-databroker-cli.sh Outdated Show resolved Hide resolved
build-databroker.sh Outdated Show resolved Hide resolved
expressions:
# LLVM exception not relevant for the project, thus in situation
# like this we choose to use vanilla Apache-2.0 terms
"Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT": "Apache-2.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

@mikehaller - we discussed license curation some time ago, could be interesting to check if this curation file is considered by our internal scanning tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this could also be expressed in ORT, see the .ort curations (not migrated) in the old repository: https://github.com/eclipse/kuksa.val/blob/master/.ort.yml

But not sure what you ate trying to use internally. I remember, that ORT somehow did not allow generic (if A OR B always choose A) kind of rules, but instead it needed to be add for any identified package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I stand corrected. It CAN express general rules. Anyway, as you see there were a lot more "package specific" curations needed for some reason. But anyway, different topic maybe :D

@erikbosch
Copy link
Contributor

General comments:

  • The Dockerfiles contains some references to build-all-targets*, replace them with info on how to use the new files if you want to build locally
  • Shall we possibly give some info on how to build Docker containers locally in README?

I believe this change will break the https://github.com/boschglobal/kuksa-databroker/blob/feature/cyclonedx-sbom/.github/workflows/create_draft_release.yml. Hopefully not if we use latest kuksa-action dash version. Anyway, should better be tested.

Adding @lukasmittag and @argerus as reviewers, so that they are aware of the upcoming change and can protest, if needed

@SebastianSchildt
Copy link
Contributor Author

error: binary `cargo-license` already exists in destination
Add --force to overwrite
error: binary `cargo-cyclonedx` already exists in destination
Add --force to overwrite
     Summary Failed to install cargo-license, cargo-cyclonedx (see error(s) above).
error: some crates failed to install
Error: Process completed with exit code 101.

Could it possibly be that we use same cache key for databroker and databroker-cli? I will do some troubleshooting

No, but that is also not right.

As the message says the binaries are already installed (cached & restored) and trying to install them again will generate this error unless --force is added.

This doesn't happen for cargo cross, since it's only installed if the binary is missing with:

   which cross || cargo install cross

Interesting. I only did observe this with cross, thus I used the "which pattern" I found in the workflows here. I could use the same pattern for the other cargo tools, but question: Would we risk of running with "arbitrarily" old version for a long time, and once github throws cache suddenly get a new one?

Is there any way to always "upgrade" to a new stable version, if it exists? I think "--force" would always reinstall, that would work, but cost time...

@SebastianSchildt
Copy link
Contributor Author

Could it possibly be that we use same cache key for databroker and databroker-cli? I will do some troubleshooting

key: databroker-release-${{ matrix.platform.name }}-${{ hashFiles('**/Cargo.lock') }}

As @argerus said, that is not the root cause, but has been fixed meanwhile

@erikbosch
Copy link
Contributor

Could it possibly be that we use same cache key for databroker and databroker-cli? I will do some troubleshooting

No, but that is also not right.

As the message says the binaries are already installed (cached & restored) and trying to install them again will generate this error unless --force is added.

This doesn't happen for cargo cross, since it's only installed if the binary is missing with:

   which cross || cargo install cross

I got the impression that an error no longer shall be given upon reinstall based on the discussion in rust-lang/cargo#6727. When running cargo install locally I do not get any error when trying to install cargo-license even if it is already there

erik@debian6:~/kuksa-databroker$ cargo install cargo-license
    Updating crates.io index
     Ignored package `cargo-license v0.6.1` is already installed, use --force to override
erik@debian6:~/kuksa-databroker$ echo $?
0
erik@debian6:~/kuksa-databroker$ cargo install cargo-license
    Updating crates.io index
     Ignored package `cargo-license v0.6.1` is already installed, use --force to override
erik@debian6:~/kuksa-databroker$ echo $?
0

@SebastianSchildt SebastianSchildt marked this pull request as draft May 6, 2024 10:46
@erikbosch
Copy link
Contributor

I did some more tests on the cargo install issue. According to the links below --force shall not be needed. But it seems that we better should add two more files to the caching; ~/.cargo/.crates.toml and ~/.cargo/.crates2.json. With that https://github.com/boschglobal/kuksa-databroker/actions/workflows/create_draft_release.yml seems to work as expected.

  - uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          ~/.cargo/.crates.toml
          ~/.cargo/.crates2.json
          target/

References:

@SebastianSchildt
Copy link
Contributor Author

@erikbosch I just googled the same :D Will try. Still trying to move things....

@SebastianSchildt
Copy link
Contributor Author

Moved all the scripts now, and (hopefully) fixed the cargo install issues

@erikbosch I also moved the prepare_release.sh script and tried to "blindly" fix it, so please take a look it is doing, what you expect.

@SebastianSchildt SebastianSchildt marked this pull request as ready for review May 6, 2024 11:59
@SebastianSchildt SebastianSchildt marked this pull request as draft May 6, 2024 12:38
erikbosch
erikbosch previously approved these changes May 6, 2024
Copy link
Contributor

@erikbosch erikbosch left a comment

Choose a reason for hiding this comment

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

@SebastianSchildt
Copy link
Contributor Author

thanks for testing @erikbosch , will make some minor adjustments tomorrow, and maybe solve the target caching problem. I just think we really, really NEED correct(er), better standard compliant SBOMS, even though this now feels like refactoring whole build 🗡️ Well, as long as stuff gets better....

Signed-off-by: Sebastian Schildt <sebastian.schildt@de.bosch.com>
Signed-off-by: Sebastian Schildt <sebastian.schildt@de.bosch.com>
Copy link
Contributor

@erikbosch erikbosch left a comment

Choose a reason for hiding this comment

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

LGTM

The release script works, tested at https://github.com/boschglobal/kuksa-databroker/releases

working-directory: ${{github.workspace}}/
working-directory: ${{github.workspace}}
env:
KUKSA_DATABROKER_FEATURES: databroker/viss,databroker/tls
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any particular reason for specifying features using databroker/viss and databroker/tls instead of the more common short form viss and tls?



# Check if a certain feature set was requested
if [ -z "$KUKSA_DATABROKERCLI_FEATURES" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's more consistent to use *_DATABROKER_CLI_* as environment variable prefix as the name is databroker-cli and not databrokercli.

Suggested change
if [ -z "$KUKSA_DATABROKERCLI_FEATURES" ]; then
if [ -z "$KUKSA_DATABROKER_CLI_FEATURES" ]; then

Comment on lines 93 to 100
cargo install cargo-license cargo-cyclonedx
pip install "git+https://github.com/eclipse-kuksa/kuksa-common.git@6f3d7627760582d8ba83cc8a0f7449d00fffee84#subdirectory=sbom-tools"
- name: Build
working-directory: ${{github.workspace}}/
env:
KUKSA_DATABROKERCLI_SBOM: y
run: |
./build-databroker-cli.sh ${{ matrix.platform.name }}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if generating the SBOM was at least a separate step.. Currently, I don't know whether it's that or something with the compilation that is causing the prolonged build time.

This PR:
Build time - PR

Baseline:

Build time - Baseline

@SebastianSchildt SebastianSchildt marked this pull request as ready for review May 7, 2024 10:39
@SebastianSchildt
Copy link
Contributor Author

I would appreciate tif this to be merged now. This is quite large now, and the thing we NEED is sboms.

Nothing against optimising it further (maybe make tickets), but we should move forward so I (or someone) don't need to port over all this stuff again in some weeks

Copy link
Contributor

@erikbosch erikbosch left a comment

Choose a reason for hiding this comment

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

Good enough, lets follow up in other PRs if needed

@erikbosch erikbosch requested a review from argerus May 7, 2024 11:46
@erikbosch
Copy link
Contributor

Any objections to merging @argerus?

@SebastianSchildt - I approved but I believe you have to make sure that John approves or alternatively that you dismiss his review to be able to merge

Copy link
Contributor

@argerus argerus left a comment

Choose a reason for hiding this comment

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

I would appreciate tif this to be merged now. This is quite large now, and the thing we NEED is sboms.

Nothing against optimising it further (maybe make tickets), but we should move forward so I (or someone) don't need to port over all this stuff again in some weeks

Sure. But, as I understand it, we already generate a Software Bill Of Materials. This is a different (more correct?) way of doing it.

But it makes the compilation step take ~2x longer (?) which I think is not warranted. That should be restored in a different PR then I guess.

This PR:
Build time - PR

Baseline:
Build time - Baseline

@erikbosch erikbosch merged commit b8df0bf into eclipse-kuksa:main May 7, 2024
21 checks passed
@erikbosch erikbosch deleted the feature/cyclonedx-sbom branch May 8, 2024 06:07
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.

None yet

4 participants