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
27 changes: 11 additions & 16 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ workflows:
- 'actions/checkout@v7.0.1'
'.github/workflows/ci.yml':
- 'actions/checkout@v7.0.1'
- 'actions/upload-artifact@v7.0.1'
- 'actions/upload-artifact@v7.0.2'
- 'goto-bus-stop/setup-zig@v2.2.1'
'.github/workflows/codeql.yml':
- 'actions/checkout@v7.0.1'
Expand Down Expand Up @@ -37,7 +37,7 @@ workflows:
- 'actions/configure-pages@v6.0.0'
- 'actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346'
- 'actions/upload-pages-artifact@v5.0.0'
- 'haskell-actions/setup@v2.12.0'
- 'haskell-actions/setup@v2.12.1'
'.github/workflows/quality.yml':
- 'actions/checkout@v7.0.1'
- 'editorconfig-checker/action-editorconfig-checker@51f63319f592f97930c73d9c46184d20bd206393'
Expand All @@ -61,8 +61,8 @@ workflows:
- 'sonarsource/sonarqube-scan-action@v8.4.1'
'.github/workflows/static-analysis-gate.yml':
- 'actions/checkout@v7.0.1'
- 'actions/download-artifact@v8.0.1'
- 'actions/upload-artifact@v7.0.1'
- 'actions/download-artifact@v8.0.2'
- 'actions/upload-artifact@v7.0.2'
- 'erlef/setup-beam@v1.24.1'
'.github/workflows/test-suite.yml':
- 'actions/checkout@v7.0.1'
Expand Down Expand Up @@ -109,25 +109,20 @@ dependencies:
owner_id: 44036562
repo_id: 513659658
'actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346':
ref: '368f82528645a54fb793d4d04e342629a3f51346'
ref: 'v5.0.1'
commit: 'sha1-368f82528645a54fb793d4d04e342629a3f51346'
owner_id: 44036562
repo_id: 438112499
'actions/download-artifact@v8.0.1':
ref: 'v8.0.1'
commit: 'sha1-3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c'
'actions/download-artifact@v8.0.2':
ref: 'v8.0.2'
commit: 'sha1-9000827ccba6bdab643e8b6fd33ac0654aef8333'
owner_id: 44036562
repo_id: 192626254
'actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f':
ref: 'v7.0.0'
commit: 'sha1-bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
owner_id: 44036562
repo_id: 192625955
'actions/upload-artifact@v7.0.1':
ref: 'v7.0.1'
commit: 'sha1-043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
owner_id: 44036562
repo_id: 192625955
'actions/upload-artifact@v7.0.2':
ref: 'v7.0.2'
commit: 'sha1-cf430e030ddbb5b0abf93d22962f4752f3646cd9'
Expand Down Expand Up @@ -165,9 +160,9 @@ dependencies:
commit: 'sha1-abea47f85e598557f500fa1fd2ab7464fcb39406'
owner_id: 1006268
repo_id: 212984112
'haskell-actions/setup@v2.12.0':
ref: 'v2.12.0'
commit: 'sha1-6037f33647c3f17758a2356c80fc4a53d7e0685d'
'haskell-actions/setup@v2.12.1':
ref: 'v2.12.1'
commit: 'sha1-0f8e8c99d88aeb3fbfd523f1ef2c6f762d10d64d'
owner_id: 75048950
repo_id: 623796603
'leanprover/lean-action@ba3fdfe5c4476c925da13bf11a005ddb47e47aee':
Expand Down
58 changes: 36 additions & 22 deletions .github/workflows/workflow-linter.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# This workflow is managed by gh actions-lock.
# SPDX-License-Identifier: MPL-2.0
# This workflow is managed by gh actions-lock.
# This workflow is managed by gh actions-lock.
# This workflow is managed by gh actions-lock.
# workflow-linter.yml - Validates GitHub workflows against RSR security standards
# This workflow can be copied to other repos for consistent enforcement
name: Workflow Security Linter

on:
push:
# A PR push already runs this through pull_request; push runs only on
# main, so each PR push is linted once and main is still checked after merge.
branches:
- main
paths:
- '.github/workflows/**'
- 'scripts/check-action-pinning.js'
- 'scripts/tests/check-action-pinning-test.sh'
pull_request:
paths:
- '.github/workflows/**'
- 'scripts/check-action-pinning.js'
- 'scripts/tests/check-action-pinning-test.sh'
workflow_dispatch:

concurrency:
Expand All @@ -24,7 +29,7 @@ permissions:

jobs:
lint-workflows:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
Expand All @@ -39,13 +44,15 @@ jobs:
failed=0
for file in .github/workflows/*.yml .github/workflows/*.yaml; do
[ -f "$file" ] || continue
if ! head -1 "$file" | grep -q "^# SPDX-License-Identifier:"; then
# actions-lock may prepend its own comment. Require the licence
# in the leading comment block, before the workflow body.
if ! awk '/^# SPDX-License-Identifier:/ { found=1 } /^[[:space:]]*[^#[:space:]]/ { exit } END { exit !found }' "$file"; then
echo "ERROR: $file missing SPDX header"
failed=1
fi
done
if [ $failed -eq 1 ]; then
echo "Add '# SPDX-License-Identifier: MPL-2.0' as first line"
echo "Add '# SPDX-License-Identifier: MPL-2.0' to the leading comment block"
exit 1
fi
echo "All workflows have SPDX headers"
Expand All @@ -67,24 +74,32 @@ jobs:
fi
echo "All workflows have permissions declared"

# Bun is the estate's first-choice runtime (LANGUAGE-POLICY.adoc §1:
# Bun > Deno > pnpm > npm). It is the estate pin 1.4.2, downloaded and
# sha256-checked as Estate Rules installs its tools, so this gate runs
# no third-party action and no unpinned runtime.
- name: Install verified Bun 1.4.2
Comment thread
hyperpolymath marked this conversation as resolved.
Resolved
run: |
curl --proto '=https' --proto-redir '=https' --fail --silent --show-error --location \
https://github.com/oven-sh/bun/releases/download/bun-v1.4.2/bun-linux-x64.zip \
--output "$RUNNER_TEMP/bun.zip"
echo "36368faef7527875d5ffa52e53cd48021741f2a83eb6208a8dd64068d422a913 $RUNNER_TEMP/bun.zip" | sha256sum --check --strict
unzip -q "$RUNNER_TEMP/bun.zip" -d "$RUNNER_TEMP"
echo "$RUNNER_TEMP/bun-linux-x64" >> "$GITHUB_PATH"

# The checker is tested before it judges anything: a gate that has
# regressed to passing everything must fail here, not go green below.
- name: Self-test the pinning checker
run: bash scripts/tests/check-action-pinning-test.sh

- name: Check SHA-Pinned Actions
run: |
echo "=== Checking Action Pinning ==="
# Find any uses: lines that don't have @SHA format
# Pattern: uses: owner/repo@<40-char-hex>
unpinned=$(grep -rnE "^[[:space:]]+uses:" .github/workflows/ | \
grep -v "@[a-f0-9]\{40\}" | \
grep -v "uses: \./\|uses: docker://\|uses: actions/github-script" || true)

if [ -n "$unpinned" ]; then
echo "ERROR: Found unpinned actions:"
echo "$unpinned"
echo ""
echo "Replace version tags with SHA pins, e.g.:"
echo " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6.0.1"
exit 1
fi
echo "All actions are SHA-pinned"
# Every step-level ref must be an inline 40-hex SHA, or be listed
# under its own workflow in actions.lock with a dependency record
# that resolves to a commit (the check GitHub applies at run start).
# Job-level reusable calls must be SHA-pinned. See the script header.
bun scripts/check-action-pinning.js

- name: Check for Duplicate Workflows
run: |
Expand Down Expand Up @@ -118,7 +133,6 @@ jobs:
has_rb=$(find . -name "*.rb" -path "*/lib/*" -o -path "*/app/*" 2>/dev/null | head -1)

echo "Detected languages:"
[ -n "$has_js" ] && echo " - javascript-typescript"
[ -n "$has_py" ] && echo " - python"
[ -n "$has_go" ] && echo " - go"
[ -n "$has_rs" ] && echo " - rust (note: CodeQL rust is limited)"
Expand Down
165 changes: 165 additions & 0 deletions scripts/check-action-pinning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env bun
// SPDX-License-Identifier: MPL-2.0
//
// Assert every workflow action ref is pinned to an immutable commit, and that
// actions.lock covers every step-level ref under the workflow that uses it.
//
// Pinned means EITHER an inline 40-hex SHA, OR a ref that actions.lock lists
// under THIS workflow and resolves through a well-formed dependency record
// (commit `sha1-<40 hex>`, and `ref` equal to the tag in the key). That is the
// per-workflow check GitHub itself applies at run start: a workflow that asks
// for a ref its own lock entry lacks is refused with zero jobs. Measured on
// this repo 2026-11-17: `CI` and `Static Analysis Gate` hit startup_failure
// on PR #67 for exactly that drift, and both ran once the lock was resynced.
//
// Why each rule is here (all found in review of the earlier template copy):
//
// * Workflows are PARSED (Bun.YAML), not matched line by line, so quoted
// refs and flow-style steps (`- { uses: "o/r@main" }`) are seen. A file
// that does not parse is an error, never "no refs found".
// * Coverage is per workflow. A global set accepted a ref because some OTHER
// workflow's lock entry listed it.
// * A workflow-list entry is not proof on its own: its dependency record
// must exist and resolve to a commit.
// * No name-based exemptions. `actions/github-script` used to be skipped by
// substring, which also let `evil-actions/github-script@main` through.
// Only local actions (`./…`) and `docker://` images are not GitHub refs.
// * Job-level reusable-workflow calls (`jobs.<id>.uses`) must be SHA-pinned
// but are not required in the lock: GitHub does not check them there
// (standards#968, measured harmless).
//
// Runtime: Bun (estate first choice). Plain JavaScript, not TypeScript.
// Exit 0 if every ref passes, 1 otherwise (listing file: problem), 2 on a
// usage error. `--root DIR` checks another tree (used by the self-test).

import { readdirSync, readFileSync, existsSync, statSync } from "node:fs";
import { join } from "node:path";

const args = process.argv.slice(2);
const rootIdx = args.indexOf("--root");
const ROOT = rootIdx === -1 ? "." : args[rootIdx + 1];
if (rootIdx !== -1 && !ROOT) {
console.error("usage: check-action-pinning.js [--root DIR]");
process.exit(2);
}
const WF = join(ROOT, ".github/workflows");
const LOCK = join(WF, "actions.lock");
const isSha = (s) => s.length === 40 && /^[0-9a-f]+$/.test(s);

// owner/repo[/path]@ref -> { root: "owner/repo" (lower-cased), ref }
function split(uses) {
const at = uses.lastIndexOf("@");
if (at <= 0 || at === uses.length - 1) return null;
const parts = uses.slice(0, at).split("/");
if (parts.length < 2 || !parts[0] || !parts[1]) return null;
return { root: `${parts[0]}/${parts[1]}`.toLowerCase(), ref: uses.slice(at + 1) };
}

// Every `uses:` in a parsed workflow, tagged step or job level.
function refsOf(doc) {
const out = [];
const jobs = doc && typeof doc === "object" ? doc.jobs : null;
if (!jobs || typeof jobs !== "object") return out;
for (const [id, job] of Object.entries(jobs)) {
if (!job || typeof job !== "object") continue;
if (typeof job.uses === "string") out.push({ level: "job", where: `jobs.${id}`, uses: job.uses.trim() });
if (Array.isArray(job.steps)) {
job.steps.forEach((step, i) => {
if (step && typeof step === "object" && typeof step.uses === "string") {
out.push({ level: "step", where: `jobs.${id}.steps[${i}]`, uses: step.uses.trim() });
}
});
}
}
return out;
}

function loadLock(bad) {

Check failure on line 77 in scripts/check-action-pinning.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_lithoglyphdb&issues=AaHqo5tBQlFEd-4wrzVd&open=AaHqo5tBQlFEd-4wrzVd&pullRequest=68
if (!existsSync(LOCK)) return null;
let lock;
try {
lock = Bun.YAML.parse(readFileSync(LOCK, "utf8"));
} catch (e) {
bad.push(`${LOCK}: does not parse (${e.message})`);
return undefined;
}
if (!lock || typeof lock.workflows !== "object" || typeof lock.dependencies !== "object") {
bad.push(`${LOCK}: missing 'workflows' or 'dependencies' map`);
return undefined;
}
// Dependency records that resolve, keyed by lower-cased owner/repo@ref.
const resolved = new Set();
for (const [key, rec] of Object.entries(lock.dependencies)) {
const k = split(key);
const commit = rec && typeof rec.commit === "string" ? rec.commit : "";
const okCommit = commit.startsWith("sha1-") && isSha(commit.slice(5).toLowerCase());
// A tag key must record that tag; a SHA key must resolve to that SHA.
const okRef = k && (isSha(k.ref) ? commit.toLowerCase() === `sha1-${k.ref}` : rec.ref === k.ref);
if (k && okCommit && okRef) resolved.add(`${k.root}@${k.ref}`);
else bad.push(`${LOCK}: dependency record '${key}' does not resolve to a commit`);
}
// Per-workflow lists, keyed by workflow path relative to the root.
const perWorkflow = new Map();
for (const [path, list] of Object.entries(lock.workflows)) {
const set = new Set();
for (const entry of Array.isArray(list) ? list : []) {
const k = typeof entry === "string" ? split(entry) : null;
if (k) set.add(`${k.root}@${k.ref}`);
}
perWorkflow.set(path, set);
}
return { resolved, perWorkflow };
}

function main() {

Check failure on line 114 in scripts/check-action-pinning.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 35 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_lithoglyphdb&issues=AaHqo5tBQlFEd-4wrzVe&open=AaHqo5tBQlFEd-4wrzVe&pullRequest=68
if (!existsSync(WF) || !statSync(WF).isDirectory()) {
console.log("no .github/workflows — nothing to check");
return 0;
}
const bad = [];
const lock = loadLock(bad);
if (lock) console.log(`lockfile present: ${lock.resolved.size} resolvable record(s)`);
else if (lock === null) console.log("no lockfile — every ref must be an inline 40-character SHA");

const files = readdirSync(WF).filter((f) => f.endsWith(".yml") || f.endsWith(".yaml")).sort();
let count = 0;
for (const f of files) {
const rel = `.github/workflows/${f}`;
let doc;
try {
doc = Bun.YAML.parse(readFileSync(join(WF, f), "utf8"));
} catch (e) {
bad.push(`${rel}: does not parse as YAML (${e.message})`);
continue;
}
const listed = lock ? lock.perWorkflow.get(rel) : undefined;
for (const { level, where, uses } of refsOf(doc)) {
if (uses.startsWith("./") || uses.startsWith("docker://")) continue;
count++;
const k = split(uses);
if (!k) { bad.push(`${rel} ${where}: '${uses}' is not owner/repo@ref`); continue; }
const key = `${k.root}@${k.ref}`;
if (level === "job") {
if (!isSha(k.ref)) bad.push(`${rel} ${where}: reusable workflow '${uses}' is not pinned to a 40-hex commit`);
continue;
}
if (lock) {
if (!listed || !listed.has(key)) bad.push(`${rel} ${where}: '${uses}' is not in this workflow's actions.lock entry`);

Check warning on line 147 in scripts/check-action-pinning.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_lithoglyphdb&issues=AaHqo5tBQlFEd-4wrzVf&open=AaHqo5tBQlFEd-4wrzVf&pullRequest=68
else if (!lock.resolved.has(key)) bad.push(`${rel} ${where}: '${uses}' has no dependency record that resolves to a commit`);
} else if (!isSha(k.ref)) {
bad.push(`${rel} ${where}: '${uses}' is not pinned to a 40-hex commit`);
}
}
}

if (bad.length) {
console.log("\nERROR: unpinned or unlocked action refs:");
for (const b of bad) console.log(` ${b}`);
console.log("\nPin to a full commit SHA, or run `gh actions-lock` so this workflow's lock entry resolves the ref.");
return 1;
}
console.log(`all ${count} action ref(s) in ${files.length} workflow(s) are pinned`);
return 0;
}

process.exit(main());
Loading
Loading