oficina / equipo Public

Mac slice F task 12 fix 2: no scan path exclusions, lost records, header

Astra round 2, three Important, fixed tests-first:

1. The worker's gitleaks rules are the pinned defaults with every path
   exclusion removed (the global list, and each rule's allow list naming
   paths); file-name rules stay. A secret under node_modules, in
   gitleaks.toml or in a .bin file now ends secret_in_candidate.
2. A record failure at the scanner's start (Gate.Run reports it as
   checks_unavailable) maps to errScanUnproven: the step ends
   secret_in_candidate unterminated.
3. State.pack is the single header comparison (awaitPack no longer
   compares the first chunk).

Mutations, each a test failure: H1 global exclusions kept, H2 per-rule
exclusions kept, H3 and H4 preview rules on the worker, H5 and H5b a
lost record as an ordinary scanner error, H6 a mismatched later chunk,
H7 a wrong first header.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev f494162e9b1cbc6ad9f1ee296d278ffc58c893b4 parent 24a53f2
5 files changed, +226 −25
  • .rastrillo/budgets.txt +1 −1
  • internal/runner/thin/preview_security.go +9 −4
  • internal/runner/thin/worker_checks.go +6 −6
  • internal/runner/thin/worker_engineering_test.go +129 −13
  • internal/runner/thin/worker_scan.go +81 −1
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 20bae02c..8ee440b0 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full
perf GET /releases/* skip Verified runner release file downloads, not browser GET screens.
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s;
-size internal/runner/thin 33317 29899 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials, worker conns, worker Engineering; measured 33317/29899.
+size internal/runner/thin 33402 30015 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials, worker conns, worker Engineering; measured 33402/30015.
time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes.
time internal/runner/mac 45s Real processes killed and proven gone: groups, sessions, the runner-user sweep, turns, restarts; probes end to end. Measured 29.3s locally.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s).
diff --git a/internal/runner/thin/preview_security.go b/internal/runner/thin/preview_security.go
index f23b4e6c..ab289f5e 100644
--- a/internal/runner/thin/preview_security.go
+++ b/internal/runner/thin/preview_security.go
@@ -90,6 +90,11 @@ var errScanner = errors.New("the secret scanner could not scan")
// finding, else errScanner when it could not tell. Its report is read
// for a count only: no finding's text is kept.
func (e *Engineer) gitleaks(ctx context.Context, stage string) (bool, error) {
+ return e.gitleaksWith(ctx, stage, previewSecretRules)
+}
+
+// gitleaksWith is gitleaks with the trusted rules given.
+func (e *Engineer) gitleaksWith(ctx context.Context, stage, rules string) (bool, error) {
binary, pin := previewScannerTool(e.O.Runner)
if !release.VerifyGitleaks(binary, pin) {
return false, errScanner
@@ -102,7 +107,7 @@ func (e *Engineer) gitleaks(ctx context.Context, stage string) (bool, error) {
config := filepath.Join(dir, "trusted.toml")
ignore := filepath.Join(dir, "empty.ignore")
report := filepath.Join(dir, "findings.json")
- if os.WriteFile(config, []byte(previewSecretRules), 0600) != nil || os.WriteFile(ignore, nil, 0600) != nil {
+ if os.WriteFile(config, []byte(rules), 0600) != nil || os.WriteFile(ignore, nil, 0600) != nil {
return false, errScanner
}
args := func(bin, cfg, ign, rep, files string) []string {
@@ -155,10 +160,10 @@ func readFindings(report string) (bool, error) {
}
// workerLeaks is the worker's scanner off a Mac (the test build's fake
-// worker on Linux): the preview scanner's bubblewrap; marker and record
-// are not needed there.
+// worker on Linux): the preview scanner's bubblewrap with the worker's
+// trusted rules; marker and record are not needed there.
func (e *Engineer) workerLeaks(ctx context.Context, stage, _ string, _ func(string) error) (bool, error) {
- return e.gitleaks(ctx, stage)
+ return e.gitleaksWith(ctx, stage, workerSecretRules())
}
type previewRefusalError struct{ reason string }
diff --git a/internal/runner/thin/worker_checks.go b/internal/runner/thin/worker_checks.go
index abd6bfd6..146c8266 100644
--- a/internal/runner/thin/worker_checks.go
+++ b/internal/runner/thin/worker_checks.go
@@ -135,9 +135,10 @@ func (w *Worker) checks(ctx context.Context, r stepRow, progress func(wire.StepR
return done(wire.ChecksFailed, "")
}
-// awaitPack waits for every chunk of the attempt's inbound transfer and
-// checks its header against want (what the step row says, whatever its
-// id) before reassembling it.
+// awaitPack waits for every chunk of the attempt's inbound transfer
+// (the transfer its first chunk names) and reassembles it: State.pack
+// refuses it unless every chunk's header is want (what the step row says,
+// with that id).
func (w *Worker) awaitPack(ctx context.Context, r stepRow, want wire.TransferHeader) ([]byte, error) {
wait := w.PackWait
if wait <= 0 {
@@ -150,10 +151,9 @@ func (w *Worker) awaitPack(ctx context.Context, r stepRow, want wire.TransferHea
return nil, err
}
if ok {
+ // State.pack is the one comparison: every chunk's header,
+ // the first included, must be want.
want.ID = h.ID
- if h != want {
- return nil, errPackRefused
- }
pack, err := w.State.pack(ctx, want)
if !errors.Is(err, ErrPackIncomplete) {
return pack, err
diff --git a/internal/runner/thin/worker_engineering_test.go b/internal/runner/thin/worker_engineering_test.go
index 93fc665e..64b948d9 100644
--- a/internal/runner/thin/worker_engineering_test.go
+++ b/internal/runner/thin/worker_engineering_test.go
@@ -9,6 +9,7 @@ import (
"encoding/base64"
"encoding/hex"
"encoding/json"
+ "errors"
"fmt"
"log/slog"
"os"
@@ -26,6 +27,8 @@ import (
"amadan.net/oficina/equipo/internal/runner/mac"
"amadan.net/oficina/equipo/internal/runner/provider"
"amadan.net/oficina/equipo/internal/wire"
+ "github.com/spf13/viper"
+ gitleaksconfig "github.com/zricethezav/gitleaks/v8/config"
)
// Engineering on a Mac worker (Mac runners slice F, task 12) on Linux:
@@ -543,16 +546,20 @@ func TestWorkerObjectScan(t *testing.T) {
base map[string]string
kind string
}{
- "gitleaks by file name": {note: "create:nuget.config|<configuration><packageSourceCredentials><feed><add key=\"Username\" value=\"me\" /><add key=\"ClearTextPassword\" value=\"Xk9pQ2vR7sLm4TzWq8Ny\" /></feed></packageSourceCredentials></configuration>", names: []string{"nuget.config"}, kind: "gitleaks"},
- "gitleaks in a renamed file": {base: map[string]string{"old-settings.txt": "token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"\n"}, note: "move:old-settings.txt|moved-settings.txt", names: []string{"moved-settings.txt"}, kind: "gitleaks"},
- "raw in a text file": {note: "create:notes.txt|key " + token, names: []string{"notes.txt"}},
- "base64 in a binary file": {note: "bytes:blob.bin|" + base64.StdEncoding.EncodeToString(binary), names: []string{"blob.bin"}},
- "in a file name": {note: "create:" + token + ".txt|hello"},
- "in a symlink target": {note: "symlink:planted-link|/tmp/" + token, names: []string{"planted-link"}},
- "in the commit message": {note: "edit:Swipe.swift|false|true\nsay:" + token},
- "hex-encoded": {note: "create:hex.txt|" + hex.EncodeToString([]byte(token)), names: []string{"hex.txt"}},
- "the runner credential, URL": {note: "create:cred.txt|" + urlForm, names: []string{"cred.txt"}},
- "gitleaks finds a key": {note: "create:keys.txt|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"keys.txt"}},
+ // Paths gitleaks' defaults would skip are scanned on a worker.
+ "gitleaks under node_modules": {note: "create:node_modules/key.txt|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"node_modules/key.txt"}, kind: "gitleaks"},
+ "gitleaks in gitleaks.toml": {note: "create:gitleaks.toml|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"gitleaks.toml"}, kind: "gitleaks"},
+ "gitleaks in a .bin file": {note: "create:firmware.bin|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"firmware.bin"}, kind: "gitleaks"},
+ "gitleaks by file name": {note: "create:nuget.config|<configuration><packageSourceCredentials><feed><add key=\"Username\" value=\"me\" /><add key=\"ClearTextPassword\" value=\"Xk9pQ2vR7sLm4TzWq8Ny\" /></feed></packageSourceCredentials></configuration>", names: []string{"nuget.config"}, kind: "gitleaks"},
+ "gitleaks in a renamed file": {base: map[string]string{"old-settings.txt": "token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"\n"}, note: "move:old-settings.txt|moved-settings.txt", names: []string{"moved-settings.txt"}, kind: "gitleaks"},
+ "raw in a text file": {note: "create:notes.txt|key " + token, names: []string{"notes.txt"}},
+ "base64 in a binary file": {note: "bytes:blob.bin|" + base64.StdEncoding.EncodeToString(binary), names: []string{"blob.bin"}},
+ "in a file name": {note: "create:" + token + ".txt|hello"},
+ "in a symlink target": {note: "symlink:planted-link|/tmp/" + token, names: []string{"planted-link"}},
+ "in the commit message": {note: "edit:Swipe.swift|false|true\nsay:" + token},
+ "hex-encoded": {note: "create:hex.txt|" + hex.EncodeToString([]byte(token)), names: []string{"hex.txt"}},
+ "the runner credential, URL": {note: "create:cred.txt|" + urlForm, names: []string{"cred.txt"}},
+ "gitleaks finds a key": {note: "create:keys.txt|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"keys.txt"}},
"the scanner fails": {note: "edit:Swipe.swift|false|true", before: func(t *testing.T, x *engRig) {
script := filepath.Join(x.dir, "bin", "gitleaks")
os.Remove(script)
@@ -1190,9 +1197,10 @@ func TestGateLeaks(t *testing.T) {
files map[string]string
found bool
}{
- "clean": {map[string]string{"a.swift": "let a = 1\n"}, false},
- "a key": {map[string]string{"keys.txt": "token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"\n"}, true},
- "by name": {map[string]string{"nuget.config": "<configuration><packageSourceCredentials><feed><add key=\"ClearTextPassword\" value=\"Xk9pQ2vR7sLm4TzWq8Ny\" /></feed></packageSourceCredentials></configuration>\n"}, true},
+ "clean": {map[string]string{"a.swift": "let a = 1\n"}, false},
+ "under node_modules": {map[string]string{"node_modules/k.txt": "token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"\n"}, true},
+ "a key": {map[string]string{"keys.txt": "token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"\n"}, true},
+ "by name": {map[string]string{"nuget.config": "<configuration><packageSourceCredentials><feed><add key=\"ClearTextPassword\" value=\"Xk9pQ2vR7sLm4TzWq8Ny\" /></feed></packageSourceCredentials></configuration>\n"}, true},
} {
t.Run(name, func(t *testing.T) {
stage := filepath.Join(t.TempDir(), "scan", "files")
@@ -1228,3 +1236,111 @@ func TestMacLeaksNeedTheProvenGate(t *testing.T) {
t.Fatal("scanned without the proven gate")
}
}
+
+// Fix round 2, #1: the worker's trusted rules are gitleaks' defaults with
+// no path exclusion at all (global or per rule), its file-name rules
+// kept, and the runner's own rules added.
+func TestWorkerSecretRules(t *testing.T) {
+ v := viper.New()
+ v.SetConfigType("toml")
+ if err := v.ReadConfig(strings.NewReader(workerSecretRules())); err != nil {
+ t.Fatal(err)
+ }
+ var raw gitleaksconfig.ViperConfig
+ if err := v.Unmarshal(&raw); err != nil {
+ t.Fatal(err)
+ }
+ cfg, err := raw.Translate()
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, a := range cfg.Allowlists {
+ if len(a.Paths) != 0 {
+ t.Fatalf("a global path exclusion: %v", a.Paths)
+ }
+ }
+ for id, r := range cfg.Rules {
+ for _, a := range r.Allowlists {
+ if len(a.Paths) != 0 {
+ t.Fatalf("rule %s excludes paths: %v", id, a.Paths)
+ }
+ }
+ }
+ for _, id := range []string{"nuget-config-password", "pkcs12-file", "github-pat", "equipo-github-token", "equipo-private-key-header"} {
+ if _, ok := cfg.Rules[id]; !ok {
+ t.Errorf("rule %s missing", id)
+ }
+ }
+ if r := cfg.Rules["nuget-config-password"]; r.Path == nil {
+ t.Error("the nuget rule lost its file name")
+ }
+}
+
+// Fix round 2, #2: the scanner's record cannot be written at its start:
+// the scan's end is unproven, never an ordinary scanner error.
+func TestGateLeaksRecordLost(t *testing.T) {
+ runnerPath := previewScannerFixture(t)
+ binary, pin := previewScannerTool(runner.Config{Executable: runnerPath})
+ g := &mac.Gate{Env: []string{"PATH=/usr/bin:/bin"}, ScratchHome: true, Lines: 10, Sandbox: wire.SandboxNone}
+ stage := filepath.Join(t.TempDir(), "scan", "files")
+ os.MkdirAll(stage, 0o700)
+ os.WriteFile(filepath.Join(stage, "a.swift"), []byte("let a = 1\n"), 0o600)
+ _, err := gateLeaks(context.Background(), g, binary, pin, stage, "scan-test", func(string) error { return errors.New("disk full") })
+ if !errors.Is(err, errScanUnproven) {
+ t.Fatalf("a lost scanner record: %v", err)
+ }
+}
+
+// Fix round 2, #2: in an attempt, the scanner's record write fails as it
+// starts: secret_in_candidate, unterminated, nothing uploaded.
+func TestWorkerEngineeringScannerRecordLost(t *testing.T) {
+ x := newEngRig(t)
+ x.note("edit:Swipe.swift|false|true")
+ runnerPath := previewScannerFixture(t)
+ binary, pin := previewScannerTool(runner.Config{Executable: runnerPath})
+ g := &mac.Gate{Env: []string{"PATH=/usr/bin:/bin"}, ScratchHome: true, Lines: 10, Sandbox: wire.SandboxSeatbelt}
+ x.w.Eng.Leaks = func(ctx context.Context, stage, marker string, record func(string) error) (bool, error) {
+ return gateLeaks(ctx, g, binary, pin, stage, marker, record)
+ }
+ stage := filepath.Join(x.w.stepsDir(), stepKey(x.r), "scan", "files")
+ if _, err := x.state.db.Exec("CREATE TRIGGER lost_scan BEFORE UPDATE OF ns_id ON steps WHEN NEW.ns_id = '" + mac.RecordID(0, engineeringMarker(stage)) + "' BEGIN SELECT RAISE(FAIL, 'lost'); END"); err != nil {
+ t.Fatal(err)
+ }
+ rep := x.run(t)
+ if rep.State != wire.StepFailed || rep.Reason != wire.ReasonSecretInCandidate || rep.Termination || rep.CandidateSHA != "" {
+ t.Fatalf("report %+v", rep)
+ }
+ if c := x.committed(); c.CandidateSHA != "" {
+ t.Fatalf("committed %+v", c)
+ }
+}
+
+// Fix round 2, #3: every chunk's header is compared (State.pack), the
+// later ones too.
+func TestWorkerEngineeringRefusesALaterChunk(t *testing.T) {
+ x := newEngRig(t)
+ x.w.PackWait = 300 * time.Millisecond
+ x.note("edit:Swipe.swift|false|true")
+ h := x.engHeader()
+ pack, err := x.pri.e.packCommits(context.Background(), h)
+ if err != nil {
+ t.Fatal(err)
+ }
+ sum := sha256.Sum256(pack)
+ half := len(pack) / 2
+ other := h
+ other.TaskID = "tkother"
+ for i, c := range []struct {
+ h wire.TransferHeader
+ data []byte
+ }{{h, pack[:half]}, {other, pack[half:]}} {
+ if err := x.state.AcceptChunk(context.Background(), fmt.Sprintf("chunk-%d", i), wire.Blob{Transfer: c.h, Index: i, Total: 2, SHA256: hex.EncodeToString(sum[:]), Data: base64.StdEncoding.EncodeToString(c.data)}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ before := x.steps()
+ rep := x.exec(t, x.r)
+ if rep.State != wire.StepFailed || rep.Reason != "candidate_unavailable" || x.steps() != before {
+ t.Fatalf("report %+v", rep)
+ }
+}
diff --git a/internal/runner/thin/worker_scan.go b/internal/runner/thin/worker_scan.go
index a04b8210..78fd0f12 100644
--- a/internal/runner/thin/worker_scan.go
+++ b/internal/runner/thin/worker_scan.go
@@ -1,6 +1,9 @@
package thin
import (
+ "sync"
+
+ gitleaksconfig "github.com/zricethezav/gitleaks/v8/config"
"time"
"amadan.net/oficina/equipo/internal/release"
@@ -329,7 +332,7 @@ func gateLeaks(ctx context.Context, g *mac.Gate, binary, pin, stage, marker stri
}
root := filepath.Dir(stage)
config, ignore, report := filepath.Join(root, "trusted.toml"), filepath.Join(root, "empty.ignore"), filepath.Join(root, "findings.json")
- if os.WriteFile(config, []byte(previewSecretRules), 0600) != nil || os.WriteFile(ignore, nil, 0600) != nil {
+ if os.WriteFile(config, []byte(workerSecretRules()), 0600) != nil || os.WriteFile(ignore, nil, 0600) != nil {
return false, errScanner
}
if record == nil {
@@ -340,6 +343,12 @@ func gateLeaks(ctx context.Context, g *mac.Gate, binary, pin, stage, marker stri
switch {
case !res.Terminated:
return false, errScanUnproven
+ case res.Reason == "checks_unavailable":
+ // The gate's start failed, a record write included (the scan's
+ // marker or group, or its turn's record: Gate.Run reports each
+ // so), or its turn's record was lost while it ran: its end is not
+ // proven, whatever ran.
+ return false, errScanUnproven
case res.Reason != "":
return false, errScanner
}
@@ -352,3 +361,74 @@ func gateLeaks(ctx context.Context, g *mac.Gate, binary, pin, stage, marker stri
}
return false, nil
}
+
+// workerSecretRules is the worker's trusted gitleaks configuration: the
+// pinned build's own default rules (gitleaks' config.DefaultConfig, the
+// same version as the scanner), with every path exclusion taken out (the
+// global list, and each rule's allow list that names paths, whole), so a
+// secret under node_modules, in gitleaks.toml or in a .bin file is found
+// like any other; the rules that go by a file's name (nuget.config,
+// .p12) stay. The runner's own rules are added, as for previews.
+var workerSecretRules = sync.OnceValue(func() string {
+ var out []string
+ for _, block := range tomlBlocks(gitleaksconfig.DefaultConfig) {
+ header := strings.TrimSpace(strings.SplitN(block, "\n", 2)[0])
+ switch {
+ case header == "[[rules.allowlists]]" && hasPaths(block):
+ continue
+ case header == "[allowlist]":
+ block = withoutPaths(block)
+ }
+ out = append(out, block)
+ }
+ return strings.Join(out, "") + "\n" + strings.TrimPrefix(previewSecretRules, "[extend]\nuseDefault = true\n")
+})
+
+// tomlBlocks splits a TOML document before each table header (a line
+// starting "["), keeping every byte.
+func tomlBlocks(doc string) []string {
+ var out []string
+ start := 0
+ for i := 0; i < len(doc); {
+ end := strings.IndexByte(doc[i:], '\n')
+ if end < 0 {
+ break
+ }
+ next := i + end + 1
+ if next < len(doc) && doc[next] == '[' {
+ out = append(out, doc[start:next])
+ start = next
+ }
+ i = next
+ }
+ return append(out, doc[start:])
+}
+
+// hasPaths: the block sets paths.
+func hasPaths(block string) bool {
+ for _, line := range strings.Split(block, "\n") {
+ if strings.HasPrefix(strings.TrimSpace(line), "paths") && strings.Contains(line, "=") {
+ return true
+ }
+ }
+ return false
+}
+
+// withoutPaths is the block with its paths array (to its closing "]"
+// line) removed.
+func withoutPaths(block string) string {
+ var out []string
+ skipping := false
+ for _, line := range strings.SplitAfter(block, "\n") {
+ t := strings.TrimSpace(line)
+ switch {
+ case !skipping && strings.HasPrefix(t, "paths") && strings.Contains(t, "="):
+ skipping = !strings.HasSuffix(t, "]")
+ case skipping:
+ skipping = t != "]"
+ default:
+ out = append(out, line)
+ }
+ }
+ return strings.Join(out, "")
+}