name: Security
on:
push:
branches: [main, develop, "release/*"]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: security-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
semgrep:
name: Semgrep SAST (p/rust + p/secrets)
runs-on: ubuntu-latest
timeout-minutes: 10
container:
image: semgrep/semgrep@sha256:59fbed6127ea7c5dde3ba6a85142733bb20ea9aaa36120c953904f1539aaf66e steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Run semgrep (block on findings)
run: semgrep scan --config p/rust --config p/secrets --error --metrics=off
gitleaks:
name: Gitleaks (full history)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
fetch-depth: 0
- uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_CONFIG_FILE: .gitleaks.toml
vet:
name: Cargo Vet (supply chain)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: cargo-vet
- name: Run cargo vet check (committed Cargo.lock)
run: cargo vet check --locked
sbom:
name: SBOM (CycloneDX)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: cargo-cyclonedx
- name: Generate Cargo.lock (library crate, not committed)
run: cargo generate-lockfile
- name: Generate SBOM (all features)
run: cargo cyclonedx -f json --all-features
- name: Upload SBOM artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 with:
name: sbom-cyclonedx
path: garrison.cdx.json
fuzz-regression:
name: Fuzz Regression (corpus smoke)
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (nightly)
run: bash scripts/setup_rust.sh nightly
shell: bash
- name: Install cargo-fuzz
run: cargo install cargo-fuzz --locked
- name: Fuzz corpus smoke (60s per target)
run: |
for target in fuzz_saml_xml fuzz_oidc_discovery fuzz_jwt_verify fuzz_http_auth_headers; do
echo "::group::$target"
cargo +nightly fuzz run "$target" -- -max_total_time=60
echo "::endgroup::"
done
reproducible-build:
name: Reproducible Build (byte-identical)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- name: Fetch dependencies
run: cargo fetch --locked
- name: Verify byte-identical rebuild
run: scripts/verify_reproducible_build.sh
dismiss-test-fixture-alerts:
name: Dismiss test-fixture code scanning alerts
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 10
concurrency:
group: dismiss-alerts-${{ github.run_id }}
cancel-in-progress: false
permissions:
contents: read
security-events: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Dismiss open alerts classified as test fixtures (used_in_tests)
run: |
set -uo pipefail
repo="${{ github.repository }}"
# 2026-11-14 API 漂移对齐(0.9.0 发布轮实测):
# 1) GraphQL 侧 `Repository.codeScanningAlerts` 与 `Mutation.resolveSecurityAlert`
# 均已不在当前 schema(undefinedField),探针与 mutation 路径整体移除;
# 2) PATCH 端点仅接受 `state` + `dismissed_reason`(注意过去分词 dismissed),
# `dismissal_reason` / `dismissal_comment` 均报 422 not permitted——豁免理由
# 改为写进运行日志(本步骤输出即留痕),API 侧不再携带 comment。
# 3) PUT 形(REST 文档旧示例)实测 404,仍只用 PATCH。
echo "=== GET 诊断(状态行 + 令牌权限头)==="
gh api -i "repos/$repo/code-scanning/alerts?state=open&per_page=2" 2>&1 | grep -E "^HTTP|x-github-token-permissions|message" | head -6 || true
alerts="$(gh api "repos/$repo/code-scanning/alerts?state=open&per_page=100" \
--jq '.[] | [.number, .rule.id, .most_recent_instance.location.path, .most_recent_instance.location.start_line] | @tsv' 2>&1)" || {
echo "GET 失败,原样输出:"; echo "$alerts" | tail -5; exit 1; }
count=0
while IFS=$'\t' read -r num rule path line; do
[ -n "$num" ] || continue
case "$rule" in
rust/hard-coded-cryptographic-value|rust/cleartext-logging) ;;
*)
echo "SKIP(非测试夹具类,需人工分诊): #$num $rule $path:$line"
continue
;;
esac
echo "豁免理由(API 已不支持 dismissal_comment,留痕于此):[$rule] 测试夹具/测试代码($path:$line,已逐条人工核实):固定占位密钥与本地化错误文案断言,非真实凭证泄漏;生产路径敏感值由 mask_metadata 与 inklog secret-scan 出站门控覆盖。"
if gh api -X PATCH "repos/$repo/code-scanning/alerts/$num" \
-f state=dismissed \
-f dismissed_reason="used in tests" \
--silent; then
count=$((count + 1))
echo "dismissed #$num $rule $path:$line"
else
echo "FAILED #$num $rule $path:$line"
fi
done <<< "$alerts"
echo "共豁免 $count 条"
workflow-hygiene:
name: Workflow Hygiene (actionlint + zizmor)
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: actionlint
uses: docker://rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 with:
args: -color -shellcheck=error
- name: zizmor (GitHub Actions 安全审计)
uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd with:
persona: regular