In CI pipelines
Run the mlab CLI, postmortem and assay in GitHub Actions, GitLab CI and Jenkins: exit codes per tool, failing a build on a threshold, caching and secrets.
Three of the binaries are made to gate a build:
| Tool | Gates on | Network |
|---|---|---|
mlab (mlab sbom scan) | Known vulnerabilities in a lockfile or SBOM, matched on vuln.mlab.sh | Yes. No key needed; an optional token raises the quota |
postmortem | Malicious code in dependencies (scan), and supply-chain risk and known vulnerabilities (tree, audit) | scan is offline. --online and --vulns call out |
assay | Unsafe or malformed ML model artifacts | Offline |
For vulnerability scanning with no binary at all, the GitHub Action mlab-sh/vuln-scan-action does the same server-side scan as mlab sbom scan.
Exit codes
Every tool keeps findings and errors apart. A build script should treat "found something" and "could not check" differently, and must never let "could not check" pass.
mlab
| Code | Meaning |
|---|---|
0 | Success |
1 | Generic failure: network, TLS, unreadable response |
2 | Authentication: missing, rejected or unrecognised key |
3 | Quota exhausted or rate limited |
4 | Invalid input: bad domain, unreadable file, unsupported type |
5 | Platform in maintenance |
6 | Nothing found: no scan for that domain, unknown hash |
7 | A --fail-on gate matched: the scan worked and found something bad enough |
An incomplete sbom scan (a package that could not be scanned, an advisory source that is down, a manifest cut at your tier's package limit) never passes --fail-on: it exits non-zero with the reason. Entries that can never be scanned (a git or path dependency, an unpinned requirement) are printed as warnings and do not fail the gate.
postmortem
| Command | 0 | 1 | 2 |
|---|---|---|---|
scan | Nothing at or above --severity (default high) | A finding met or exceeded --severity | No supported ecosystem found at any path |
tree, audit, system (the CI gate) | No active gate tripped | A threshold was exceeded | No supported ecosystem, an unusable target, or a misconfigured gate |
A gate that needs data the run did not collect (--max-high without --online, --fail-on-vuln without --vulns) exits 2. It never passes silently.
assay
| Code | Meaning |
|---|---|
0 | Clean: nothing at or above --fail-on (default high) |
1 | Findings at or above --fail-on |
2 | Unreadable or malformed artifact |
3 | Internal error, or the path does not exist |
4 | The path exists but holds nothing scannable (--allow-empty turns this into 0) |
In a directory scan, the worst outcome wins: a malformed artifact anywhere outranks a finding elsewhere.
k3sec and engram
Both exit 0 on success and 1 on any error, with the reason on stderr. Neither has a findings gate: build one with jq on their JSON output (recipes).
Failing on a threshold
| Tool | Threshold flags | Values |
|---|---|---|
mlab sbom scan | --fail-on <severity> | critical, high, medium, low (from the advisory's CVSS v3 vector) |
postmortem scan | --severity <level> (exit 1), --min-severity <level> (hide below) | info, low, medium, high, critical |
postmortem tree / audit | --fail-on-vuln <sev>, --max-vulns <N> (need --vulns); --max-risk <N>, --max-dep <N>, --max-high <N>, --max-sus <N> (need --online) | Each --max-* is a ceiling: it trips when the value is strictly greater |
assay scan / verify / compare | --fail-on <severity> | info, low, medium, high, critical |
mlab sbom scan Cargo.lock web/package-lock.json --fail-on high
postmortem scan . --severity high
postmortem tree . --online --vulns --max-high 0 --fail-on-vuln high
assay scan ./models/ --fail-on highmlab sbom scan --json and assay scan --json still apply the gate, so one step can both save the report and fail. When you pipe the JSON into tee, set pipefail, otherwise the pipeline returns tee's exit code:
set -o pipefail
assay scan ./models/ --json --fail-on high | tee assay-report.jsonpostmortem's gate summary goes to stderr, so --json on stdout stays clean. With several lockfiles, mlab sbom scan judges --fail-on once at the end, across all of them. postmortem tree trips if any target trips. To fail only on new risk, compare with a baseline taken from a clean run: postmortem tree . --json -o baseline.json, then --baseline baseline.json.
Installing in a job
Pin versions. Each release publishes a SHA256SUMS file covering its assets.
# mlab CLI (tarballs: x86_64 / aarch64, linux-gnu / apple-darwin)
V=1.3.0 T=x86_64-unknown-linux-gnu
curl -fsSLO "https://github.com/mlab-sh/mlab-cli/releases/download/v${V}/mlab-${V}-${T}.tar.gz"
curl -fsSLO "https://github.com/mlab-sh/mlab-cli/releases/download/v${V}/SHA256SUMS"
sha256sum -c --ignore-missing SHA256SUMS
tar xzf "mlab-${V}-${T}.tar.gz" && install -m 0755 "mlab-${V}-${T}/mlab" /usr/local/bin/
# postmortem (also x86_64-pc-windows-msvc as a .zip)
V=2.9.2 T=x86_64-unknown-linux-gnu
curl -fsSL "https://github.com/mlab-sh/postmortem/releases/download/v${V}/postmortem-${V}-${T}.tar.gz" | tar xz
install -m 0755 "postmortem-${V}-${T}/postmortem" /usr/local/bin/
# assay (no release yet: build from the mlab-sh repository, pinned to a commit)
cargo install --locked --git https://github.com/mlab-sh/assay --rev <commit>Never run cargo install assay: the assay crate on crates.io is an unrelated project from another author. See assay installation.
On Debian and Ubuntu runners, the .deb of the mlab CLI and postmortem from the same release pages installs with sudo apt install ./<file>.deb. postmortem is also in the apt.mlab.sh repository (see mlab-agent for the repository setup).
GitHub Actions
postmortem ships its own action, mlab-sh/postmortem@v2. It installs a pinned release, runs postmortem tree with your thresholds, writes a job summary, uploads SARIF to Code Scanning (sarif: true by default), and can open an issue when the gate trips.
name: supply-chain
on: [push, pull_request]
permissions:
contents: read
security-events: write # SARIF upload
jobs:
gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache postmortem lookups
uses: actions/cache@v4
with:
path: ~/.postmortem/cache
key: postmortem-${{ hashFiles('**/*.lock', '**/package-lock.json', '**/go.sum') }}
restore-keys: postmortem-
- name: postmortem gate
uses: mlab-sh/postmortem@v2
with:
version: v2.9.2 # the input defaults to an older release: pin it
online: true
vulns: true
max-high: 0
fail-on-vuln: high
vuln-token: ${{ secrets.VULN_MLAB_TOKEN }}
- name: mlab sbom scan
env:
MLAB_VULN_TOKEN: ${{ secrets.VULN_MLAB_TOKEN }}
run: |
V=1.3.0 T=x86_64-unknown-linux-gnu
curl -fsSL "https://github.com/mlab-sh/mlab-cli/releases/download/v${V}/mlab-${V}-${T}.tar.gz" | tar xz
"./mlab-${V}-${T}/mlab" sbom scan Cargo.lock --fail-on high
models:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache assay
uses: actions/cache@v4
with:
path: ~/.cargo/bin/assay
key: assay-${{ runner.os }}
- name: assay
shell: bash
run: |
command -v assay || cargo install --locked --git https://github.com/mlab-sh/assay --rev <commit>
set -o pipefail
assay scan ./models/ --json --fail-on high | tee assay-report.json
- if: always()
uses: actions/upload-artifact@v4
with:
name: assay-report
path: assay-report.json| postmortem action input | Default | Effect |
|---|---|---|
path / paths | . | One target, or newline-separated targets for a monorepo (a directory or an explicit lockfile) |
version | v2.2.0 | The postmortem release to run |
online, vulns | true | Repository reputation and known vulnerabilities |
max-risk, max-dep, max-high, max-sus, max-vulns, fail-on-vuln | unset | The gate thresholds |
allow, config, baseline | unset | Allowlist entries, a postmortem.conf with a [gate] block, a baseline tree --json |
sarif | true | Emit SARIF and upload it |
soft-fail | false | Report, never fail the job |
create-issue | false | Open or update one issue per branch when the gate trips (needs issues: write, skipped on pull requests) |
github-token, vuln-token | github.token, unset | Rate-limit tokens for GitHub and vuln.mlab.sh |
Outputs: exit-code (0 pass, 1 gate tripped, 2 misconfiguration or no ecosystem), sarif-file, issue-url.
To report without failing, use soft-fail: true and branch on steps.<id>.outputs.exit-code yourself.
GitLab CI
GitLab does not read SARIF. postmortem writes GitLab's own dependency scanning report with --gitlab (on audit and tree), which the merge request widget reads. Publish it with artifacts: when: always, otherwise the failed run, the one you need the report from, publishes nothing.
postmortem ci gitlab > .gitlab-ci.yml prints a ready-made pipeline pinned to the version of the binary that printed it. A hand-written equivalent with the other two tools:
stages: [scan]
variables:
POSTMORTEM_VERSION: "2.9.2"
MLAB_VERSION: "1.3.0"
TARGET: x86_64-unknown-linux-gnu
postmortem:
stage: scan
image: debian:bookworm-slim
cache:
key: postmortem
paths: [.postmortem-cache/]
before_script:
- apt-get update && apt-get install -y --no-install-recommends ca-certificates curl
- curl -fsSL "https://github.com/mlab-sh/postmortem/releases/download/v${POSTMORTEM_VERSION}/postmortem-${POSTMORTEM_VERSION}-${TARGET}.tar.gz" | tar xz
- mkdir -p .postmortem-cache && ln -sfn "$CI_PROJECT_DIR/.postmortem-cache" "$HOME/.postmortem"
script:
# GITHUB_TOKEN and VULN_MLAB_TOKEN: masked CI/CD variables
- ./postmortem-${POSTMORTEM_VERSION}-${TARGET}/postmortem audit . --online --vulns
--max-high 0 --fail-on-vuln high
--gitlab -o gl-dependency-scanning-report.json
artifacts:
when: always
reports:
dependency_scanning: gl-dependency-scanning-report.json
mlab-sbom:
stage: scan
image: debian:bookworm-slim
before_script:
- apt-get update && apt-get install -y --no-install-recommends ca-certificates curl
- curl -fsSL "https://github.com/mlab-sh/mlab-cli/releases/download/v${MLAB_VERSION}/mlab-${MLAB_VERSION}-${TARGET}.tar.gz" | tar xz
script:
# MLAB_VULN_TOKEN: masked CI/CD variable
- ./mlab-${MLAB_VERSION}-${TARGET}/mlab sbom scan package-lock.json --fail-on high --json > mlab-sbom.json
artifacts:
when: always
paths: [mlab-sbom.json]GitLab only caches paths inside the project directory, so the example links ~/.postmortem into it.
Jenkins
postmortem ci jenkins > Jenkinsfile prints a pipeline that publishes SARIF through the Warnings Next Generation plugin in a post { always { … } } block. A declarative example combining the tools, with tokens from Jenkins credentials:
pipeline {
agent { label 'linux' }
environment {
PM_V = '2.9.2'
MLAB_V = '1.3.0'
T = 'x86_64-unknown-linux-gnu'
}
stages {
stage('Install') {
steps {
sh '''
curl -fsSL "https://github.com/mlab-sh/postmortem/releases/download/v${PM_V}/postmortem-${PM_V}-${T}.tar.gz" | tar xz
curl -fsSL "https://github.com/mlab-sh/mlab-cli/releases/download/v${MLAB_V}/mlab-${MLAB_V}-${T}.tar.gz" | tar xz
'''
}
}
stage('Supply chain') {
steps {
withCredentials([
string(credentialsId: 'github-token', variable: 'GITHUB_TOKEN'),
string(credentialsId: 'vuln-mlab-token', variable: 'VULN_MLAB_TOKEN'),
]) {
sh './postmortem-${PM_V}-${T}/postmortem tree . --online --vulns --max-high 0 --fail-on-vuln high --sarif -o postmortem.sarif'
}
}
}
stage('Vulnerabilities') {
steps {
withCredentials([string(credentialsId: 'vuln-mlab-token', variable: 'MLAB_VULN_TOKEN')]) {
sh './mlab-${MLAB_V}-${T}/mlab sbom scan package-lock.json --fail-on high --json > mlab-sbom.json'
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'postmortem.sarif, mlab-sbom.json', allowEmptyArchive: true
recordIssues tool: sarif(pattern: 'postmortem.sarif')
}
}
}To branch on the code instead of failing at once, capture it: sh(script: '...', returnStatus: true) returns the exit code, which you can compare with the tables above.
Caching
| Tool | What to cache | Notes |
|---|---|---|
| postmortem | ~/.postmortem/cache/ | Backs --online and --vulns. Published versions never change, so most entries are kept forever: a missing repository for one day, "no known advisory" for an OS package for 12 hours. Entries are written atomically and versioned (an entry from another format version is a miss), so a shared or restored cache is safe. postmortem cache info, cache path, cache prune --stale. |
| k3sec | ~/.cache/k3sec (or $XDG_CACHE_HOME/k3sec) | Vulnerability results per image digest, valid for --cache-ttl seconds. --no-cache ignores it. |
| assay | The binary only (~/.cargo/bin/assay) | Scans are offline and deterministic. To detect tampering between builds, pin the manifest and file hashes of a known-good run and compare them. |
| mlab CLI | Nothing | Every command asks the server. sbom scan retries by itself after a cooldown refusal (429) of up to 30 seconds. |
Secrets
| Variable | Read by | Needed for |
|---|---|---|
MLAB_VULN_TOKEN | mlab | Optional. Raises the vuln.mlab.sh scan quota (otherwise counted per IP, shared by every runner behind the same NAT) |
MLAB_API_KEY | mlab, k3sec | mlab: every mlab.sh platform command (scan, results, limits, …). Not needed for sbom scan, vuln, cve, actor. k3sec: higher limits on vuln.mlab.sh |
VULN_MLAB_TOKEN | postmortem | Optional. Raises the anonymous vuln.mlab.sh limit for --vulns |
GITHUB_TOKEN (also GITLAB_TOKEN, CODEBERG_TOKEN) | postmortem | --online repository lookups; without one, the anonymous GitHub limit is 60 requests per hour |
The mlab CLI reads MLAB_VULN_TOKEN; postmortem reads VULN_MLAB_TOKEN. The same vuln.mlab.sh token can feed both, under each name.
- Use environment variables, not flags.
--api-keyand--vuln-tokenare visible to every process on the runner and end up in logs. The mlab CLI resolves flag, then environment, then~/.mlab/conf.yml. - Don't run
mlab loginin CI unless the runner is ephemeral: it writes the key to~/.mlab/conf.yml(mode0600). The environment variable needs nothing on disk. - Use masked or protected variables (GitLab), repository or environment secrets (GitHub), credential bindings (Jenkins).
- Keep tokens out of committed files such as
.pre-commit-config.yamlorpostmortem.conf. - Don't scan untrusted pull requests with secrets. postmortem's action already skips issue creation on pull requests, because a fork's token is read-only.
Progress animations turn themselves off when CI is set or stderr is not a terminal, and warnings still print. mlab --quiet (or MLAB_NO_PROGRESS=1) silences all progress output, assay --no-progress the progress display, and NO_COLOR turns off colour in postmortem.
See also
- Recipes: short workflows chaining the tools.
- GitHub Action: the vuln.mlab.sh scan with no binary.
- postmortem, assay, mlab CLI.
k3sec on Kubernetes
Run k3sec on every node of a cluster from the official DaemonSet: what it is allowed to do, how to configure it, how to write and test detection rules, and how to upgrade it.
Recipes
Short, real workflows that chain the mlab binaries: from postmortem findings to CVE details, k3sec SBOMs to a vulnerability gate, a nightly domain scan, offline triage of a memory dump, and more.