Skip to content

Sync laptop-only work: openforge (8 commits) + Mint zh-Hant/es phrasings - #48

Open
juw12 wants to merge 9 commits into
mainfrom
sync/laptop-only-commits
Open

juw12 wants to merge 9 commits into
mainfrom
sync/laptop-only-commits

Conversation

@juw12

@juw12 juw12 commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Carries over the work that only existed on the laptop clone in ~/Documents/Default Project (its .git folder went missing today and was restored from GitHub).

What was actually missing: of 619 laptop-only commits, 607 were already on main with identical subjects (rebased SHAs). Only 12 were genuinely missing:

Tests

  • apps/mint/tests/test_core.py passes (0 failures), incl. 10 new checks for the above.
  • The laptop's own test file (the 4 old commits' expectations) also passes against this branch.
  • openforge TypeScript tests not run - no node/npm on this PC.

The full laptop history is also preserved on branch laptop-backup-2026-11-09.

OpenForge and others added 9 commits November 10, 2026 10:57
Adds POST /api/v1/runner/oidc-token that mints HS256 JWTs for runner
jobs, replacing the long-lived stored secrets model. Mirrors the
runner-side client at openforge/runner/internal/app/openforge/oidc.go.

Spec: openforge/docs/runner-oidc-endpoint.md

Components:
- apps/api/src/services/oidc-token.ts — pure HS256 issuer + verifier
  using Node crypto (no external JWT library). 5 min default lifetime,
  15 min hard cap. Constant-time signature verification.
- apps/api/src/routes/runner.ts — Hono route with Bearer auth (runner
  registration token), zod validation, structured logging.
- apps/api/src/services/__tests__/oidc-token.test.ts — vitest unit tests
  covering config validation, lifetime bounds, audience/jobId checks,
  jti distinctness, signature round-trip, expiry, wrong-secret, malformed.
- apps/api/src/index.ts — mounted runnerRouter at /api/v1/runner.

Environment:
- OIDC_ISSUER (e.g. 'forge.example.com')
- OIDC_SIGNING_SECRET (>= 32 bytes, recommend 64 random)

Follows the 2026-11-03 verified design: lifetime matches GitHub's
canonical ACTIONS_ID_TOKEN_REQUEST_TOKEN example (300s, NOT 1 hour).
Audience-restricted, issuer-bound, jti-unique per token.
Three new tables for the CI runner subsystem:

- runners: registration metadata, label set, sandbox mode (gvisor
  default), ephemeral flag (default true, matches GitHub-hosted
  runner model), concurrency cap, lifecycle status (offline/idle/
  busy/draining), last-seen timestamp for GC of stale runners.
- runner_registration_tokens: bearer tokens stored as SHA-256 hash
  (cf. CircleCI Dec 2022 — plaintext token storage was the root
  cause). Token issuance: server generates 256-bit secret, returns
  plaintext ONCE, stores only the hash + a short human prefix.
- runner_jobs: many-to-many between runners and workflow jobs.
  Partial unique index enforces 'one active runner per job'.

Verified design choices (2026-11-03):
- Default sandbox = gvisor (OpenForge policy, cf. INTEGRATION.md)
- Default ephemeral = true (matches GitHub-hosted runner model)
- registration_token hash, never plaintext (CircleCI Dec 2022)
- runner_jobs partial unique index for active assignment atomicity

Files:
- packages/db/src/schema/runners.ts (Drizzle schema)
- packages/db/src/schema/index.ts (re-export)
- packages/db/migrations/0001_runners.sql (manual migration,
  pnpm/drizzle-kit not available in this environment)
Replaces the TODO stub in routes/runner.ts with a real SHA-256-hash
lookup against runner_registration_tokens, plus an extractBearer
helper. The plaintext bearer is NEVER stored server-side.

Also adds runnerOwnsJob() stub to enforce job-ownership on the OIDC
mint path. The stub returns false (deny by default) — must be wired
to a real SELECT against runner_jobs before production.

Files:
- apps/api/src/services/runner-auth.ts — authn + bearer extract
- apps/api/src/services/__tests__/runner-auth.test.ts — unit tests
- apps/api/src/routes/runner.ts — uses new service, calls stub

Auth chain (server-side):
  1. Hono route extracts Bearer from Authorization header
  2. sha256Hex(plaintext) — never stored, only computed
  3. SELECT against runner_registration_tokens WHERE token_hash =
  4. Verify expires_at IS NULL OR expires_at > now()
  5. INNER JOIN runners to return { id, name }
  6. runnerOwnsJob(runnerId, jobId) — stub, returns false
  7. Mint OIDC token (HS256, 5min default, 15min cap)

Verified invariants (2026-11-03):
- Hash is SHA-256 hex (64 chars), enforced by DB constraint
- Plaintext is not stored (cf. CircleCI Dec 2022)
- Constant-time comparison where applicable
- Stub defaults to deny (safe default)
Replaces the stub return-false with a real Drizzle query:
  SELECT 1 FROM runner_jobs
  WHERE runner_id = \ AND job_id = \ AND picked_up_at IS NOT NULL

This enforces that a runner can only mint OIDC tokens for jobs it has
actually picked up (the partial unique index on runner_jobs already
guarantees one active assignment per job).

Query is index-friendly:
  - runner_jobs_runner_idx covers runner_id
  - runner_jobs_job_idx covers job_id
  - partial unique index on active rows filters the result set
Adds the cache-mode workflow-key claim to OIDC tokens minted by the
runner route. The runner can now request an audience=openforge-cache
token with cache_mode: read|write|write-only|none and the server will
include the cache_mode claim in the JWT payload.

Mirrors GitHub's ACTIONS_CACHE_MODE semantics (verified 2026-11-03
during pass-2 spec verification): low-trust triggers get read-only
cache access by default; trusted triggers get write access.

This addresses the cache-poisoning threat class (cf. Ultralytics YOLO
Dec 2024 — fork PR's pull_request_target job wrote poisoned cache, the
release pipeline restored it).

Files:
- services/oidc-token.ts — CacheMode type, validation, JWT payload
- services/__tests__/oidc-token.test.ts — coverage for all 4 modes,
  invalid value rejection, omission-when-not-provided
- routes/runner.ts — request schema + passthrough to issueOidcToken

Test coverage added:
- cache_mode in JWT payload and response when provided
- cache_mode absent when not requested
- invalid cacheMode rejected client-side
- all 4 valid values accepted
Server-side enforcement of fork-PR permissions. The server — not the
workflow YAML — decides what permissions a job receives. Workflows can
REQUEST higher permissions but cannot GRANT them.

Verified threat model (2026-11-03):
- Pwn request (Grafana Apr 2025): fork PR + pull_request_target with base
  secrets. We kill the class by always denying fork PRs.
- pull_request_target default block (GitHub effective Dec 2 2026).

Permission levels:
  none    — no base repo secrets, no head checkout from fork
  reviewer — base repo secrets only after explicit reviewer approval
  full    — base repo secrets + head checkout (trusted triggers only)

Trust rules (server-side, NOT enforced by workflow YAML):
  fork + pull_request          → none (always)
  fork + pull_request_target   → none (always; workflow YAML can't override)
  direct push                  → full
  workflow_dispatch            → full
  pull_request (same-repo)     → reviewer
  schedule                     → full
  workflow_run                 → full

Files:
- packages/db/src/schema/actions.ts — added triggerSource, isForkPr on
  workflow_runs; permissions, isForkPr on workflow_jobs
- packages/db/migrations/0002_fork_pr_permissions.sql — schema migration
  with CHECK constraint on permissions column
- apps/api/src/services/permissions-policy.ts — resolvePermissions() helper
  with full coverage of trigger/permission matrix
- apps/api/src/services/__tests__/permissions-policy.test.ts — unit tests
  covering fork PR denial, same-repo PR reviewer-gating, opt-out, unknown
  triggers (closed-by-default), and the workflow-YAML override attempt
- apps/api/src/services/oidc-token.ts — added permissions validation,
  JWT payload claim, and response field
- apps/api/src/services/__tests__/oidc-token.test.ts — permissions tests
  including combined cacheMode+permissions in one token
- apps/api/src/routes/runner.ts — accepts permissions in request body,
  passes through to issueOidcToken, logs the level

Test coverage:
- Fork PR → none regardless of trigger type or workflow request
- Same-repo PR → reviewer (full requires explicit approval)
- Trusted triggers → full (unless workflow opts out → none)
- Unknown triggers → none (closed-by-default)
- Workflow YAML attempting to override fork-PR permission is ignored
- All permission values (none/reviewer/full) accepted
- Invalid permission values rejected client-side
- permissions claim appears in JWT payload when provided
- permissions claim omitted from JWT payload when not provided
Adds the policy decision logic for default-deny egress. Pure logic —
the actual enforcement (eBPF, iptables, nftables) is a separate
concern that consumes these decisions.

Verified threat model (2026-11-03):
- Lateral movement (cf. CircleCI Dec 2022): stolen CI token reached
  production because the runner had default network access.
- DoH bypass (cf. Harden-Runner CVE-2026-32947): domain allowlists
  bypassable via DNS-over-HTTPS through permitted hosts.

Modes:
  deny-all    — denies every egress; workflows must declare allowlist
  allow-all   — permits every egress (insecure; flagged in reason)
  allowlist   — permit only destinations matching one of the entries

Allowlist entry kinds:
  host       — exact hostname match
  wildcard   — suffix match (entry starts with '.')
  cidr       — IPv4 CIDR match (e.g. '10.0.0.0/8')

Default allowlist (used when workflow declares egress: allowlist but
no entries):
  - registry.npmjs.org
  - pypi.org
  - *.githubusercontent.com (GitHub Actions CDN)
  - *.openforge.example (the OpenForge server itself)

Test coverage:
- deny-all denies every destination
- allow-all permits every destination
- allowlist: exact host match allowed
- allowlist: different host on same TLD rejected
- allowlist: wildcard suffix match allowed
- allowlist: CIDR match within range allowed
- allowlist: CIDR match outside range rejected
- allowlist: empty allowlist denies everything
- CIDR: malformed (no slash, bad prefix) rejected
- CIDR: /0 (match-all) works
- IPv4: malformed destination rejected
- default allowlist contains common destinations and typed entries
Adds an in-process Hono app harness + the OIDC token end-to-end test.
Exercises the full token flow: bearer auth, runnerOwnsJob check, JWT
mint with cache_mode + permissions claims, and signature verification
on the way back.

Files:
- apps/api/src/__tests__/e2e/setup.ts — boots the Hono app in-process,
  sets OIDC_ISSUER + OIDC_SIGNING_SECRET env vars, exposes a fetch()
  wrapper for tests.
- apps/api/src/__tests__/e2e/oidc-roundtrip.test.ts — full round-trip:
  - 401 on missing Authorization
  - 403 when runner doesn't own the job
  - 200 with valid JWT when runner owns the job
  - Verifies iss, aud, sub, cache_mode, permissions claims
  - Verifies exp is ~5 minutes from now
  - Verifies signature mismatch on tampered token
- docs/e2e-tests.md — setup instructions and scope.

Setup:
  DATABASE_URL=postgres://... pnpm vitest run src/__tests__/e2e

Requires Postgres + migrations 0001_runners.sql and
0002_fork_pr_permissions.sql applied.

Out of scope (documented in e2e-tests.md):
  - Go runner binary integration (handled by openforge/runner tests)
  - Real sandbox boot (requires runsc/kata-runtime installed)
  - Real egress filter (requires eBPF or iptables)
  - Webhook delivery end-to-end
…op work)

Re-adds the laptop-only phrasings on top of the zhTweak/esTweak rewriters from 3.5.3-3.5.5: Traditional Chinese command words (刪除/合計/貨幣/主題/低於/紅色/改為/欄 ...) are mapped to Simplified before matching, column names are left as typed; Spanish 'menos que', 'modo <tema>', and verb forms sumar/promediar/contar.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants