Skip to content

Commit 9540221

Browse files
Zie619claude
andcommitted
feat(ci): [15.2] enhance GitLab CI template with severity filter and JSON fallback
- Add TRUSERA_FAIL_ON_SEVERITY variable for Cedar gate threshold - Add JSON results fallback in policy gate (policy-results → results.json) - Fall back to TRUSERA_SEVERITY_THRESHOLD if dedicated var not set Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3b1e9e4 commit 9540221

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.gitlab-ci-trusera.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Trusera AI-BOM Scanner — GitLab CI Template
2+
#
3+
# Usage: Include this template in your .gitlab-ci.yml:
4+
#
5+
# include:
6+
# - remote: 'https://raw.githubusercontent.com/Trusera/ai-bom/main/.gitlab-ci-trusera.yml'
7+
#
8+
# variables:
9+
# TRUSERA_SCAN_TARGET: "."
10+
# TRUSERA_SEVERITY_THRESHOLD: "high"
11+
#
12+
# Or copy this file into your repo and include locally:
13+
#
14+
# include:
15+
# - local: '.gitlab-ci-trusera.yml'
16+
17+
stages:
18+
- scan
19+
- policy-gate
20+
21+
variables:
22+
TRUSERA_SCAN_TARGET:
23+
value: "."
24+
description: "Directory or path to scan"
25+
TRUSERA_FORMAT:
26+
value: "sarif"
27+
description: "Output format (cyclonedx, sarif, spdx, table, html, markdown, csv, json)"
28+
TRUSERA_SCAN_LEVEL:
29+
value: "standard"
30+
description: "Scan depth: quick, standard, or deep"
31+
TRUSERA_SEVERITY_THRESHOLD:
32+
value: ""
33+
description: "Fail pipeline if severity >= threshold (critical, high, medium, low). Leave empty to skip."
34+
TRUSERA_CEDAR_POLICY_FILE:
35+
value: ""
36+
description: "Path to Cedar policy file for policy gate evaluation. Leave empty to skip."
37+
TRUSERA_CEDAR_ENTITIES_FILE:
38+
value: ""
39+
description: "Path to Cedar entities file for additional context (optional)"
40+
TRUSERA_FAIL_ON_SEVERITY:
41+
value: ""
42+
description: "Cedar gate: only fail on violations at or above this severity (critical, high, medium, low)"
43+
44+
trusera-scan:
45+
stage: scan
46+
image: python:3.12-slim
47+
script:
48+
- pip install --quiet ai-bom
49+
- |
50+
ARGS="scan ${TRUSERA_SCAN_TARGET} --format ${TRUSERA_FORMAT} --quiet"
51+
52+
if [ "${TRUSERA_SCAN_LEVEL}" = "deep" ]; then
53+
ARGS="$ARGS --deep"
54+
fi
55+
56+
if [ -n "${TRUSERA_SEVERITY_THRESHOLD}" ]; then
57+
ARGS="$ARGS --fail-on ${TRUSERA_SEVERITY_THRESHOLD}"
58+
fi
59+
60+
ARGS="$ARGS -o ai-bom-results.${TRUSERA_FORMAT}"
61+
echo "Running: ai-bom $ARGS"
62+
ai-bom $ARGS
63+
# Also produce JSON output for policy gate if a policy file is configured
64+
- |
65+
if [ -n "${TRUSERA_CEDAR_POLICY_FILE}" ]; then
66+
JSON_ARGS="scan ${TRUSERA_SCAN_TARGET} --format json --quiet -o ai-bom-policy-results.json"
67+
if [ "${TRUSERA_SCAN_LEVEL}" = "deep" ]; then
68+
JSON_ARGS="$JSON_ARGS --deep"
69+
fi
70+
ai-bom $JSON_ARGS
71+
fi
72+
artifacts:
73+
paths:
74+
- ai-bom-results.*
75+
- ai-bom-policy-results.json
76+
reports:
77+
sast:
78+
- ai-bom-results.sarif
79+
when: always
80+
expire_in: 30 days
81+
82+
trusera-policy-gate:
83+
stage: policy-gate
84+
image: python:3.12-slim
85+
needs:
86+
- trusera-scan
87+
rules:
88+
- if: '$TRUSERA_CEDAR_POLICY_FILE != ""'
89+
script:
90+
- pip install --quiet ai-bom
91+
- |
92+
# Determine which JSON file to use for policy evaluation
93+
if [ -f "ai-bom-policy-results.json" ]; then
94+
RESULTS_FILE="ai-bom-policy-results.json"
95+
elif [ -f "ai-bom-results.json" ]; then
96+
RESULTS_FILE="ai-bom-results.json"
97+
else
98+
echo "Error: No JSON results found for policy evaluation"
99+
exit 2
100+
fi
101+
102+
echo "Evaluating Cedar policy: ${TRUSERA_CEDAR_POLICY_FILE}"
103+
104+
GATE_ARGS="${RESULTS_FILE} ${TRUSERA_CEDAR_POLICY_FILE}"
105+
106+
# Cedar-specific severity threshold (falls back to scan threshold if not set)
107+
SEV="${TRUSERA_FAIL_ON_SEVERITY:-${TRUSERA_SEVERITY_THRESHOLD}}"
108+
if [ -n "${SEV}" ]; then
109+
GATE_ARGS="$GATE_ARGS --fail-on-severity ${SEV}"
110+
fi
111+
112+
if [ -n "${TRUSERA_CEDAR_ENTITIES_FILE}" ]; then
113+
GATE_ARGS="$GATE_ARGS --entities ${TRUSERA_CEDAR_ENTITIES_FILE}"
114+
fi
115+
116+
python3 scripts/cedar-gate.py $GATE_ARGS

0 commit comments

Comments
 (0)