Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/threat-model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Threat model anchor check

on:
push:
branches: [main]
paths:
- 'docs/THREAT_MODEL.md'
- 'docs/SECURITY.md'
- 'SECURITY.md'
- 'contracts/**'
- 'packages/**'
- 'services/**'
- 'scripts/check-threat-model-anchors.mjs'
- 'scripts/check-threat-model-anchors.test.mjs'
- 'scripts/threat-model-ci.test.mjs'
- 'package.json'
- '.github/workflows/threat-model.yml'
pull_request:
paths:
- 'docs/THREAT_MODEL.md'
- 'docs/SECURITY.md'
- 'SECURITY.md'
- 'contracts/**'
- 'packages/**'
- 'services/**'
- 'scripts/check-threat-model-anchors.mjs'
- 'scripts/check-threat-model-anchors.test.mjs'
- 'scripts/threat-model-ci.test.mjs'
- 'package.json'
- '.github/workflows/threat-model.yml'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
threat-model:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# Read-only workflow: downstream steps do not push
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: pnpm/action-setup@v4
with:
version: 10.13.1

- uses: actions/setup-node@v4
with:
node-version: "22"
cache: pnpm

- name: Install JS dependencies
run: pnpm install --frozen-lockfile --ignore-scripts

- name: Check threat-model workflow configuration
run: node --test scripts/threat-model-ci.test.mjs

- name: Run threat-model anchor script tests
run: pnpm threat-model:test

- name: Validate threat-model anchors
run: pnpm threat-model:check
16 changes: 16 additions & 0 deletions docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ print order are asserted by:
node --test scripts/check-bindings-cli.test.mjs
```

## Threat-model anchor check

The `Threat model anchor check` workflow (`.github/workflows/threat-model.yml`)
runs when threat-model docs, security docs, or security-relevant code paths
change (`docs/THREAT_MODEL.md`, `SECURITY.md`, `docs/SECURITY.md`,
`contracts/**`, `packages/**`, `services/**`, and the checker scripts). Its
blocking job installs locked JS dependencies with lifecycle scripts disabled,
then runs `pnpm threat-model:test` and `pnpm threat-model:check` in order so
`docs/THREAT_MODEL.md` keeps the five required sealed-round risk anchors.

```bash
pnpm threat-model:test # unit tests for the anchor checker
pnpm threat-model:check # docs/THREAT_MODEL.md must cover required anchors
node --test scripts/threat-model-ci.test.mjs # verifies the CI wiring
```

## Rust dependency advisory audit

Rust dependencies in the committed `Cargo.lock` are audited against the RustSec
Expand Down
51 changes: 51 additions & 0 deletions scripts/threat-model-ci.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2026 Sub Rosa contributors
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";

const workflow = readFileSync(
new URL("../.github/workflows/threat-model.yml", import.meta.url),
"utf8",
);
const scripts = JSON.parse(
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
).scripts;

test("threat-model CI runs threat-model:test and threat-model:check as blocking steps", () => {
assert.equal(
scripts["threat-model:check"],
"node scripts/check-threat-model-anchors.mjs docs/THREAT_MODEL.md",
);
assert.equal(
scripts["threat-model:test"],
"node --test scripts/check-threat-model-anchors.test.mjs",
);

assert.match(workflow, /^permissions:\n(?:\s+#.*\n)* contents: read$/m);
assert.match(
workflow,
/^concurrency:\n(?:\s+#.*\n)* group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.ref \}\}\n cancel-in-progress: true$/m,
);
assert.doesNotMatch(workflow, /\bcontinue-on-error\s*:/);

assert.match(workflow, /docs\/THREAT_MODEL\.md/);
assert.match(workflow, /SECURITY\.md/);
assert.match(workflow, /contracts\/\*\*/);
assert.match(workflow, /packages\/\*\*/);
assert.match(workflow, /services\/\*\*/);

const job = workflow.match(/^ threat-model:\n([\s\S]*)$/m)?.[1];
assert.ok(job, "threat-model job must exist");
assert.doesNotMatch(job, /^ [a-z][\w-]*:/m, "checks must stay in the threat-model job");

let previousStep = -1;
for (const step of [
"node --test scripts/threat-model-ci.test.mjs",
"pnpm threat-model:test",
"pnpm threat-model:check",
]) {
const index = job.indexOf(` run: ${step}\n`);
assert.ok(index > previousStep, `${step} must run as a blocking step in order`);
previousStep = index;
}
});