Repository navigation
Update trajan to 1.0.2 - #3669
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #3669 +/- ##
=====================================
+ Coverage 91% 91% +1%
=====================================
Files 465 465
Lines 52188 52188
=====================================
+ Hits 47281 47293 +12
+ Misses 4907 4895 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
📊 Performance Benchmark Report
📈 Detailed Results (All Benchmarks)
🎯 Performance Summary+ 1 improvement 🚀
30 unchanged ✅🔍 Significant Changes (>10%)
🐍 Python Version 3.12.3 |
en0f
approved these changes
Nov 20, 2026
en0f
left a comment
There was a problem hiding this comment.
Reviewed at 21d7e87.
Reproduce this review
# save the script below as verify-3669.sh, then:
bash verify-3669.sh blacklanternsecurity/bbot 21d7e87236b185e1ff1b579af8a605dd2fc8b7d6
# expected: SUMMARY 9 PASS, 2 FAIL, 0 SKIP, 0 BROKEN (V09 and V11 are pre-existing, outside this bump)
# control: bash verify-3669.sh blacklanternsecurity/bbot 1ead7cc262c7608aaf123d7f6fbbf6b671aa8005 -> V01=FAIL#!/usr/bin/env bash
# verify-3669.sh: reproducible checks for blacklanternsecurity/bbot#3669 (trajan 1.0.0 -> 1.0.2)
# Usage: bash verify-3669.sh <owner/repo> <sha> [<control-patch>]
# Changes nothing outside a mktemp directory and nothing on GitHub (PR-VF-02).
# The trajan binary is downloaded and checksummed, never executed.
#
# CONTROL: sha 1ead7cc262c7608aaf123d7f6fbbf6b671aa8005
# CONTROL-EXPECT: V01=FAIL
# AUTHOR-CODE: none
set -uo pipefail
REPO="${1:?owner/repo}"; SHA="${2:?sha}"; PATCH="${3:-}"
PASS=0; FAIL=0; SKIP=0; BROKEN=0
pass() { echo "PASS $1 $2"; PASS=$((PASS+1)); }
fail() { echo "FAIL $1 $2 -- $3"; FAIL=$((FAIL+1)); }
skip() { echo "SKIP $1 $2 -- $3"; SKIP=$((SKIP+1)); }
broken() { echo "BROKEN $1 $2 -- $3"; BROKEN=$((BROKEN+1)); }
summary() { echo "SUMMARY $PASS PASS, $FAIL FAIL, $SKIP SKIP, $BROKEN BROKEN"; [ "$FAIL" -eq 0 ] && [ "$BROKEN" -eq 0 ]; }
echo "script_sha256 $(shasum -a 256 "$0" | cut -d' ' -f1)"
echo "git $(git --version | cut -d' ' -f3)"
echo "curl $(curl --version | head -1 | cut -d' ' -f2)"
echo "python3 $(python3 -c 'import platform; print(platform.python_version())')"
echo "gh $(gh --version | head -1 | cut -d' ' -f3)"
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0
GIT=(git -c credential.helper= -c 'credential.helper=!gh auth git-credential')
"${GIT[@]}" clone --quiet --filter=blob:none --no-checkout "https://github.com/$REPO.git" "$WORK/src" || { broken V00 "clone" "clone failed"; summary; exit 1; }
cd "$WORK/src"
"${GIT[@]}" cat-file -e "$SHA^{commit}" 2>/dev/null || "${GIT[@]}" fetch --quiet origin "+refs/pull/*/head:refs/remotes/pr/*" || true
"${GIT[@]}" checkout --quiet --detach "$SHA" || { broken V00 "checkout $SHA" "checkout failed"; summary; exit 1; }
[ "$(git rev-parse HEAD)" = "$SHA" ] || { broken V00 "HEAD is $SHA" "HEAD mismatch"; summary; exit 1; }
if [ -n "$PATCH" ]; then git apply "$PATCH" || { broken V00 "apply control patch" "git apply failed"; summary; exit 1; }; fi
MOD=bbot/modules/trajan.py
VER="$(python3 -I -c 'import re,sys; m=re.search(r"version: VersionStr = Field\(\"([0-9.]+)\"", open(sys.argv[1]).read()); print(m.group(1) if m else "")' "$MOD")"
[ -n "$VER" ] || { broken V00 "read pinned trajan version" "no version Field in $MOD"; summary; exit 1; }
echo "pinned_trajan $VER"
UP=praetorian-inc/trajan
gh api --method GET "repos/$UP/releases/latest" > "$WORK/latest.json" 2>/dev/null || { broken V00 "read trajan releases/latest" "gh api failed"; summary; exit 1; }
gh api --method GET "repos/$UP/releases/tags/v$VER" > "$WORK/rel.json" 2>/dev/null || echo '{}' > "$WORK/rel.json"
LATEST="$(python3 -I -c 'import json,sys; print(json.load(open(sys.argv[1]))["tag_name"].lstrip("v"))' "$WORK/latest.json")"
echo "latest_trajan $LATEST"
# ---- checks: each line states the desired property --------------------------
# V01: the module pins the newest stable trajan release
if [ "$VER" = "$LATEST" ]; then pass V01 "trajan.py pins the latest stable trajan release ($LATEST)"
else fail V01 "trajan.py pins the latest stable trajan release ($LATEST)" "pinned $VER"; fi
# V02: every asset bbot's deps_ansible URL resolves to exists for the pinned version
# URL template: trajan_#{VERSION}_#{BBOT_OS}_#{BBOT_CPU_ARCH_GOLANG}.tar.gz
MISSING="$(python3 -I -c '
import json,sys
names={a["name"] for a in json.load(open(sys.argv[1])).get("assets",[])}
v=sys.argv[2]
want=[f"trajan_{v}_{o}_{a}.tar.gz" for o in ("linux","darwin") for a in ("amd64","arm64")]
print(" ".join(w for w in want if w not in names))' "$WORK/rel.json" "$VER")"
if [ -z "$MISSING" ]; then pass V02 "v$VER publishes the tar.gz for linux/darwin x amd64/arm64 that deps_ansible downloads"
else fail V02 "v$VER publishes the tar.gz for linux/darwin x amd64/arm64 that deps_ansible downloads" "missing: $MISSING"; fi
# V09: the URL deps_ansible builds on macOS resolves to a published asset.
# bbot sets BBOT_OS from os_platform_friendly(), which returns "macOS" on darwin;
# BBOT_OS_PLATFORM is the raw "darwin". Pre-existing (same template at the base).
OSF="$(python3 -I -c '
import re,sys
s=open(sys.argv[1]).read()
m=re.search(r"def os_platform_friendly\(\):.*?if p == \"darwin\":\s*return \"(\w+)\"", s, re.S)
print(m.group(1) if m else "darwin")' bbot/core/helpers/misc.py)"
OSVAR="$(grep -oE '#\{BBOT_OS(_PLATFORM)?\}_#\{BBOT_CPU_ARCH_GOLANG\}' "$MOD" | head -1)"
case "$OSVAR" in *BBOT_OS_PLATFORM*) MACOS=darwin;; *) MACOS="$OSF";; esac
MACASSET="trajan_${VER}_${MACOS}_arm64.tar.gz"
if python3 -I -c 'import json,sys; sys.exit(0 if any(a["name"]==sys.argv[2] for a in json.load(open(sys.argv[1])).get("assets",[])) else 1)' "$WORK/rel.json" "$MACASSET"; then
pass V09 "on macOS, deps_ansible resolves to a published asset ($MACASSET)"
else fail V09 "on macOS, deps_ansible resolves to a published asset" "template uses $OSVAR -> $MACASSET, not published (asset is darwin)"; fi
# V03/V04: the linux_amd64 tarball matches the vendor checksum (and the API digest) and holds a root-level 'trajan' member
ASSET="trajan_${VER}_linux_amd64.tar.gz"
BASEURL="https://github.com/$UP/releases/download/v$VER"
if curl -fsSLo "$WORK/$ASSET" "$BASEURL/$ASSET" && curl -fsSLo "$WORK/checksums.txt" "$BASEURL/checksums.txt"; then
SUM="$(awk -v f="$ASSET" '$2==f{print $1}' "$WORK/checksums.txt")"
APIDIG="$(python3 -I -c 'import json,sys; print(next((a.get("digest") or "" for a in json.load(open(sys.argv[1]))["assets"] if a["name"]==sys.argv[2]),"").removeprefix("sha256:"))' "$WORK/rel.json" "$ASSET")"
GOT="$(shasum -a 256 "$WORK/$ASSET" | cut -d' ' -f1)"
if [ -n "$SUM" ] && [ "$GOT" = "$SUM" ] && { [ -z "$APIDIG" ] || [ "$GOT" = "$APIDIG" ]; } \
&& tar tzf "$WORK/$ASSET" > "$WORK/members.txt" && grep -qx 'trajan' "$WORK/members.txt"; then
pass V03 "$ASSET matches checksums.txt and the release API digest, and contains the 'trajan' member deps_ansible extracts"
else
fail V03 "$ASSET matches checksums.txt and the release API digest, and contains the 'trajan' member deps_ansible extracts" "got=$GOT checksums=$SUM api=$APIDIG"
fi
if echo "0000000000000000000000000000000000000000000000000000000000000000 $WORK/$ASSET" | shasum -a 256 -c - >/dev/null 2>&1; then
broken V04 "wrong-hash control is rejected" "accepted a wrong hash"
else pass V04 "wrong-hash control is rejected"; fi
else
skip V03 "$ASSET matches checksums.txt and contains 'trajan'" "download failed"
skip V04 "wrong-hash control is rejected" "download failed"
fi
# Upstream source at the pinned tag (read, never built or run)
"${GIT[@]}" clone --quiet --filter=blob:none --no-checkout "https://github.com/$UP.git" "$WORK/trajan" \
&& git -C "$WORK/trajan" rev-parse -q --verify "refs/tags/v$VER^{commit}" >/dev/null \
&& echo "trajan_tag v$VER $(git -C "$WORK/trajan" rev-parse "v$VER^{commit}")" \
|| { broken V05 "clone trajan at v$VER" "clone or tag failed"; summary; exit 1; }
show() { git -C "$WORK/trajan" show "v$VER:$1" 2>/dev/null; }
flags() { for f in "$@"; do show "$f"; done | grep -E 'Flags\(\)\.' | grep -oE '(\(&[A-Za-z.]+, |String\()"[a-z-]+"' | grep -oE '"[a-z-]+"' | tr -d '"' | sort -u; }
# V05: every flag execute_trajan passes exists on that subcommand at v$VER
ROOTF="$(flags cmd/trajan/root.go)"
MISS=""
need() { local sub="$1"; shift; local have; have="$(printf '%s\n%s\n' "$ROOTF" "$(flags cmd/trajan/$sub/scan.go cmd/trajan/$sub/root.go)")"
for fl in "$@"; do printf '%s\n' "$have" | grep -x "$fl" >/dev/null || MISS="$MISS $sub:--$fl"; done; }
need github repo output token
need gitlab project output token
need ado org repo output token
need jfrog url secrets output token
need jenkins url repo output token username password
if [ -z "$MISS" ]; then pass V05 "trajan v$VER defines every flag trajan.py passes to github/gitlab/ado/jfrog/jenkins scan"
else fail V05 "trajan v$VER defines every flag trajan.py passes to github/gitlab/ado/jfrog/jenkins scan" "missing:$MISS"; fi
# V10: trajan.py passes the -o shorthand, so the root command must still define it for --output (challenge C6)
if show cmd/trajan/root.go | grep -E 'PersistentFlags\(\)\.StringVarP\(&output, "output", "o"' >/dev/null; then
pass V10 "trajan v$VER root command defines -o as the shorthand for --output"
else fail V10 "trajan v$VER root command defines -o as the shorthand for --output" "not found in cmd/trajan/root.go"; fi
# V11: the deps installer's setup_status key changes when the trajan version changes (challenge C8).
# _module_hash() hashes the preloaded deps (the deps_ansible literal, placeholder unsubstituted) plus bbot __version__.
# Pre-existing: compares this tree's literal with its first parent's.
DEPSCMP="$(python3 -I -c '
import ast,json,subprocess,sys
def d(s):
for n in ast.walk(ast.parse(s)):
if isinstance(n,ast.Assign) and any(getattr(t,"id",None)=="deps_ansible" for t in n.targets):
return json.dumps(ast.literal_eval(n.value),sort_keys=True)
cur=open("bbot/modules/trajan.py").read()
try: par=subprocess.check_output(["git","show","HEAD~1:bbot/modules/trajan.py"],stderr=subprocess.DEVNULL).decode()
except Exception: print("NOPARENT"); sys.exit()
print("SAME" if d(cur)==d(par) else "DIFF")')"
case "$DEPSCMP" in
DIFF) pass V11 "the trajan version change alters the deps setup_status hash input";;
SAME) fail V11 "the trajan version change alters the deps setup_status hash input" "deps_ansible literal identical to HEAD~1; installs at the same bbot version keep the old binary";;
*) skip V11 "the trajan version change alters the deps setup_status hash input" "no parent commit";;
esac
# V06: the JSON keys parse_findings / parse_jfrog_results read are still emitted at v$VER
# (grep a file, not a pipe: grep -q exiting early SIGPIPEs printf, and pipefail turns that into a false miss)
{ show internal/cmdutil/scan.go; show pkg/detections/finding.go; show cmd/trajan/jfrog/scan.go; show pkg/jfrog/artifacts.go; show pkg/jfrog/types.go; } > "$WORK/jsonsrc.go"
MISSK=""
for k in findings type severity evidence workflow artifactSecrets buildSecrets secretTypes artifact path buildName buildNumber envVar; do
grep -qE "json:\"$k[,\"]" "$WORK/jsonsrc.go" || MISSK="$MISSK $k"; done
if [ -z "$MISSK" ]; then pass V06 "trajan v$VER JSON output still carries every key trajan.py parses"
else fail V06 "trajan v$VER JSON output still carries every key trajan.py parses" "missing:$MISSK"; fi
# V07: every trajan severity, upper-cased, is a severity bbot's FINDING accepts
BAD="$(python3 -I -c '
import re,sys
trajan=set(re.findall(r"Severity\w* +Severity = \"(\w+)\"", sys.stdin.read()))
src=open(sys.argv[1]).read()
m=re.search(r"_severity_order = \[([^\]]*)\]", src)
bbot=set(re.findall(r"\"(\w+)\"", m.group(1))) if m else set()
print("NOBBOT" if not bbot else ("NOTRAJAN" if not trajan else " ".join(sorted(s for s in trajan if s.upper() not in bbot))))' bbot/core/event/base.py < <(show pkg/detections/finding.go))"
case "$BAD" in
NOBBOT|NOTRAJAN) broken V07 "trajan severities map onto bbot severities" "could not parse ($BAD)";;
"") pass V07 "every trajan v$VER severity, upper-cased, is a bbot FINDING severity";;
*) fail V07 "every trajan v$VER severity, upper-cased, is a bbot FINDING severity" "unmapped: $BAD";;
esac
# V08: the module's own test ran green in CI at this SHA
if [ -f bbot/test/test_step_2/module_tests/test_module_trajan.py ]; then
CR="$(gh api --method GET "repos/$REPO/commits/$SHA/check-runs" --paginate -q '.check_runs[] | select(.name|test("^test / test \\(")) | .conclusion' 2>/dev/null | sort -u | tr '\n' ' ')"
if [ -z "$CR" ]; then skip V08 "test_module_trajan ran green in CI (test / test matrix) at $SHA" "no test matrix check runs at this SHA"
elif [ "$CR" = "success " ]; then pass V08 "test_module_trajan ran green in CI (test / test matrix) at $SHA"
else fail V08 "test_module_trajan ran green in CI (test / test matrix) at $SHA" "conclusions: $CR"; fi
else fail V08 "test_module_trajan exists" "missing"; fi
# ------------------------------------------------------------------------------
summary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR uses https://api.github.com/repos/praetorian-inc/trajan/releases/latest to obtain the latest version of trajan and update the version in bbot/modules/trajan.py.
Release notes:
Changelog