Run Rivex in CI.
Harden a Dockerfile on every push, with the GitHub Action or with the rivex command on GitLab CI, Jenkins, Azure DevOps or Bitbucket Pipelines.
Before you start.
Every CI job needs an API key. Create one on the API keys page and store it in your CI system as a secret named RIVEX_API_KEY. Each section below says where. Never write the key in a file that you commit.
To try on your own machine what the CI jobs run, install the CLI and set two shell variables. Replace <your-api-key> with your key:
export RIVEX_API_URL=https://api.rivexsecurity.com
export RIVEX_API_KEY='<your-api-key>' rivex --api-url "$RIVEX_API_URL" harden Dockerfile -o Dockerfile.hardened Each job below runs this command on the file named Dockerfile at the top of your repository and writes Dockerfile.hardened. To make a job fail on a serious finding, add --fail-on high. The command line guide lists the exit codes.
In a CI job, Rivex doesn't build the hardened Dockerfile in its sandbox: your pipeline usually builds the image itself right after, and each sandbox build uses one of the month's verified builds of your plan. The job's log says Build verification: not run — skipped in CI. To build it in the sandbox anyway, add --verify-build --build-context . to the command, or set RIVEX_VERIFY_BUILD=true in the job. Each snippet below has this as a comment. The command line guide explains how the CLI decides.
GitHub Actions.
Store the key as a repository secret named RIVEX_API_KEY. Then add this workflow as .github/workflows/harden.yml:
name: Harden Dockerfile
on: [push]
jobs:
harden:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: rivex
uses: Rivex-Security/rivex-cli@v1
with:
api-key: ${{ secrets.RIVEX_API_KEY }}
fail-on: high
- if: always()
uses: actions/upload-artifact@v4
with:
name: hardened-dockerfile
path: ${{ steps.rivex.outputs.hardened-dockerfile }} The job fails when a finding is high or critical. The hardened file is saved as an artifact either way.
Inputs.
dockerfile: the Dockerfile to harden, relative to the top of the repository. Default:Dockerfile.output: where to write the hardened Dockerfile. Default:Dockerfile.hardened.api-url: the address of the Rivex API. Default:https://api.rivexsecurity.com.api-key: your API key. Pass it from a secret. Empty by default.token: a sign-in token, used only whenapi-keyis empty. Empty by default.fail-on: fail the step when a finding has this severity or a higher one:critical,high,medium,lowornone. Default:none.attest: set it totrueto sign a build provenance attestation for the hardened file. Default:false. The job then needs the permissions shown below.scan-backend: set it toscoutto scan an image with Docker Scout after hardening. The scan writesscout-results.sarifand uploads it as thescout-sarifartifact. Findings never fail the job. Default:none.image-ref: the image to scan. Required whenscan-backendisscout: without it, no scan runs. Empty by default.registry-auth: credentials for base images on a private registry, onehost=username:secretper line. The action passes them to the CLI only as theRIVEX_REGISTRY_AUTHenvironment variable. Prefer short-lived tokens. Empty by default. Registry credentials has examples.verify-build: set it totrueto build the hardened Dockerfile in the Rivex sandbox. Each build uses one of the month's verified builds. Default:false. Left atfalse, the action passes nothing to the CLI, so a job-levelRIVEX_VERIFY_BUILD=truestill turns builds on.build-context: the project folder to send with the Dockerfile for that build, for example.. Used only whenverify-buildistrue. Empty by default.attestation-out: where to save the Rivex-signed attestation (a Sigstore bundle), passed as--attestation-out. Not the same as GitHub'sattest. Empty by default.sbom-out: where to save the CycloneDX SBOM, passed as--sbom-out. Empty by default.verify: a Dockerfile to check against its attestation. Setting it switches the action to verify mode: it runsrivex verifyinstead of hardening, needs noapi-keyand never contacts Rivex. Check hardened Dockerfiles in CI has an example. Empty by default.attestation: the bundle to check in verify mode. Default:attestation.sigstore.jsonnext to the Dockerfile.no-disabled-rules: set it totruein verify mode to fail when a policy turned off any rule. Default:false.
With attest: true, give the job these permissions:
permissions:
contents: read
id-token: write
attestations: write Output.
hardened-dockerfile: the path of the hardened Dockerfile, the same as theoutputinput.
GitLab CI.
Add RIVEX_API_KEY as a masked variable under Settings, CI/CD, Variables. Write the job to a file:
rivex ci init --platform gitlab --output rivex-gitlab.yml Then copy the job into your .gitlab-ci.yml:
rivex-harden:
image: alpine:3.20
script:
- wget -q https://github.com/Rivex-Security/rivex-cli/releases/latest/download/rivex_linux_amd64 https://github.com/Rivex-Security/rivex-cli/releases/latest/download/checksums.txt
- grep ' rivex_linux_amd64$' checksums.txt | sha256sum -c -
- chmod +x rivex_linux_amd64 && mv rivex_linux_amd64 rivex
- ./rivex harden Dockerfile -o Dockerfile.hardened --api-url https://api.rivexsecurity.com
# In CI the build is not verified. To build it in the sandbox, which uses one of your monthly verified builds, add: --verify-build --build-context .
# Set RIVEX_API_KEY in Settings > CI/CD > Variables (masked) Jenkins.
Add a credential of the kind "Secret text" with the ID rivex-api-key; the stage reads it as RIVEX_API_KEY. Write the stage to a file:
rivex ci init --platform jenkins --output rivex-jenkins.groovy Then copy the stage into the stages block of your Jenkinsfile:
stage('Rivex Harden') {
agent {
docker { image 'alpine:3.20' }
}
steps {
withCredentials([string(credentialsId: 'rivex-api-key', variable: 'RIVEX_API_KEY')]) {
sh '''
wget -q https://github.com/Rivex-Security/rivex-cli/releases/latest/download/rivex_linux_amd64 https://github.com/Rivex-Security/rivex-cli/releases/latest/download/checksums.txt
grep ' rivex_linux_amd64$' checksums.txt | sha256sum -c -
chmod +x rivex_linux_amd64 && mv rivex_linux_amd64 rivex
./rivex harden Dockerfile -o Dockerfile.hardened --api-url https://api.rivexsecurity.com
# In CI the build is not verified. To build it in the sandbox, which uses one of your monthly verified builds, add: --verify-build --build-context .
'''
}
}
} Azure DevOps.
Add RIVEX_API_KEY as a secret variable of your pipeline. Write the steps to a file:
rivex ci init --platform azure --output rivex-azure.yml Then copy the steps into the steps list of your azure-pipelines.yml:
- script: |
wget -q https://github.com/Rivex-Security/rivex-cli/releases/latest/download/rivex_linux_amd64 https://github.com/Rivex-Security/rivex-cli/releases/latest/download/checksums.txt
grep ' rivex_linux_amd64$' checksums.txt | sha256sum -c -
chmod +x rivex_linux_amd64 && mv rivex_linux_amd64 rivex
./rivex harden Dockerfile -o Dockerfile.hardened --api-url https://api.rivexsecurity.com
# In CI the build is not verified. To build it in the sandbox, which uses one of your monthly verified builds, add: --verify-build --build-context .
displayName: 'Rivex Harden'
env:
RIVEX_API_KEY: $(RIVEX_API_KEY) # secret variables reach a script only through env
# Set RIVEX_API_KEY as a secret pipeline variable in Azure DevOps Bitbucket Pipelines.
Add RIVEX_API_KEY as a secured variable under Repository settings, Repository variables. Write the configuration to a file:
rivex ci init --platform bitbucket --output rivex-bitbucket.yml The file is a whole bitbucket-pipelines.yml. If you already have one, copy the step into it:
pipelines:
default:
- step:
name: Rivex Harden
image: alpine:3.20
script:
- wget -q https://github.com/Rivex-Security/rivex-cli/releases/latest/download/rivex_linux_amd64 https://github.com/Rivex-Security/rivex-cli/releases/latest/download/checksums.txt
- grep ' rivex_linux_amd64$' checksums.txt | sha256sum -c -
- chmod +x rivex_linux_amd64 && mv rivex_linux_amd64 rivex
- ./rivex harden Dockerfile -o Dockerfile.hardened --api-url https://api.rivexsecurity.com
# In CI the build is not verified. To build it in the sandbox, which uses one of your monthly verified builds, add: --verify-build --build-context .
# Set RIVEX_API_KEY in Repository Settings > Repository variables