id: syft-sbom-artifact-drift-gate
namespace: company.team
description: |
Catch SBOM drift between what a build recorded and what actually ships.
A CD pipeline POSTs the artifact name to a keyed webhook, the flow
rebuilds the package list with Syft over a fixture artifact tree in its
official container, and a Python step diffs the fresh SBOM against the
stored build-time baseline. Drift beyond the tolerated percentage posts
the added and removed packages to Slack and fails the execution, while a
matching artifact is recorded as clean and the verdict, counts, and
package lists are published as outputs.
triggers:
- id: on_artifact_promote
type: io.kestra.plugin.core.trigger.Webhook
description: CD POSTs here with the artifact name when a build requests
promotion, to verify the shipped package set still matches the recorded
baseline.
key: "{{ secret('SBOM_DRIFT_WEBHOOK_KEY') }}"
- id: nightly_drift_sweep
type: io.kestra.plugin.core.trigger.Schedule
description: Fallback net, a nightly re-check of the last promoted artifact
against its baseline, shipped disabled until an operator switches it on.
cron: "0 2 * * *"
disabled: true
inputs:
- id: artifact_name
type: STRING
defaults: payments-service
description: Logical artifact name whose package set is compared against the
build-time baseline file.
- id: drift_threshold_pct
type: INT
defaults: 10
description: Maximum tolerated package churn percentage before the artifact is
treated as drifted.
tasks:
# --- 1. sbom rebuild ---
- id: sbom_workspace
type: io.kestra.plugin.core.flow.WorkingDirectory
description: One shared directory so the artifact tree, the baseline, the Syft
report, and the drifter all see the same files.
tasks:
- id: prepare_artifact
type: io.kestra.plugin.scripts.shell.Commands
description: Materialize a fixture artifact tree with heredocs and write the
build-time baseline package list the drift check compares against.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
entryPoint: []
containerImage: python:3.12-slim
commands:
- |
set -u
mkdir -p app
cat > app/requirements.txt <<'REQ'
flask==2.3.2
werkzeug==2.3.7
jinja2==3.1.2
urllib3==2.0.4
requests==2.31.0
flask-cors==4.0.0
REQ
cat > app/package.json <<'PKG'
{
"name": "payments-service-ui",
"version": "1.4.2",
"dependencies": {
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
PKG
cat > baseline.json <<'JSON'
{
"artifact": "payments-service",
"recorded_at": "2026-09-30T02:11:00Z",
"packages": [
"flask@2.3.2",
"werkzeug@2.3.7",
"jinja2@3.1.2",
"urllib3@2.0.4",
"requests@2.31.0",
"flask-cors@4.0.0"
]
}
JSON
echo "artifact tree and baseline prepared"
- id: generate_sbom
type: io.kestra.plugin.scripts.shell.Commands
description: Write a bundled fixture SBOM, run Syft over the artifact tree in
its official image with the exit code absorbed, and fall back to the
fixture when the tool cannot run so the gate stays deterministic.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
entryPoint: []
containerImage: anchore/syft:latest
env:
ARTIFACT_NAME: "{{ inputs.artifact_name }}"
outputFiles:
- syft-report.json
commands:
- |
set -u
cat > fixture-syft-report.json <<'JSON'
{
"artifacts": [
{"name": "flask", "version": "2.3.2", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "werkzeug", "version": "2.3.7", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "jinja2", "version": "3.1.2", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "urllib3", "version": "2.0.4", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "requests", "version": "2.31.0", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "flask-cors", "version": "5.0.0", "type": "python", "locations": [{"path": "app/requirements.txt"}]},
{"name": "markupsafe", "version": "2.1.3", "type": "python", "locations": [{"path": "app/requirements.txt"}]}
],
"source": {"type": "directory"}
}
JSON
echo "Building SBOM for artifact tree with Syft"
syft dir:./app -o syft-json=syft-report.json || true
if [ ! -s syft-report.json ]; then
cp fixture-syft-report.json syft-report.json
echo "syft unavailable in this sandbox, emitting the bundled fixture SBOM"
fi
echo "report bytes $(wc -c < syft-report.json)"
- id: compare_baseline
type: io.kestra.plugin.scripts.python.Script
description: Diff the fresh Syft package set against the baseline, compute the
churn percentage, and emit the drift verdict through the outputs
protocol.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: python:3.12-slim
env:
ARTIFACT_NAME: "{{ inputs.artifact_name }}"
DRIFT_THRESHOLD_PCT: "{{ inputs.drift_threshold_pct }}"
script: |
import json
import os
artifact = os.environ.get("ARTIFACT_NAME", "unknown-artifact")
try:
threshold = float(os.environ.get("DRIFT_THRESHOLD_PCT", "10"))
except ValueError:
threshold = 10.0
def load_json(path, default):
if os.path.exists(path) and os.path.getsize(path) > 0:
try:
with open(path, "r") as handle:
return json.load(handle)
except ValueError:
return default
return default
report = load_json("syft-report.json", {})
baseline_doc = load_json("baseline.json", {})
current = []
if isinstance(report, dict):
for art in report.get("artifacts") or []:
if not isinstance(art, dict):
continue
name = str(art.get("name") or "").strip()
if not name:
continue
current.append(name + "@" + str(art.get("version") or "unversioned"))
baseline = []
if isinstance(baseline_doc, dict):
baseline = [str(p).strip() for p in (baseline_doc.get("packages") or []) if str(p).strip()]
current_set = sorted(set(current))
baseline_set = sorted(set(baseline))
added = sorted(set(current_set) - set(baseline_set))
removed = sorted(set(baseline_set) - set(current_set))
drift_pct = round(100.0 * (len(added) + len(removed)) / max(len(baseline_set), 1), 2)
drifted = drift_pct > threshold
verdict = "DRIFT" if drifted else "CLEAN"
added_summary = ", ".join(added) or "none"
removed_summary = ", ".join(removed) or "none"
payload = {
"artifact": artifact,
"package_count": len(current_set),
"baseline_count": len(baseline_set),
"added_packages": added,
"removed_packages": removed,
"added_summary": added_summary,
"removed_summary": removed_summary,
"drift_pct": drift_pct,
"drifted": drifted,
"verdict": verdict,
}
print("artifact=%s packages=%d baseline=%d drift=%s verdict=%s" % (
artifact, len(current_set), len(baseline_set), drift_pct, verdict))
print("::" + json.dumps({"outputs": payload}) + "::")
# --- 2. drift gate ---
- id: check_drift
type: io.kestra.plugin.core.flow.If
description: Block the promotion only when the package churn percentage sits
above the tolerated threshold, a matching artifact is recorded and left
alone.
condition: "{{ (outputs.compare_baseline.vars.drift_pct | number) >
(inputs.drift_threshold_pct | number) }}"
then:
- id: alert_slack_drift
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the drift percentage with the added and removed packages so
the release channel sees exactly what changed since the build.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "SBOM DRIFT for {{ inputs.artifact_name }} - {{ outputs.compare_baseline.vars.drift_pct }} percent package churn against the build baseline (threshold {{ inputs.drift_threshold_pct }}). Added {{ outputs.compare_baseline.vars.added_summary }}. Removed {{ outputs.compare_baseline.vars.removed_summary }}. Execution {{ execution.id }}."
}
- id: fail_artifact
type: io.kestra.plugin.core.execution.Fail
description: Fail the execution so the promotion pipeline stops before a drifted
artifact reaches the production registry.
errorMessage: "SBOM drift of {{ outputs.compare_baseline.vars.drift_pct }}
percent blocked {{ inputs.artifact_name }} against a threshold of {{
inputs.drift_threshold_pct }}."
else:
- id: log_clean
type: io.kestra.plugin.core.log.Log
description: Record the clean comparison so the execution history doubles as the
SBOM attestation for this artifact.
message: "SBOM matches the build baseline for {{ inputs.artifact_name }} with {{
outputs.compare_baseline.vars.package_count }} packages and 0 percent
drift."
errors:
- id: notify_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Escalate any failure to the ops channel with the execution url.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{"text": "FAILED: {{ flow.id }} {{ execution.id }}"}
outputs:
- id: verdict
type: STRING
description: DRIFT when package churn exceeds the threshold, otherwise CLEAN.
value: "{{ outputs.compare_baseline.vars.verdict }}"
- id: drift_pct
type: FLOAT
description: Package churn percentage against the baseline, for example 50.0.
value: "{{ outputs.compare_baseline.vars.drift_pct }}"
- id: package_count
type: INT
description: Number of distinct packages in the freshly built SBOM.
value: "{{ outputs.compare_baseline.vars.package_count }}"
- id: added_packages
type: ARRAY
description: 'Packages present in the fresh SBOM but absent from the baseline.'
value: "{{ outputs.compare_baseline.vars.added_packages | toJson }}"
- id: removed_packages
type: ARRAY
description: 'Packages present in the baseline but absent from the fresh SBOM.'
value: "{{ outputs.compare_baseline.vars.removed_packages | toJson }}"