Skip to main content
Plans: Every plan. Who: an owner or admin creates the API token; a project maintainer adds the CI/CD variable and the job.
This job runs when you push a Git tag. It installs Syft, generates a CycloneDX JSON SBOM of the repository and sends it to Pharus, with the tag as the product version.

Before you start

1

Create a token

In Pharus, go to Settings → API tokens and create a token for the product family. See create a token.
2

Store it as a CI/CD variable

In GitLab, open the project’s Settings → CI/CD → Variables and add a variable with the key PHARUS_TOKEN and the token as its value. Mask it, so it doesn’t show in job logs.
If you also mark the variable as protected, GitLab only passes it to pipelines on protected branches and tags. Protect the tags the job runs on, or leave the variable unprotected.

The job

Add this job to .gitlab-ci.yml:
What it does:
  • Trigger: rules: - if: $CI_COMMIT_TAG runs the job only in pipelines for a Git tag.
  • Generate: the job installs curl in a small Alpine image, downloads one Syft release, checks its SHA-256, and Syft writes sbom.cdx.json from the repository.
  • Version: the tag, such as v4.2, becomes the product version in Pharus.
  • Send: the last command gzips the file and posts it to POST /api/v1/sboms. The X-Pharus-* headers fill in the Pipeline card on the SBOM’s page, with a link to the job.
  • Retry, then report: curl tries again through a short outage at Pharus (a 5xx answer, a timeout or a refused connection) for about a minute. Pharus answers a file it already has as a duplicate, so a retry is safe. If the upload still fails, --fail-with-body fails the job and prints Pharus’ message in the log.
  • Release anyway: allow_failure: true shows a failed upload as a warning instead of failing the pipeline. Remove the line if a release must not pass without its SBOM in Pharus.
Pharus’ answer is printed in the job log. Its warnings list gaps in the SBOM quality and components past end of life upstream; the SBOM is stored either way. See the response. The job uses the deploy stage, one of GitLab’s default stages. If your .gitlab-ci.yml lists its own stages, use one of those.
Pharus has no source label for GitLab, so these SBOMs show API as their Source. The Pipeline card still links to the GitLab job.

Update Syft

The job pins Syft to one release and the SHA-256 of its download. Anything that runs in your pipeline can change the checked-out code that later jobs build and deploy, so the job runs only the file you chose: if the download doesn’t match the hash, sha256sum -c fails, and GitLab stops the job before Syft runs. To move to a newer Syft:
1

Pick a release

Open Syft’s releases and download syft_<version>_checksums.txt from the release you want.
2

Change both variables

Set SYFT_VERSION to the version without the v, for example 1.52.0, and SYFT_SHA256 to the hash on the syft_<version>_linux_amd64.tar.gz line of that file.
The values are for Linux on x86-64 (amd64). For a runner on ARM64, see the variation below.
If your job pipes Syft’s install.sh into sh, from an earlier copy of this page, replace those lines with these.

Variations

Use syft dir:. -o spdx-json=sbom.spdx.json and gzip sbom.spdx.json in the last command. Pharus reads SPDX JSON 2.2 and 2.3.
Replace dir:. with the image reference, for example registry.gitlab.com/acme/gateway-g3:4.2. For a private registry, give Syft credentials as Syft’s documentation describes.
Change linux_amd64 to linux_arm64 in the download URL, and set SYFT_SHA256 to the hash on the syft_<version>_linux_arm64.tar.gz line. For Syft 1.52.0 that is c46d5e4c28e12aa4c5becfaa343ef1c7f89045b6b895f2c21d471c62db09c706. In the job, uname -m prints x86_64 for amd64 and aarch64 for ARM64.
Use rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH, and send your release version in X-Pharus-Version in place of $CI_COMMIT_TAG. Without a version, Pharus uses the version inside the SBOM, if it has one.

Check that it worked

The job log shows Pharus’ answer, with "status":"parsed" for a new SBOM and "duplicate":true when Pharus already had the file. In Pharus, the SBOM appears under SBOMs, and the token’s Last used time changes under Settings → API tokens. All codes are listed under errors.

Upload an SBOM

API introduction

GitHub Actions

Azure Pipelines