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

SBOM file generation. #312

Merged
merged 1 commit into from
Aug 31, 2022
Merged

SBOM file generation. #312

merged 1 commit into from
Aug 31, 2022

Conversation

jvanz
Copy link
Member

@jvanz jvanz commented Aug 25, 2022

Adds new steps in the build and release workflow to generate, sign and publish a SBOM file for Policy Server.

Fix #305

@jvanz jvanz self-assigned this Aug 25, 2022
@jvanz jvanz requested a review from a team as a code owner August 25, 2022 17:15
Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

Looks good!
I like how the signing of the artifacts happens in the same job as the build, and the release job just consumes the signed artifacts already.

I wonder though, if we could keep the release job in the .github/workflows/release.yml workflow file. I feel it's clearer to set everything in one file with:

on:
  push:
    tags:
    - 'v*'

and not use if: github.ref_type == 'tag'.

I wonder also if by having it in a different workflow, it's more easy to find the release job in the github pop-ups of commits and so.

@jvanz jvanz force-pushed the main branch 4 times, most recently from cdfb145 to ed2044a Compare August 29, 2022 17:34
@jvanz
Copy link
Member Author

jvanz commented Aug 29, 2022

@viccuad , in order to have a more complete SBOM file, the tool needs access to the files generated by the build. Thus, the release workflow needs to have access to the target directory. That's the reason I've merged the release worflows into a single file. I can split it again and call the same worflows to build the binaries in both workflows (ci and release). Do you prefer that? One cons of this approach is that the build will run twice when a tag is released. What do you think?

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@jvanz jvanz force-pushed the main branch 18 times, most recently from 5172ba1 to 31d194b Compare August 30, 2022 14:41
@jvanz
Copy link
Member Author

jvanz commented Aug 30, 2022

I don't understand if the final SPDX file will contain a list of all the dependencies of the policy-server binary (basically the contents of Cargo.lock).

As far as I could understand reading the spdx specification the file contains anything used to build the binary. Therefore, you can see all the files include in a package, the relationship between packages, checksum of everything, license and etc.

@jvanz jvanz requested review from flavio and viccuad August 30, 2022 17:29
@flavio
Copy link
Member

flavio commented Aug 31, 2022

Thanks @jvanz, I was able to run the command locally.

I've looked at the _manifest/spdx_2.2/manifest.spdx.json file generated and I wonder how useful it would be.

For example, take a look at this snippet about the addr2line dependency:

    {
      "fileName": "./deps/addr2line-28aec851f2e54f6a.d",
      "SPDXID": "SPDXRef-File--deps-addr2line-28aec851f2e54f6a.d-19D14F2B41953D84DFBB935FED640F81D0809DFA",
      "checksums": [
        {
          "algorithm": "SHA256",
          "checksumValue": "4512d8e3dd2ea20f9b30e414254f9f04dcd8991d764b6f1a6d6b47abab74e6d2"
        },
        {
          "algorithm": "SHA1",
          "checksumValue": "19d14f2b41953d84dfbb935fed640f81d0809dfa"
        }
      ],
      "licenseConcluded": "NOASSERTION",
      "licenseInfoInFiles": [
        "NOASSERTION"
      ],
      "copyrightText": "NOASSERTION"
    },

This snippet doesn't tell me where the dependency is coming (crates.io release, a github repository,...) and it doesn't tell me the version being used. I can see what I assume is a git commit shasum inside of the folder name ./deps/addr2line-28aec851f2e54f6a.d.

This isn't what I expected to find inside of a SPDX report.

I did some quick search, and I ran opensbom-generator/spdx-sbom-generator in this way:

$ spdx-sbom-generator

This produced a bom-cargo.spdx which has contents that are more aligned with what I was expecting. For example, taking the same addr2line dependency:

##### Package representing the addr2line

PackageName: addr2line
SPDXID: SPDXRef-Package-addr2line-0.17.0
PackageVersion: 0.17.0
PackageSupplier: NOASSERTION
PackageDownloadLocation: https://github.com/gimli-rs/addr2line
FilesAnalyzed: false
PackageChecksum: SHA1: 59f51ecbe91443fc78708b82c2ad39645cba5d9d
PackageHomePage: https://github.com/rust-lang/crates.io-index
PackageLicenseConcluded: NOASSERTION
PackageLicenseDeclared: NOASSERTION
PackageCopyrightText: NOASSERTION
PackageLicenseComments: NOASSERTION
PackageComment: NOASSERTION

Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-rustc-demangle-0.1.21 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-smallvec-1.9.0 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-backtrace-0.3.66 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-clap-3.2.17 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-cpp-demangle-0.3.5 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-fallible-iterator-0.2.0 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-gimli-0.26.2 
Relationship: SPDXRef-Package-addr2line-0.17.0 DEPENDS_ON SPDXRef-Package-object-0.29.0 

This looks more "human-friendly".

Now, I'm not suggesting we have to move to this other tool. I just wonder if we are not invoking the Microsoft one with the right set of parameters.

Makefile Outdated Show resolved Hide resolved
@viccuad
Copy link
Member

viccuad commented Aug 31, 2022

@flavio here, the sbom-tool outputs the expected contents for addr2line (in fact, the same you pasted). After applying #312 (comment).

@jvanz jvanz force-pushed the main branch 4 times, most recently from 6b2a01e to 2a6b2c7 Compare August 31, 2022 13:46
@jvanz jvanz requested a review from viccuad August 31, 2022 13:47
@jvanz jvanz force-pushed the main branch 2 times, most recently from fe20024 to 9b57432 Compare August 31, 2022 13:54
@jvanz
Copy link
Member Author

jvanz commented Aug 31, 2022

@viccuad @flavio , I've updated the PR to use the spdx-sbom-generator tool and generate the right packages dependencies.

Furthermore, I've also open an issue in the sbom-tool to know why we cannot get the right packages dependencies relationships from cargo file.

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
.github/workflows/container-image.yml Outdated Show resolved Hide resolved
@jvanz jvanz force-pushed the main branch 4 times, most recently from e5b7338 to ff230f9 Compare August 31, 2022 14:33
@jvanz jvanz requested a review from flavio August 31, 2022 14:35
Cargo.toml Outdated Show resolved Hide resolved
env:
COSIGN_EXPERIMENTAL: 1

- name: Upload policy-server binary
Copy link
Member

@viccuad viccuad Aug 31, 2022

Choose a reason for hiding this comment

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

Maybe we could sign the binary and upload the binary and its signature to the interim artifacts.
The signatures could be checked when building the container image. I suppose this may be needed for SLSA.
Not much improvement for our current security stance, as we depend on GHA and artifacts anyway. But in the future we could build in our own worker.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think this would be a nice improvement. However I would not block this PR to get this implemented, I would rather file a new issue

Copy link
Member Author

Choose a reason for hiding this comment

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

That's sound a good idea indeed. I've just created an issue to keep track of this improvement.

Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

Approving, I'm happy to merge as it is.

We could add SBOM for both build image and resulting container image in following PRs.

Copy link
Member

@flavio flavio left a comment

Choose a reason for hiding this comment

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

LGTM, I left some minor comments that are not mandatory to get this PR merged

env:
COSIGN_EXPERIMENTAL: 1

- name: Upload policy-server binary
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think this would be a nice improvement. However I would not block this PR to get this implemented, I would rather file a new issue

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Adds new steps in the build and release workflow to generate, sign and
publish a SBOM file for Policy Server.
@jvanz jvanz merged commit fa095f7 into kubewarden:main Aug 31, 2022
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.

policy-server: create SBOM file
3 participants