openvibers/openvibe-git Commits
Forge CI runs GitHub's security checks too: the secret scan and the dependency audit (#128)
Changes
@@@ -65,6 +65,18 @@ ln -sfn "$NODE_DIR" /opt/openvibe-node/currentchown -R root:root /opt/openvibe-nodeexport PATH="/opt/openvibe-node/current/bin:$PATH"++# gitleaks for the run's secret scan (runner/security.js): the version and checksum openvibe-shared's security.yml pins.++GITLEAKS_VERSION=${GITLEAKS_VERSION:-8.30.1}++GITLEAKS_SHA256=${GITLEAKS_SHA256:-551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb}++if ! /usr/local/bin/gitleaks version 2>/dev/null | grep -q "$GITLEAKS_VERSION"; then++ TMP=$(mktemp -d)++ curl -fsSL "https://github.com/gitleaks/gitleaks/releases/download/v$GITLEAKS_VERSION/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" -o "$TMP/g.tar.gz"++ echo "$GITLEAKS_SHA256 $TMP/g.tar.gz" | sha256sum -c --quiet -++ tar -xzf "$TMP/g.tar.gz" -C "$TMP" gitleaks++ install -o root -g root -m 0755 "$TMP/gitleaks" /usr/local/bin/gitleaks++ rm -rf "$TMP"++fi++# pnpm into /usr (bubblewrap binds the host's /usr read-only).if ! command -v pnpm >/dev/null 2>&1 || [ "$(pnpm --version 2>/dev/null)" != "$PNPM_VERSION" ]; thennpm install -g --no-audit --no-fund "pnpm@$PNPM_VERSION" >/dev/null@@@ -150,6 +150,13 @@ repositories) to `ov-node-01` (8 cores, 15 GB):- **The verdict** is the forge's `forge/test` status; the node has no GitHub login, so it does not post to GitHub(`"githubStatus": false`). The ship scripts read the forge's verdict directly.++- **GitHub's security checks, in the run** (`runner/security.js`, 2026-11-19): a gitleaks scan of the pushed commit's++ files (the repository's own `.gitleaks.toml` or `.github/gitleaks.toml`; no network) before the install, and++ `npm audit` / `pnpm audit` for every lockfile through the install proxy after it, failing at the repository's++ `audit_fail_level` (critical by default, as openvibe-shared's security.yml: high is reported, not enforced; or++ `high`, or `none`). Findings fail the run after the tests have run, and the description names them. gitleaks is++ the version and checksum security.yml pins, installed at /usr/local/bin by `node-setup.sh`.++Each run's description says where the time went: `Forge runner passed in 2m 10s (install 3s from the cache, tests2m 4s)`.@@@ -72,6 +72,9 @@ function loadConfig(env = process.env) {// The test phase's OV_TEST_TIMEOUT_SCALE (openvibe-shared/test-runner 4.323.0 and later): a runner slower or busier// than the machines a repository's per-file limits were set on stretches them (the shared node: 2).testTimeoutScale: Math.min(10, Math.max(1, Number(raw.testTimeoutScale) || 1)),++ // GitHub's security workflow, in the run (runner/security.js): the secret scan and the dependency audit.++ secretScan: raw.secretScan !== false,++ audit: raw.audit !== false,// Host folders shown read-only in both phases (runner/sandbox.js safeRoBinds): the node shows /opt/google (Chrome).roBinds: Array.isArray(raw.roBinds) ? raw.roBinds.map(String).slice(0, 20) : [],// Installs kept between runs (runner/deps-cache.js) and the package managers' download caches. Both live on@@@ -99,6 +102,8 @@ function loadConfig(env = process.env) {image: String((item && item.image) || cfg.image),cpus: int(item && item.cpus, 4, 1, 8),memory_mb: int(item && item.memory_mb, 6144, 512, 12288),++ // As security.yml's audit-fail-level: critical (default), high, or none (report only).++ audit_fail_level: ['critical', 'high', 'none'].includes(item && item.audit_fail_level) ? item.audit_fail_level : 'critical',},]));if (!cfg.token) throw new Error(`no runner token: write it to ${tokenFile} (0600) or set GIT_CI_RUNNER_TOKEN`);@@@ -13,7 +13,8 @@ const { createProxy } = require('./proxy');const { runProcess } = require('./process');const { podmanArgs, bwrapArgs, bwrapScope, installScript, podmanCleanup, scopeCleanup, detectEngine, RELAY } = require('./sandbox');const { reportGithubStatus } = require('./github-status');--const { createDepsCache, cacheKey, survey, installed, autoCommands } = require('./deps-cache');++const { createDepsCache, cacheKey, survey, installed, autoCommands, lockfilesIn } = require('./deps-cache');++const security = require('./security');@@@ -191,6 +192,22 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {}}++ // GitHub's security workflow, here (runner/security.js): what they find fails the run, after the tests ran.++ const problems = [];++ if (!state && cfg.secretScan) {++ const scan = await phase('secrets', installScript(security.secretScanScript(), { proxy: false }), null);++ if (superseded) state = 'superseded';++ else if (scan.code === 0) onData('secret scan: nothing found\n');++ else if (scan.code === 1) {++ const found = security.readSecretFindings(runDir);++ if (found.length) {++ for (const f of found.slice(0, 20)) onData(`secret scan: ${f.rule} at ${f.file}:${f.line} (redacted)\n`);++ onData('A real secret: rotate it first, then remove it. A proven false positive: a narrow [[allowlists]] entry (path AND value) in .gitleaks.toml.\n');++ problems.push(`secret scan: ${found.length} finding${found.length === 1 ? '' : 's'}`);++ } else onData('secret scan: findings only in the runner\'s own folders, ignored\n');++ } else if (scan.code === 3) { /* said so in its own output */ } else onData(`secret scan could not run (exit ${scan.code}); not counted\n`);++ }++let installMs = 0;let fromCache = false;if (!state) {@@@ -225,14 +242,37 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {}}}++ const repoConf = cfg.repos[String(job.repo.full_name || '').toLowerCase()] || {};++ const auditLevel = repoConf.audit_fail_level || 'critical';++ if (!state && cfg.audit && auditLevel !== 'none') {++ const locks = lockfilesIn(runDir);++ if (locks.length) {++ proxy = createProxy({ allow: cfg.proxyAllow, log: { warn: (line) => onData(`${line}\n`) } });++ const socket = path.join(runDir, '.ci', 'proxy.sock');++ await proxy.listen(socket);++ await phase('audit', installScript(security.auditScript(locks)), socket);++ await proxy.close().catch(() => {});++ proxy = null;++ if (superseded) state = 'superseded';++ const results = security.readAuditCounts(runDir, locks);++ for (const r of results) {++ onData(r.counts++ ? `audit ${r.lockfile}: ${security.LEVELS.map((l) => `${r.counts[l]} ${l}`).join(', ')}\n`++ : `audit ${r.lockfile}: no answer (the registry unreachable?); nothing was checked\n`);++ }++ const failing = security.auditFailures(results, auditLevel);++ if (failing.length) problems.push(`dependency audit (${auditLevel}): ${failing.join('; ')}`.slice(0, 300));++ }++ }if (!state) {const t1 = clock();const test = await phase('test', installScript(commands.test, { proxy: false }), null);const timing = `install ${words(installMs)}${fromCache ? ' from the cache' : ''}, tests ${words(clock() - t1)}`;if (superseded) state = 'superseded';else if (test.timedOut) { state = 'timed_out'; description = `Timed out after ${words(totalMs)}`; }-- else if (test.code === 0) { state = 'success'; description = `Forge runner passed in ${words(clock() - started)} (${timing})`; }-- else { state = 'failure'; exitCode = test.code; description = `Forge runner failed (exit ${test.code}) in ${words(clock() - started)} (${timing})`; }++ else if (test.code === 0 && !problems.length) { state = 'success'; description = `Forge runner passed in ${words(clock() - started)} (${timing})`; }++ else if (test.code === 0) { state = 'failure'; exitCode = 1; description = `Forge runner failed: ${problems.join('; ')} (tests passed; ${timing})`; }++ else { state = 'failure'; exitCode = test.code; description = `Forge runner failed (exit ${test.code}) in ${words(clock() - started)} (${timing})${problems.length ? `; also ${problems.join('; ')}` : ''}`; }}} catch (err) {if (superseded) state = 'superseded';nnew file mode 100644@@@ -0,0 +1,75 @@++'use strict';++++/**++ * The checks GitHub's security workflow (openvibe-shared .github/workflows/security.yml) runs, in the forge's own run++ * (2026-11-19, the owner: "handle CI with our own system"), so forge/test is the whole verdict:++ *++ * secrets gitleaks over the pushed commit's files, in the sandbox with no network, with the repository's own++ * .gitleaks.toml (or .github/gitleaks.toml). A finding fails the run. A runner without gitleaks says so and++ * skips it (/usr/local/bin/gitleaks on the shared node, the version security.yml pins).++ * audit npm audit / pnpm audit for every lockfile in the checkout, through the install proxy (the registry's++ * advisories), failing at the repository's audit_fail_level: critical by default, as security.yml (high++ * is reported, not enforced), or high, or none. An audit that returns nothing (the registry unreachable)++ * is reported and checks nothing, as on GitHub.++ */++const fs = require('node:fs');++const path = require('node:path');++++const LEVELS = ['critical', 'high', 'moderate', 'low'];++++const q = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;++++/** The secret scan's script: exit 0 clean, 1 findings (gitleaks' own), 3 no gitleaks here, anything else an error. */++function secretScanScript() {++ return [++ 'command -v gitleaks >/dev/null 2>&1 || { echo "secret scan: gitleaks is not installed on this runner"; exit 3; }',++ 'cfg=""',++ '[ -f .gitleaks.toml ] && cfg="--config .gitleaks.toml"',++ '[ -z "$cfg" ] && [ -f .github/gitleaks.toml ] && cfg="--config .github/gitleaks.toml"',++ // The runner's own folders are not the repository's.++ 'mkdir -p .ci',++ 'gitleaks dir . $cfg --no-banner --redact --report-format json --report-path .ci/gitleaks.json --exit-code 1 --log-level warn',++ ].join('\n');++}++++/** What the scan found: the findings without their secrets (gitleaks redacts them), the runner's folders left out. */++function readSecretFindings(runDir) {++ let rows = [];++ try { rows = JSON.parse(fs.readFileSync(path.join(runDir, '.ci', 'gitleaks.json'), 'utf8')); } catch { return []; }++ return (Array.isArray(rows) ? rows : [])++ .filter((r) => r && r.File && !/^(\.\/)?\.(ci|home|cache|pnpm)\//.test(String(r.File)))++ .map((r) => ({ rule: String(r.RuleID || ''), file: String(r.File).replace(/^\.\//, ''), line: Number(r.StartLine) || 0 }));++}++++/** The audit's script: one JSON report per lockfile under the checkout's .ci, whatever the audit's own exit code. */++function auditScript(lockfiles) {++ const lines = ['ROOT=$(pwd)', 'mkdir -p "$ROOT/.ci"'];++ lockfiles.forEach((lf, i) => {++ const dir = path.posix.dirname(lf);++ const out = `.ci/audit-${i}.json`;++ if (lf.endsWith('pnpm-lock.yaml')) lines.push(`(cd ${q(dir)} && pnpm audit --json > "$ROOT/"${q(out)} 2>/dev/null) || true`);++ else if (lf.endsWith('package-lock.json') || lf.endsWith('npm-shrinkwrap.json')) lines.push(`(cd ${q(dir)} && npm audit --json > "$ROOT/"${q(out)} 2>/dev/null) || true`);++ });++ return lines.join('\n');++}++++/** Each lockfile's advisory counts, or null when its audit returned nothing. */++function readAuditCounts(runDir, lockfiles) {++ return lockfiles.map((lockfile, i) => {++ let data = null;++ try { data = JSON.parse(fs.readFileSync(path.join(runDir, '.ci', `audit-${i}.json`), 'utf8')); } catch { data = null; }++ const v = data && data.metadata && data.metadata.vulnerabilities;++ if (!v || typeof v !== 'object') return { lockfile, counts: null };++ return { lockfile, counts: Object.fromEntries(LEVELS.map((l) => [l, Number(v[l]) || 0])) };++ });++}++++/** The lockfiles whose advisories reach the fail level (critical: critical; high: high or critical; none: never). */++function auditFailures(results, level = 'critical') {++ if (level === 'none') return [];++ const counted = level === 'high' ? ['critical', 'high'] : ['critical'];++ return results.filter((r) => r.counts && counted.some((l) => r.counts[l] > 0))++ .map((r) => `${r.lockfile}: ${counted.map((l) => `${r.counts[l]} ${l}`).join(', ')}`);++}++++module.exports = { secretScanScript, readSecretFindings, auditScript, readAuditCounts, auditFailures, LEVELS };nnew file mode 100644@@@ -0,0 +1,82 @@++'use strict';++// GitHub's security workflow in the forge's own run (2026-11-19): a secret scan (gitleaks, with the repository's own++// .gitleaks.toml) and a dependency audit failing at the repository's level, critical by default.++// - The scan's findings are read without the runner's own folders; with gitleaks here, a planted key is found and a++// narrow allowlist entry clears it.++// - The audit runs npm or pnpm per lockfile, writes a report each, and fails at critical (or high, or never).++// - The configuration turns each on by default and takes a repository's audit_fail_level.++const assert = require('assert');++const fs = require('fs');++const os = require('os');++const path = require('path');++const { spawnSync } = require('child_process');++const security = require('../runner/security');++const { loadConfig } = require('../runner/config');++++const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ov-ci-sec-'));++const write = (file, text) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, text); };++try {++ // ── The scan's script and its report ──++ const script = security.secretScanScript();++ assert.match(script, /gitleaks dir \. \$cfg --no-banner --redact/, 'the files at the pushed commit, redacted');++ assert.match(script, /--config \.gitleaks\.toml/);++ assert.match(script, /\.github\/gitleaks\.toml/, 'the config where security.yml looks for it too');++ assert.match(script, /exit 3/, 'a runner without gitleaks says so');++ const run = path.join(tmp, 'run');++ write(path.join(run, '.ci', 'gitleaks.json'), JSON.stringify([++ { RuleID: 'aws-access-token', File: 'src/config.js', StartLine: 3, Secret: 'REDACTED' },++ { RuleID: 'generic-api-key', File: '.ci/etc/passwd', StartLine: 1 },++ ]));++ assert.deepStrictEqual(security.readSecretFindings(run), [{ rule: 'aws-access-token', file: 'src/config.js', line: 3 }], 'the runner\'s folders are not the repository\'s');++ assert.deepStrictEqual(security.readSecretFindings(path.join(tmp, 'none')), [], 'no report, nothing found');++++ // A real scan, where gitleaks is installed (the shared node; GitHub's runners skip this part).++ if (spawnSync('gitleaks', ['version']).status === 0) {++ const repo = path.join(tmp, 'repo');++ const key = ['AKIA', 'QYLPMN5HHHFPZAM2'].join(''); // the shape of an AWS key id, made up++ write(path.join(repo, 'src', 'config.js'), `module.exports = { awsKey: '${key}' };\n`);++ const sh = (cwd) => spawnSync('sh', ['-c', script], { cwd, encoding: 'utf8' });++ let out = sh(repo);++ assert.strictEqual(out.status, 1, `a planted key is found (${out.stdout}${out.stderr})`);++ assert.ok(security.readSecretFindings(repo).some((f) => f.file === 'src/config.js'), 'in the file it is in');++ write(path.join(repo, '.gitleaks.toml'), `[extend]\nuseDefault = true\n\n[[allowlists]]\ndescription = "test fixture"\ncondition = "AND"\npaths = ['''^src/config\\.js$''']\nregexes = ['''${key}''']\n`);++ out = sh(repo);++ assert.strictEqual(out.status, 0, `a narrow allowlist entry clears it (${out.stdout}${out.stderr})`);++ } else {++ console.log('ci-security: no gitleaks here; the real scan is skipped');++ }++++ // ── The audit ──++ const audit = security.auditScript(['package-lock.json', 'apps/web/pnpm-lock.yaml', 'yarn.lock']);++ assert.match(audit, /\(cd '\.' && npm audit --json > "\$ROOT\/"'\.ci\/audit-0\.json'/);++ assert.match(audit, /\(cd 'apps\/web' && pnpm audit --json > "\$ROOT\/"'\.ci\/audit-1\.json'/);++ assert.doesNotMatch(audit, /yarn/, 'yarn is not audited (as security.yml)');++ write(path.join(run, '.ci', 'audit-0.json'), JSON.stringify({ metadata: { vulnerabilities: { critical: 1, high: 2, moderate: 0, low: 3 } } }));++ write(path.join(run, '.ci', 'audit-1.json'), JSON.stringify({ metadata: { vulnerabilities: { critical: 0, high: 4, moderate: 1, low: 0 } } }));++ const results = security.readAuditCounts(run, ['package-lock.json', 'apps/web/pnpm-lock.yaml', 'other/package-lock.json']);++ assert.deepStrictEqual(results[0].counts, { critical: 1, high: 2, moderate: 0, low: 3 });++ assert.strictEqual(results[2].counts, null, 'no report: nothing was checked, not a failure');++ assert.deepStrictEqual(security.auditFailures(results), ['package-lock.json: 1 critical'], 'critical by default: high is reported, not enforced');++ assert.deepStrictEqual(security.auditFailures(results, 'high'), ['package-lock.json: 1 critical, 2 high', 'apps/web/pnpm-lock.yaml: 0 critical, 4 high']);++ assert.deepStrictEqual(security.auditFailures(results, 'none'), []);++++ // ── The configuration ──++ const token = path.join(tmp, 'token');++ fs.writeFileSync(token, 'x'.repeat(40), { mode: 0o600 });++ const conf = path.join(tmp, 'ci.json');++ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, repos: { 'OpenVibers/A': {}, 'OpenVibers/B': { audit_fail_level: 'none' }, 'OpenVibers/C': { audit_fail_level: 'bogus' } } }));++ const cfg = loadConfig({ GIT_CI_CONFIG: conf });++ assert.strictEqual(cfg.secretScan, true);++ assert.strictEqual(cfg.audit, true);++ assert.strictEqual(cfg.repos['openvibers/a'].audit_fail_level, 'critical');++ assert.strictEqual(cfg.repos['openvibers/b'].audit_fail_level, 'none');++ assert.strictEqual(cfg.repos['openvibers/c'].audit_fail_level, 'critical', 'an unknown level is the default');++ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, secretScan: false, audit: false }));++ const off = loadConfig({ GIT_CI_CONFIG: conf });++ assert.strictEqual(off.secretScan, false);++ assert.strictEqual(off.audit, false);++++ console.log('ci-security: secret scan, its allowlist, the audit at each level and the configuration passed');++} finally {++ fs.rmSync(tmp, { recursive: true, force: true });++}
@@ -65,6 +65,18 @@ ln -sfn "$NODE_DIR" /opt/openvibe-node/current
@@ -65,6 +65,18 @@ ln -sfn "$NODE_DIR" /opt/openvibe-node/current
chown -R root:root /opt/openvibe-node
chown -R root:root /opt/openvibe-node
export PATH="/opt/openvibe-node/current/bin:$PATH"
export PATH="/opt/openvibe-node/current/bin:$PATH"
+# gitleaks for the run's secret scan (runner/security.js): the version and checksum openvibe-shared's security.yml pins.
+GITLEAKS_VERSION=${GITLEAKS_VERSION:-8.30.1}
+GITLEAKS_SHA256=${GITLEAKS_SHA256:-551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb}
+if ! /usr/local/bin/gitleaks version 2>/dev/null | grep -q "$GITLEAKS_VERSION"; then
+ TMP=$(mktemp -d)
+ curl -fsSL "https://github.com/gitleaks/gitleaks/releases/download/v$GITLEAKS_VERSION/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" -o "$TMP/g.tar.gz"
+ echo "$GITLEAKS_SHA256 $TMP/g.tar.gz" | sha256sum -c --quiet -
+ tar -xzf "$TMP/g.tar.gz" -C "$TMP" gitleaks
+ install -o root -g root -m 0755 "$TMP/gitleaks" /usr/local/bin/gitleaks
+ rm -rf "$TMP"
+fi
+
# pnpm into /usr (bubblewrap binds the host's /usr read-only).
# pnpm into /usr (bubblewrap binds the host's /usr read-only).
if ! command -v pnpm >/dev/null 2>&1 || [ "$(pnpm --version 2>/dev/null)" != "$PNPM_VERSION" ]; then
if ! command -v pnpm >/dev/null 2>&1 || [ "$(pnpm --version 2>/dev/null)" != "$PNPM_VERSION" ]; then
npm install -g --no-audit --no-fund "pnpm@$PNPM_VERSION" >/dev/null
npm install -g --no-audit --no-fund "pnpm@$PNPM_VERSION" >/dev/null
@@ -150,6 +150,13 @@ repositories) to `ov-node-01` (8 cores, 15 GB):
@@ -150,6 +150,13 @@ repositories) to `ov-node-01` (8 cores, 15 GB):
- **The verdict** is the forge's `forge/test` status; the node has no GitHub login, so it does not post to GitHub
- **The verdict** is the forge's `forge/test` status; the node has no GitHub login, so it does not post to GitHub
(`"githubStatus": false`). The ship scripts read the forge's verdict directly.
(`"githubStatus": false`). The ship scripts read the forge's verdict directly.
+- **GitHub's security checks, in the run** (`runner/security.js`, 2026-11-19): a gitleaks scan of the pushed commit's
+ files (the repository's own `.gitleaks.toml` or `.github/gitleaks.toml`; no network) before the install, and
+ `npm audit` / `pnpm audit` for every lockfile through the install proxy after it, failing at the repository's
+ `audit_fail_level` (critical by default, as openvibe-shared's security.yml: high is reported, not enforced; or
+ `high`, or `none`). Findings fail the run after the tests have run, and the description names them. gitleaks is
+ the version and checksum security.yml pins, installed at /usr/local/bin by `node-setup.sh`.
+
Each run's description says where the time went: `Forge runner passed in 2m 10s (install 3s from the cache, tests
Each run's description says where the time went: `Forge runner passed in 2m 10s (install 3s from the cache, tests
2m 4s)`.
2m 4s)`.
@@ -72,6 +72,9 @@ function loadConfig(env = process.env) {
@@ -72,6 +72,9 @@ function loadConfig(env = process.env) {
// The test phase's OV_TEST_TIMEOUT_SCALE (openvibe-shared/test-runner 4.323.0 and later): a runner slower or busier
// The test phase's OV_TEST_TIMEOUT_SCALE (openvibe-shared/test-runner 4.323.0 and later): a runner slower or busier
// than the machines a repository's per-file limits were set on stretches them (the shared node: 2).
// than the machines a repository's per-file limits were set on stretches them (the shared node: 2).
testTimeoutScale: Math.min(10, Math.max(1, Number(raw.testTimeoutScale) || 1)),
testTimeoutScale: Math.min(10, Math.max(1, Number(raw.testTimeoutScale) || 1)),
+ // GitHub's security workflow, in the run (runner/security.js): the secret scan and the dependency audit.
+ secretScan: raw.secretScan !== false,
+ audit: raw.audit !== false,
// Host folders shown read-only in both phases (runner/sandbox.js safeRoBinds): the node shows /opt/google (Chrome).
// Host folders shown read-only in both phases (runner/sandbox.js safeRoBinds): the node shows /opt/google (Chrome).
roBinds: Array.isArray(raw.roBinds) ? raw.roBinds.map(String).slice(0, 20) : [],
roBinds: Array.isArray(raw.roBinds) ? raw.roBinds.map(String).slice(0, 20) : [],
// Installs kept between runs (runner/deps-cache.js) and the package managers' download caches. Both live on
// Installs kept between runs (runner/deps-cache.js) and the package managers' download caches. Both live on
@@ -99,6 +102,8 @@ function loadConfig(env = process.env) {
@@ -99,6 +102,8 @@ function loadConfig(env = process.env) {
image: String((item && item.image) || cfg.image),
image: String((item && item.image) || cfg.image),
cpus: int(item && item.cpus, 4, 1, 8),
cpus: int(item && item.cpus, 4, 1, 8),
memory_mb: int(item && item.memory_mb, 6144, 512, 12288),
memory_mb: int(item && item.memory_mb, 6144, 512, 12288),
+ // As security.yml's audit-fail-level: critical (default), high, or none (report only).
+ audit_fail_level: ['critical', 'high', 'none'].includes(item && item.audit_fail_level) ? item.audit_fail_level : 'critical',
},
},
]));
]));
if (!cfg.token) throw new Error(`no runner token: write it to ${tokenFile} (0600) or set GIT_CI_RUNNER_TOKEN`);
if (!cfg.token) throw new Error(`no runner token: write it to ${tokenFile} (0600) or set GIT_CI_RUNNER_TOKEN`);
@@ -13,7 +13,8 @@ const { createProxy } = require('./proxy');
@@ -13,7 +13,8 @@ const { createProxy } = require('./proxy');
const { runProcess } = require('./process');
const { runProcess } = require('./process');
const { podmanArgs, bwrapArgs, bwrapScope, installScript, podmanCleanup, scopeCleanup, detectEngine, RELAY } = require('./sandbox');
const { podmanArgs, bwrapArgs, bwrapScope, installScript, podmanCleanup, scopeCleanup, detectEngine, RELAY } = require('./sandbox');
const { reportGithubStatus } = require('./github-status');
const { reportGithubStatus } = require('./github-status');
-const { createDepsCache, cacheKey, survey, installed, autoCommands } = require('./deps-cache');
+const { createDepsCache, cacheKey, survey, installed, autoCommands, lockfilesIn } = require('./deps-cache');
+const security = require('./security');
@@ -191,6 +192,22 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
@@ -191,6 +192,22 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
}
}
}
}
+ // GitHub's security workflow, here (runner/security.js): what they find fails the run, after the tests ran.
+ const problems = [];
+ if (!state && cfg.secretScan) {
+ const scan = await phase('secrets', installScript(security.secretScanScript(), { proxy: false }), null);
+ if (superseded) state = 'superseded';
+ else if (scan.code === 0) onData('secret scan: nothing found\n');
+ else if (scan.code === 1) {
+ const found = security.readSecretFindings(runDir);
+ if (found.length) {
+ for (const f of found.slice(0, 20)) onData(`secret scan: ${f.rule} at ${f.file}:${f.line} (redacted)\n`);
+ onData('A real secret: rotate it first, then remove it. A proven false positive: a narrow [[allowlists]] entry (path AND value) in .gitleaks.toml.\n');
+ problems.push(`secret scan: ${found.length} finding${found.length === 1 ? '' : 's'}`);
+ } else onData('secret scan: findings only in the runner\'s own folders, ignored\n');
+ } else if (scan.code === 3) { /* said so in its own output */ } else onData(`secret scan could not run (exit ${scan.code}); not counted\n`);
+ }
+
let installMs = 0;
let installMs = 0;
let fromCache = false;
let fromCache = false;
if (!state) {
if (!state) {
@@ -225,14 +242,37 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
@@ -225,14 +242,37 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
}
}
}
}
}
}
+ const repoConf = cfg.repos[String(job.repo.full_name || '').toLowerCase()] || {};
+ const auditLevel = repoConf.audit_fail_level || 'critical';
+ if (!state && cfg.audit && auditLevel !== 'none') {
+ const locks = lockfilesIn(runDir);
+ if (locks.length) {
+ proxy = createProxy({ allow: cfg.proxyAllow, log: { warn: (line) => onData(`${line}\n`) } });
+ const socket = path.join(runDir, '.ci', 'proxy.sock');
+ await proxy.listen(socket);
+ await phase('audit', installScript(security.auditScript(locks)), socket);
+ await proxy.close().catch(() => {});
+ proxy = null;
+ if (superseded) state = 'superseded';
+ const results = security.readAuditCounts(runDir, locks);
+ for (const r of results) {
+ onData(r.counts
+ ? `audit ${r.lockfile}: ${security.LEVELS.map((l) => `${r.counts[l]} ${l}`).join(', ')}\n`
+ : `audit ${r.lockfile}: no answer (the registry unreachable?); nothing was checked\n`);
+ }
+ const failing = security.auditFailures(results, auditLevel);
+ if (failing.length) problems.push(`dependency audit (${auditLevel}): ${failing.join('; ')}`.slice(0, 300));
+ }
+ }
if (!state) {
if (!state) {
const t1 = clock();
const t1 = clock();
const test = await phase('test', installScript(commands.test, { proxy: false }), null);
const test = await phase('test', installScript(commands.test, { proxy: false }), null);
const timing = `install ${words(installMs)}${fromCache ? ' from the cache' : ''}, tests ${words(clock() - t1)}`;
const timing = `install ${words(installMs)}${fromCache ? ' from the cache' : ''}, tests ${words(clock() - t1)}`;
if (superseded) state = 'superseded';
if (superseded) state = 'superseded';
else if (test.timedOut) { state = 'timed_out'; description = `Timed out after ${words(totalMs)}`; }
else if (test.timedOut) { state = 'timed_out'; description = `Timed out after ${words(totalMs)}`; }
- else if (test.code === 0) { state = 'success'; description = `Forge runner passed in ${words(clock() - started)} (${timing})`; }
- else { state = 'failure'; exitCode = test.code; description = `Forge runner failed (exit ${test.code}) in ${words(clock() - started)} (${timing})`; }
+ else if (test.code === 0 && !problems.length) { state = 'success'; description = `Forge runner passed in ${words(clock() - started)} (${timing})`; }
+ else if (test.code === 0) { state = 'failure'; exitCode = 1; description = `Forge runner failed: ${problems.join('; ')} (tests passed; ${timing})`; }
+ else { state = 'failure'; exitCode = test.code; description = `Forge runner failed (exit ${test.code}) in ${words(clock() - started)} (${timing})${problems.length ? `; also ${problems.join('; ')}` : ''}`; }
}
}
} catch (err) {
} catch (err) {
if (superseded) state = 'superseded';
if (superseded) state = 'superseded';
new file mode 100644
new file mode 100644
@@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
+'use strict';
+
+/**
+ * The checks GitHub's security workflow (openvibe-shared .github/workflows/security.yml) runs, in the forge's own run
+ * (2026-11-19, the owner: "handle CI with our own system"), so forge/test is the whole verdict:
+ *
+ * secrets gitleaks over the pushed commit's files, in the sandbox with no network, with the repository's own
+ * .gitleaks.toml (or .github/gitleaks.toml). A finding fails the run. A runner without gitleaks says so and
+ * skips it (/usr/local/bin/gitleaks on the shared node, the version security.yml pins).
+ * audit npm audit / pnpm audit for every lockfile in the checkout, through the install proxy (the registry's
+ * advisories), failing at the repository's audit_fail_level: critical by default, as security.yml (high
+ * is reported, not enforced), or high, or none. An audit that returns nothing (the registry unreachable)
+ * is reported and checks nothing, as on GitHub.
+ */
+const fs = require('node:fs');
+const path = require('node:path');
+
+const LEVELS = ['critical', 'high', 'moderate', 'low'];
+
+const q = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
+
+/** The secret scan's script: exit 0 clean, 1 findings (gitleaks' own), 3 no gitleaks here, anything else an error. */
+function secretScanScript() {
+ return [
+ 'command -v gitleaks >/dev/null 2>&1 || { echo "secret scan: gitleaks is not installed on this runner"; exit 3; }',
+ 'cfg=""',
+ '[ -f .gitleaks.toml ] && cfg="--config .gitleaks.toml"',
+ '[ -z "$cfg" ] && [ -f .github/gitleaks.toml ] && cfg="--config .github/gitleaks.toml"',
+ // The runner's own folders are not the repository's.
+ 'mkdir -p .ci',
+ 'gitleaks dir . $cfg --no-banner --redact --report-format json --report-path .ci/gitleaks.json --exit-code 1 --log-level warn',
+ ].join('\n');
+}
+
+/** What the scan found: the findings without their secrets (gitleaks redacts them), the runner's folders left out. */
+function readSecretFindings(runDir) {
+ let rows = [];
+ try { rows = JSON.parse(fs.readFileSync(path.join(runDir, '.ci', 'gitleaks.json'), 'utf8')); } catch { return []; }
+ return (Array.isArray(rows) ? rows : [])
+ .filter((r) => r && r.File && !/^(\.\/)?\.(ci|home|cache|pnpm)\//.test(String(r.File)))
+ .map((r) => ({ rule: String(r.RuleID || ''), file: String(r.File).replace(/^\.\//, ''), line: Number(r.StartLine) || 0 }));
+}
+
+/** The audit's script: one JSON report per lockfile under the checkout's .ci, whatever the audit's own exit code. */
+function auditScript(lockfiles) {
+ const lines = ['ROOT=$(pwd)', 'mkdir -p "$ROOT/.ci"'];
+ lockfiles.forEach((lf, i) => {
+ const dir = path.posix.dirname(lf);
+ const out = `.ci/audit-${i}.json`;
+ if (lf.endsWith('pnpm-lock.yaml')) lines.push(`(cd ${q(dir)} && pnpm audit --json > "$ROOT/"${q(out)} 2>/dev/null) || true`);
+ else if (lf.endsWith('package-lock.json') || lf.endsWith('npm-shrinkwrap.json')) lines.push(`(cd ${q(dir)} && npm audit --json > "$ROOT/"${q(out)} 2>/dev/null) || true`);
+ });
+ return lines.join('\n');
+}
+
+/** Each lockfile's advisory counts, or null when its audit returned nothing. */
+function readAuditCounts(runDir, lockfiles) {
+ return lockfiles.map((lockfile, i) => {
+ let data = null;
+ try { data = JSON.parse(fs.readFileSync(path.join(runDir, '.ci', `audit-${i}.json`), 'utf8')); } catch { data = null; }
+ const v = data && data.metadata && data.metadata.vulnerabilities;
+ if (!v || typeof v !== 'object') return { lockfile, counts: null };
+ return { lockfile, counts: Object.fromEntries(LEVELS.map((l) => [l, Number(v[l]) || 0])) };
+ });
+}
+
+/** The lockfiles whose advisories reach the fail level (critical: critical; high: high or critical; none: never). */
+function auditFailures(results, level = 'critical') {
+ if (level === 'none') return [];
+ const counted = level === 'high' ? ['critical', 'high'] : ['critical'];
+ return results.filter((r) => r.counts && counted.some((l) => r.counts[l] > 0))
+ .map((r) => `${r.lockfile}: ${counted.map((l) => `${r.counts[l]} ${l}`).join(', ')}`);
+}
+
+module.exports = { secretScanScript, readSecretFindings, auditScript, readAuditCounts, auditFailures, LEVELS };
new file mode 100644
new file mode 100644
@@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
+'use strict';
+// GitHub's security workflow in the forge's own run (2026-11-19): a secret scan (gitleaks, with the repository's own
+// .gitleaks.toml) and a dependency audit failing at the repository's level, critical by default.
+// - The scan's findings are read without the runner's own folders; with gitleaks here, a planted key is found and a
+// narrow allowlist entry clears it.
+// - The audit runs npm or pnpm per lockfile, writes a report each, and fails at critical (or high, or never).
+// - The configuration turns each on by default and takes a repository's audit_fail_level.
+const assert = require('assert');
+const fs = require('fs');
+const os = require('os');
+const path = require('path');
+const { spawnSync } = require('child_process');
+const security = require('../runner/security');
+const { loadConfig } = require('../runner/config');
+
+const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ov-ci-sec-'));
+const write = (file, text) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, text); };
+try {
+ // ── The scan's script and its report ──
+ const script = security.secretScanScript();
+ assert.match(script, /gitleaks dir \. \$cfg --no-banner --redact/, 'the files at the pushed commit, redacted');
+ assert.match(script, /--config \.gitleaks\.toml/);
+ assert.match(script, /\.github\/gitleaks\.toml/, 'the config where security.yml looks for it too');
+ assert.match(script, /exit 3/, 'a runner without gitleaks says so');
+ const run = path.join(tmp, 'run');
+ write(path.join(run, '.ci', 'gitleaks.json'), JSON.stringify([
+ { RuleID: 'aws-access-token', File: 'src/config.js', StartLine: 3, Secret: 'REDACTED' },
+ { RuleID: 'generic-api-key', File: '.ci/etc/passwd', StartLine: 1 },
+ ]));
+ assert.deepStrictEqual(security.readSecretFindings(run), [{ rule: 'aws-access-token', file: 'src/config.js', line: 3 }], 'the runner\'s folders are not the repository\'s');
+ assert.deepStrictEqual(security.readSecretFindings(path.join(tmp, 'none')), [], 'no report, nothing found');
+
+ // A real scan, where gitleaks is installed (the shared node; GitHub's runners skip this part).
+ if (spawnSync('gitleaks', ['version']).status === 0) {
+ const repo = path.join(tmp, 'repo');
+ const key = ['AKIA', 'QYLPMN5HHHFPZAM2'].join(''); // the shape of an AWS key id, made up
+ write(path.join(repo, 'src', 'config.js'), `module.exports = { awsKey: '${key}' };\n`);
+ const sh = (cwd) => spawnSync('sh', ['-c', script], { cwd, encoding: 'utf8' });
+ let out = sh(repo);
+ assert.strictEqual(out.status, 1, `a planted key is found (${out.stdout}${out.stderr})`);
+ assert.ok(security.readSecretFindings(repo).some((f) => f.file === 'src/config.js'), 'in the file it is in');
+ write(path.join(repo, '.gitleaks.toml'), `[extend]\nuseDefault = true\n\n[[allowlists]]\ndescription = "test fixture"\ncondition = "AND"\npaths = ['''^src/config\\.js$''']\nregexes = ['''${key}''']\n`);
+ out = sh(repo);
+ assert.strictEqual(out.status, 0, `a narrow allowlist entry clears it (${out.stdout}${out.stderr})`);
+ } else {
+ console.log('ci-security: no gitleaks here; the real scan is skipped');
+ }
+
+ // ── The audit ──
+ const audit = security.auditScript(['package-lock.json', 'apps/web/pnpm-lock.yaml', 'yarn.lock']);
+ assert.match(audit, /\(cd '\.' && npm audit --json > "\$ROOT\/"'\.ci\/audit-0\.json'/);
+ assert.match(audit, /\(cd 'apps\/web' && pnpm audit --json > "\$ROOT\/"'\.ci\/audit-1\.json'/);
+ assert.doesNotMatch(audit, /yarn/, 'yarn is not audited (as security.yml)');
+ write(path.join(run, '.ci', 'audit-0.json'), JSON.stringify({ metadata: { vulnerabilities: { critical: 1, high: 2, moderate: 0, low: 3 } } }));
+ write(path.join(run, '.ci', 'audit-1.json'), JSON.stringify({ metadata: { vulnerabilities: { critical: 0, high: 4, moderate: 1, low: 0 } } }));
+ const results = security.readAuditCounts(run, ['package-lock.json', 'apps/web/pnpm-lock.yaml', 'other/package-lock.json']);
+ assert.deepStrictEqual(results[0].counts, { critical: 1, high: 2, moderate: 0, low: 3 });
+ assert.strictEqual(results[2].counts, null, 'no report: nothing was checked, not a failure');
+ assert.deepStrictEqual(security.auditFailures(results), ['package-lock.json: 1 critical'], 'critical by default: high is reported, not enforced');
+ assert.deepStrictEqual(security.auditFailures(results, 'high'), ['package-lock.json: 1 critical, 2 high', 'apps/web/pnpm-lock.yaml: 0 critical, 4 high']);
+ assert.deepStrictEqual(security.auditFailures(results, 'none'), []);
+
+ // ── The configuration ──
+ const token = path.join(tmp, 'token');
+ fs.writeFileSync(token, 'x'.repeat(40), { mode: 0o600 });
+ const conf = path.join(tmp, 'ci.json');
+ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, repos: { 'OpenVibers/A': {}, 'OpenVibers/B': { audit_fail_level: 'none' }, 'OpenVibers/C': { audit_fail_level: 'bogus' } } }));
+ const cfg = loadConfig({ GIT_CI_CONFIG: conf });
+ assert.strictEqual(cfg.secretScan, true);
+ assert.strictEqual(cfg.audit, true);
+ assert.strictEqual(cfg.repos['openvibers/a'].audit_fail_level, 'critical');
+ assert.strictEqual(cfg.repos['openvibers/b'].audit_fail_level, 'none');
+ assert.strictEqual(cfg.repos['openvibers/c'].audit_fail_level, 'critical', 'an unknown level is the default');
+ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, secretScan: false, audit: false }));
+ const off = loadConfig({ GIT_CI_CONFIG: conf });
+ assert.strictEqual(off.secretScan, false);
+ assert.strictEqual(off.audit, false);
+
+ console.log('ci-security: secret scan, its allowlist, the audit at each level and the configuration passed');
+} finally {
+ fs.rmSync(tmp, { recursive: true, force: true });
+}