# CBOMkit-action GitHub Action to generate CBOMs. CBOMkit-action identifies all project modules contained in a github repository, scans the corresponding source code and produces a CBOM object per module. A project module is a part of a repo that can be used independently of other modules and may be published as a separate package. CBOMkit-action also generates a consolidated CBOM file that contains all crypto findings for the entire repository. All CBOM objects can be uploaded as json files in a github workflow artifact. This artifact is a zip file (`CBOM.zip`) that contains all CBOMs. For a particular package module the CBOM file is `cbom-.json. The overall CBOM is named `cbom.json`. ## Usage Create a yaml file with a name of your choice in `.github/workflows`. The following example specifies the CBOM generation for a Java repository built with maven. ```yaml on: workflow_dispatch: jobs: cbom-scan: runs-on: ubuntu-latest name: CBOM generation permissions: contents: write pull-requests: write steps: - name: Checkout repository uses: actions/checkout@v5 - name: Build with Maven # When scanning Java code, the build should be completed beforehand run: mvn -B clean package -DskipTests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create CBOM uses: cbomkit/cbomkit-action@ id: cbom env: CBOMKIT_LANGUAGES: java, python # or java or python - name: Commit changes to new branch # Allows persisting the CBOMs after job completion and # sharing them with another job in the same workflow. uses: actions/upload-artifact@v4 with: name: "CBOM" path: ${{ steps.cbom.outputs.pattern }} if-no-files-found: warn ``` > [!NOTE] > For java repositories, the precision and the quality of generated CBOM depends > on the scanner's ability to resolve symbols defined in the dependencies. We > therefore recommend to build all java code prior to scanning as shown in above > example. `cbomkit-action` auto-constructs a list of directories used by the > scanner to search for java dependencies (jar/zip files). By default, this list > contains the project directory (cloning target) and the maven/gradle default > repository path. The scanning option `CBOMKIT_JAVA_JAR_DIR` allows to append > an additional path expression to the default list. This expression may contain > wildcards (`*`) to denote arbitrary directories. ### Parameters CBOMkit-action requires the following parameters passed as enviroment variables. If run in a workflow, these variables are automatically set by the checkout step. - `GITHUB_WORKSPACE`: Mandotory root directory of the cloned repository. - `GITHUB_OUTPUT`: Mandatory filename containing the name pattern of the CBOM files used by uploader. - `GITHUB_SERVER_URL`: (Optional) Github server url. Will be used to set the gitUrl property in the CBOM metadata which is used by CBOMkit viewer. - `GITHUB_REPOSITORY`: (Optional) Github repository name. Will be used to set the gitUrl property in the CBOM metadata which is used by CBOMkit viewer. gitUrl metadata property = GITHUB_SERVER_URL + "/" + GITHUB_REPOSITORY. - `GITHUB_REF_NAME`: (Optional) Github ref name. Will be used to set the revision (branch) property in the CBOM metadata which is used by CBOMkit viewer. - `GITHUB_SHA`: (Optional) Github commit SHA value. The first 7 characters will be used to set the commit property in the CBON metadata which is used by CBOMkit viewer. ### Scanning Options CBOMkit-action's behavior can be controlled via the following additional environment variables. - `CBOMKIT_OUTPUT_DIR`: (Optional) Output directory for CBOM files. Defaults to "cbom" if not set. - `CBOMKIT_EXCLUDE`: (Optional) Comma-separated list of java regex patterns. Matches the first occurrence of a pattern in source file/dir paths relative to the GITHUB_WORKSPACE. Files/dirs are excluded from scanning if any of the patterns match. By default, CBOMKit excludes test files from scanning. Setting CBOKKIT_EXCLUDE overrules this default. Setting CBOMKIT_EXCLUDE to an empty string turns off exclusion resulting in a complete scan of all source files. - `CBOMKIT_LANGUAGES`: (Optional) Comma-separated list of programming languages to scan. White-space will be ignored. If set, only specified programming languages will be scanned. Since CBOMkit currently supports Java and Python, only `java` or `python` are plausible values. - `CBOMKIT_GENERATE_MODULE_CBOMS`: (Optional) Generate CBOMs for project modules. Default value is `true`. - `CBOMKIT_WRITE_EMTPY_CBOMS`: (Optional) Also write CBOMs with 0 findings. Default value is `true`. - `CBOMKIT_JAVA_REQUIRE_BUILD`: (Optional) Java scans will terminate with an error if java files were found **and** the repo was not built prior to scanning. Default value is `true`. Setting it to `false` allows source-only scans of java repos with potentially lower accuracy. - `CBOMKIT_JAVA_JAR_DIR`: (Optional) CBOMkit-action auto-constructs a list of jar/zip files to be considered for scanning. This option allows the specification of an additional directory for jar/zip files specific to the crypto library. ## Supported languages and libraries The current scanning capabilities of the CBOMkit are defined by the [Sonar Cryptography Plugin's](https://github.com/cbomkit/sonar-cryptography) supported languages and cryptographic libraries: | Language | Cryptographic Library | Coverage | |----------|-----------------------------------------------------------------------------------------------|----------| | Java | [JCA](https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html) | 100% | | | [BouncyCastle](https://github.com/bcgit/bc-java) (*light-weight API*) | 100%[^1] | | Python | [pyca/cryptography](https://cryptography.io/en/latest/) | 100% | | Go | [crypto](https://pkg.go.dev/crypto) (*standard library*) | 100%[^2] | | | [golang.org/x/crypto](https://pkg.go.dev/golang.org/x/crypto) | Partial[^3] | | C# | [System.Security.Cryptography](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography) | In development[^4] | [^1]: We only cover the BouncyCastle *light-weight API* according to [this specification](https://javadoc.io/static/org.bouncycastle/bctls-jdk14/1.80/specifications.html) [^2]: All packages under [`crypto`](https://pkg.go.dev/crypto@go1.25.6#section-directories) are covered except `crypto/x509` [^3]: Covers `golang.org/x/crypto/hkdf`, `golang.org/x/crypto/pbkdf2`, and `golang.org/x/crypto/sha3` [^4]: C# support uses an [ANTLR v7 grammar](https://github.com/antlr/grammars-v4/tree/master/csharp) to parse source files directly. The current csharp support only covers the language support and does not contain detection rules other than the rules used for verifying the detection engine. **This is not yet meant for active usage!** **Known limitations of the detection engine:** no cross-method variable tracking (only single-method scope), only works for c# v7, string-based matching (no type resolution) While the CBOMkit's scanning capabilities are currently bound to the Sonar Cryptography Plugin, the modular design of this plugin allows for potential expansion to support additional languages and cryptographic libraries in future updates.