Skip to content
Merged
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
28 changes: 28 additions & 0 deletions .github/workflows/security-scan-codex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ jobs:
ENDOR_API_CREDENTIALS_KEY: ${{ secrets.ENDOR_API_CREDENTIALS_KEY }}
ENDOR_API_CREDENTIALS_SECRET: ${{ secrets.ENDOR_API_CREDENTIALS_SECRET }}
run: |
# Sample memory, disk and OOM kills inside the worker step, because a
# shard killed for memory never runs later steps. This cannot help a
# lost runner, which keeps no log; it covers killed (137/143) and
# surviving shards. `free` counts tmpfs as shared/cache, so report
# available and shared memory rather than used.
oom_seen=0
sample() {
mem=$(free -m | awk '/^Mem:/ {printf "mem_available_mb=%s mem_shared_mb=%s mem_total_mb=%s", $7, $5, $2} /^Swap:/ {printf " swap_used_mb=%s", $3}')
disk=$(df --output=pcent / | tail -1 | tr -d ' ')
echo "runner-resources $(date -u +%T) $mem root_disk_used=$disk"
# Print only OOM kills this shell hasn't printed yet.
kills=$(sudo -n dmesg -T 2>/dev/null | grep -i 'killed process' || true)
if [ -n "$kills" ]; then
printf '%s\n' "$kills" | tail -n "+$((oom_seen + 1))" | sed 's/^/runner-resources oom: /'
oom_seen=$(printf '%s\n' "$kills" | wc -l)
fi
}
(
while sleep 60; do
sample
timeout 20 docker stats --no-stream --format 'runner-resources container={{.Name}} mem={{.MemUsage}}' 2>/dev/null || true
done
) 2>/dev/null &
sampler=$!
# Take a last sample (listing every OOM kill so far), then stop the
# sampler and its pending sleep. Under -e, a failing trap command
# replaces the worker's exit status, so the whole cleanup is best effort.
trap '{ sample; pkill -P "$sampler"; kill "$sampler"; } 2>/dev/null || true' EXIT
bun scripts/security/run-codex-scan-worker.ts \
--batch-limit "$CODEX_SECURITY_SCAN_LIMIT" \
--lane "$CODEX_SECURITY_SCAN_LANE" \
Expand Down
1 change: 1 addition & 0 deletions scripts/security/endor/fixtures/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set -eu
# docker run --rm --network bridge --cap-drop ALL \
# --cap-add NET_ADMIN --cap-add SETUID --cap-add SETGID --cap-add SETPCAP \
# --cap-add CHOWN --security-opt no-new-privileges:true --read-only \
# --memory 3g --memory-swap 3g \
# --tmpfs /tmp:rw,nosuid,nodev,exec --tmpfs /output:rw,mode=1777 \
# --mount type=bind,source="$PWD/scripts/security/endor/fixtures",target=/fixture,readonly \
# --mount type=bind,source="$PWD/scripts/security/endor/scan.sh",target=/scan.sh,readonly \
Expand Down
6 changes: 6 additions & 0 deletions scripts/security/run-endor-plugin-scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ describe("runEndorPluginScan", () => {
);
const runArgs = await dockerRunArgs(workspace);
expect(runArgs).toContain("--rm");
// Without a cap, concurrent large scans exhaust the hosted runner's memory;
// a swap limit equal to the memory limit keeps the container off swap.
expect(runArgs).toEqual(expect.arrayContaining(["--memory", "--memory-swap"]));
const memory = runArgs[runArgs.indexOf("--memory") + 1];
expect(memory).toMatch(/^\d+g$/);
expect(runArgs[runArgs.indexOf("--memory-swap") + 1]).toBe(memory);
expect(runArgs).toContain(
`type=bind,source=${join(workspace, "endor-artifact")},target=/workspace,readonly`,
);
Expand Down
10 changes: 10 additions & 0 deletions scripts/security/run-endor-plugin-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const CHILD_RUNTIME_ENV_KEYS = [
] as const;
const DEFAULT_ENDOR_TIMEOUT_MS = 20 * 60 * 1000;
const DOCKER_REMOVE_TIMEOUT_MS = 10_000;
// Hosted ubuntu-22.04 runners have 16 GB, and a shard runs 4 scans at once by default.
const ENDOR_CONTAINER_MEMORY = "3g";
// Community packages with large dependency trees produce reports over 8 MiB.
// Only the bounded summary is kept; diagnostics are capped separately.
const MAX_ENDOR_REPORT_BYTES = 64 * 1024 * 1024;
Expand Down Expand Up @@ -281,6 +283,14 @@ export async function runEndorPluginScan(input: {
"--security-opt",
"no-new-privileges:true",
"--read-only",
// A --memory-swap equal to --memory allows no swap. The /tmp tmpfs (npm
// tree, npm cache, call graph) counts against the cap, so an oversized scan
// is killed inside this container and fails only its own report, instead
// of exhausting the runner.
"--memory",
ENDOR_CONTAINER_MEMORY,
"--memory-swap",
ENDOR_CONTAINER_MEMORY,
"--entrypoint",
"/usr/local/bin/clawhub-endor-entrypoint",
"--tmpfs",
Expand Down
16 changes: 13 additions & 3 deletions specs/endor-plugin-scans.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ A claimed job runs Endor when:
- the job is a package release whose family is `code-plugin`.

That covers official and community code plugins. Skills and bundle plugins never
run Endor. There is no backfill: existing releases gain a result the next time
they are scanned for any reason (new publication, owner rescan, admin rescan).
run Endor. The `package-scan-backfill` cron enqueues Endor report-only jobs for
releases whose Endor result is missing or `failed` (see
`specs/plugin-single-scan-routing.md`); any other scan also refreshes it.

## Result contract

Expand All @@ -34,7 +35,8 @@ they are scanned for any reason (new publication, owner rescan, admin rescan).
package with a root `pnpm-lock.yaml`: `endorctl` needs pnpm for it, and the
scanner image only runs npm and Yarn through credential-stripping shims.
- A scanner failure or timeout is saved as `failed` with a generic reason. It
does not fail or retry the job; owners or admins can request a rescan.
does not fail or immediately retry the job; the backfill cron re-enqueues it
later, and owners or admins can request a rescan.
- A later scan replaces the stored result; this is not a report archive. The
previous result stays visible while replacement work is queued or running.

Expand Down Expand Up @@ -64,6 +66,14 @@ Endor runs with `docker run --rm` from a digest-pinned image built by the manual
- installs firewall rules blocking private, link-local and special-use IPv4/IPv6
destinations, then drops all capabilities and runs as the unprivileged `node`
user (it uses public DNS resolvers because the firewall blocks private ones);
- is capped at 3 GiB of memory with no swap, so a shard's default 4 concurrent
scans leave headroom on the 16 GB hosted runner. The `/tmp` tmpfs, which
holds the npm tree, npm cache and call graph, counts against the cap. An
oversized scan is killed inside its own container and only its report fails.
Because the backfill cron re-enqueues failed reports, a package that never
fits keeps failing on later passes until the cap changes. Without
the cap, from 2026-11-07 concurrent scans of large packages exhausted the
runner: the kernel killed the worker, or GitHub lost contact with the runner;
- runs npm and Yarn through shims that strip Endor credentials and disable
dependency scripts. The image pins an npm version that also suppresses Git
dependency `prepare` scripts; the isolation proof below checks this.
Expand Down
Loading