staticcheck: switch SA1019 on; every SA check now runs
Go code-health batch 3 (#1123). Deprecated APIs migrated where behaviour stays identical: go/parser.ParseDir, test ReverseProxy Directors, ecdsa raw key coordinates (the database handle secret is byte-for-byte the same on every accepted key) and tar.TypeRegA. The 41 sites left carry a lint:ignore naming the blocker, mostly the edge tunnel's use of golang.org/x/net/http2, which net/http cannot replace yet. staticcheck.conf now enables every SA check. Reviewed by Astra (round 1, READY AFTER FIXES; the key-width P2 fixed in 20009722, scoped check passed). Census approved on #280. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from staticcheck-sa1019 into main.
39 files changed,
+595
−180
docs/superpowers/notes/census-proposal-staticcheck-sa1019.md+19 −0docs/superpowers/reviews/CHECK-BRIEF-staticcheck-sa1019-R1-fix.md+18 −0docs/superpowers/reviews/CHECK-staticcheck-sa1019-R1-fix.md+13 −0docs/superpowers/reviews/FINDINGS-staticcheck-sa1019-R1.md+40 −0docs/superpowers/reviews/REVIEW-BRIEF-staticcheck-sa1019.md+41 −0internal/activator/claimgen_test.go+14 −22internal/activator/tenancies_test.go+49 −33internal/activator/tunnel_refuse_test.go+5 −2internal/apppolicy/writers_test.go+1 −0internal/awsmanaged/storage.go+1 −0internal/awsmanaged/storage_test.go+6 −0internal/boxroles/imports_test.go+16 −8internal/console/apidbclaim.go+18 −1internal/console/apidbclaim_test.go+51 −0internal/console/keymail_test.go+3 −4internal/console/opshots_test.go+119 −10internal/console/store_gate.go+4 −2internal/console/svcroutes_test.go+16 −14internal/demobuild/source.go+5 −1internal/demobuild/source_test.go+12 −0internal/edge/certsync_e2e_test.go+5 −5internal/edge/demo_countdown_test.go+1 −1internal/edge/demo_forward_test.go+1 −1internal/edge/replica_reach_test.go+1 −0internal/edge/replicaproxy_test.go+1 −0internal/edge/tunnel.go+8 −2internal/edge/upgrades_test.go+3 −0internal/groupadmission/state_test.go+14 −8internal/host/pagearm_test.go+2 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-staticcheck-sa1019.tsv+8 −0internal/tunnelclient/drain_test.go+3 −0internal/tunnelclient/refuse_test.go+6 −0internal/tunnelclient/tlsstate_test.go+3 −0internal/tunnelclient/tunnelclient_test.go+1 −0internal/tunnelclient/upgrade.go+11 −2internal/tunnelclient/upgrade_box_test.go+3 −0move_offline_run_test.go+64 −54staticcheck.conf+8 −10
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-staticcheck-sa1019.md b/docs/superpowers/notes/census-proposal-staticcheck-sa1019.md| new file mode 100644 |
| index 000000000..7a85548b1 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-staticcheck-sa1019.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: staticcheck-sa1019 |
| + |
| +Ruling `census-ruling-staticcheck-sa1019`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `staticcheck.conf` `external` | body | unchanged (1) | Turns SA1019 on (drops -SA1019 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added. | |
| + |
| +Envelopes re-pinned: `.`, `internal/demobuild`, `internal/edge`, `internal/tunnelclient`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `staticcheck.conf` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-audit-gate-vet-staticcheck;basis=new: staticcheck configuration at the module root (which SA checks run). Read only by the staticcheck tool in CI and make staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa4006;basis=Turns SA4006 on (drops -SA4006 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa1012;basis=SA1012 removed from the excluded checks and the comment updated; a lint setting, no code path changes |
| + |
| +Seal: `5fcd060180e923773dad3faee7cc60ee250779a242b1dc14f4576f413dc8a774` → `f9be26c06eb1c844b91a75f65faa51997048cb2900f3ed078be2ae28c65c0e98`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-staticcheck-sa1019.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/reviews/CHECK-BRIEF-staticcheck-sa1019-R1-fix.md b/docs/superpowers/reviews/CHECK-BRIEF-staticcheck-sa1019-R1-fix.md| new file mode 100644 |
| index 000000000..78b761865 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CHECK-BRIEF-staticcheck-sa1019-R1-fix.md |
| @@ -0,0 +1,18 @@ |
| +# Scoped check: staticcheck-sa1019, after round 1 (not a review round) |
| + |
| +Repo carlos/platform, branch `staticcheck-sa1019` (tip in the prompt). |
| +Round 1 (`docs/superpowers/reviews/FINDINGS-staticcheck-sa1019-R1.md`) ended |
| +READY AFTER FIXES with one P2 in `dbHandleSecret`. The fix is commit |
| +20009722. Scope: `git show 20009722` only. |
| + |
| +Check: |
| +1. The P2: resolved, partly, not. |
| +2. For every ECDSA key the old `D.FillBytes(make([]byte, 32))` accepted, is |
| + the derived secret byte-for-byte the same, on P-256, P-384 and P-521? |
| + Does every key it refused still refuse? Independently recompute the |
| + golden values if you can. |
| +3. Do the fixtures fail under the mutations they claim? |
| + |
| +Answer each: OK, or a finding with file:line, failure scenario and fix, |
| +marked P1 or P2. End with exactly one line: CHECK PASSED, or CHECK FAILED |
| +with the P1s. Do not edit files, spawn reviewers or run full suites. |
diff --git a/docs/superpowers/reviews/CHECK-staticcheck-sa1019-R1-fix.md b/docs/superpowers/reviews/CHECK-staticcheck-sa1019-R1-fix.md| new file mode 100644 |
| index 000000000..df10787ea |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CHECK-staticcheck-sa1019-R1-fix.md |
| @@ -0,0 +1,13 @@ |
| +Scoped check of `20009722` at tip `8a172df63aec562626c54fa9c10449e6f16c3de4`. No P1 or P2 findings. |
| + |
| +1. **OK — the round-one P2 is resolved.** [apidbclaim.go:66](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/apidbclaim.go:66) discards excess leading zero bytes and panics if any excess byte is nonzero. Valid P-384 and P-521 keys whose scalars fit in 32 bytes are accepted again. |
| + |
| +2. **OK — derivation and overflow refusal are preserved for valid P-256, P-384 and P-521 keys.** Removing only leading zeros preserves the integer value. Padding the remainder to 32 bytes therefore produces exactly the old `D.FillBytes(make([]byte, 32))` input to HMAC. Every scalar requiring more than 32 bytes still panics. |
| + |
| + I independently recomputed all five fixture goldens using Python’s HMAC-SHA256; all matched. An additional 5,018 deterministic boundary and sampled encoding cases across the three curves matched the old encoding or overflow refusal. This equivalence concerns valid ECDSA keys: `Bytes()` also validates malformed key structs, unlike `FillBytes`; that behavior predates the scoped fix. |
| + |
| +3. **OK — the fixtures detect the relevant mutations.** The fitting P-384 fixtures at [apidbclaim_test.go:118](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/apidbclaim_test.go:118) detect rejecting all wide encodings, retaining the full curve width, and taking the first 32 bytes. The deterministic 257-bit fixture at [apidbclaim_test.go:135](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/apidbclaim_test.go:135) detects truncation without overflow refusal. Independent in-memory mutation simulations confirmed these results. |
| + |
| +Validation limit: the focused Go test could not run because Go attempted to update `go.mod` on the read-only filesystem. Mutation simulations did not execute the Go tests. No files were edited, reviewers spawned, or full suites run. |
| + |
| +CHECK PASSED |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/FINDINGS-staticcheck-sa1019-R1.md b/docs/superpowers/reviews/FINDINGS-staticcheck-sa1019-R1.md| new file mode 100644 |
| index 000000000..16c61a1d7 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-staticcheck-sa1019-R1.md |
| @@ -0,0 +1,40 @@ |
| +Round 1, reviewing `5048247f1c7a077530e2c12003fafcebd92f8a0f...80304c738bf190ed02c2e900213b2f7abbe29a36`. The requested tip adds only the review brief to the commit named inside it. |
| + |
| +**P1: None found.** |
| + |
| +**P2: Preserve scalar-width compatibility for larger curves.** |
| +[internal/console/apidbclaim.go:64](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/apidbclaim.go:64) |
| + |
| +`PrivateKey.Bytes()` returns the curve’s fixed-width encoding. The old `D.FillBytes(make([]byte, 32))` rejected a scalar only when its **value** needed more than 32 bytes. The new check rejects every P-384 or P-521 key, including valid keys whose scalar fits. |
| + |
| +For example, a valid P-384 key with `D = 1` previously produced a handle secret; its new 48-byte encoding triggers the panic. [Store.SigningKey:3350](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/store.go:3350) checks that a loaded key is ECDSA without restricting its curve. Such a stored key therefore changes from successful startup to a panic. Generated P-256 keys are unaffected, so this is an edge-case compatibility finding. |
| + |
| +Fix: when the encoding exceeds 32 bytes, reject only if an excess leading byte is nonzero; otherwise use its final 32 bytes. Add deterministic P-384 fixtures for a fitting scalar and an overflowing scalar. The current [test:132](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/console/apidbclaim_test.go:132) exercises only a randomly generated large scalar and misses this distinction. |
| + |
| +Fault family: preserve the accepted key set and byte-for-byte database-handle derivation. |
| + |
| +**P3: None.** |
| + |
| +The remaining checks found: |
| + |
| +- **Tar acceptance is unchanged.** `tar.TypeRegA` and `tarTypeRegNUL` both equal `'\x00'`. The physical-header predicate, link/device refusal, path validation and size checks retain their behavior. |
| +- **All 16 production suppressions are justified and line-scoped.** The tunnel needs x/net’s explicit ping and closing state, existing-connection handling, and server-specific draining/refusal machinery. In particular, `h2StreamID` depends on x/net’s response-writer shape. `Request.Cancel` remains active in the pinned transport. The S3 SDK retains legacy `Prefix` responses, and the SQL wrapper already prefers context methods before falling back. None offers a straightforward behavior-preserving migration within this change. |
| +- **The Director migrations are test-only.** No production reverse proxy changes. |
| +- **The parser migrations retain their scan scope**, including files excluded by build tags, and preserve object resolution where the guards use it. |
| +- **The new tests target their claimed mutations.** Source inspection confirms that refusing NUL headers, removing the legacy-prefix check, or using bare `SetURL` contradicts their assertions. Independently recomputing the three secret goldens matched the old derivation. The missing key-width case is covered by the P2 above. |
| + |
| +**Census verdicts for the reviewed tip:** |
| + |
| +| Unit or envelope | Verdict and evidence | |
| +|---|---| |
| +| `staticcheck.conf:external` | **APPROVE.** [Line 35](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/staticcheck.conf:35) enables SA1019. Its SHA-256 matches the overlay. The existing `legacy / accepted-legacy` disposition remains appropriate; no root read is added. | |
| +| `.` | **APPROVE.** The configuration change affects tooling. [move_offline_run_test.go:1336](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/move_offline_run_test.go:1336) retains the source guard’s checks. No production root behavior changes. | |
| +| `internal/demobuild` | **APPROVE.** [source.go:242](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/demobuild/source.go:242) substitutes an identical constant. No archive acceptance or refusal boundary changes. | |
| +| `internal/edge` | **APPROVE.** Production changes in [tunnel.go:101](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/edge/tunnel.go:101) are suppressions and formatting. Authentication, connection adoption, liveness and retry classification remain unchanged. | |
| +| `internal/tunnelclient` | **APPROVE.** [upgrade.go:116](/home/paulca/amadan.net/carlos/platform-staticcheck-sa1019/internal/tunnelclient/upgrade.go:116) and `RoundTripUpgrade` retain their executable behavior. No draining, refusal or upgrade boundary is weakened. | |
| + |
| +Validation limits: focused Go tests and the census dependency check could not complete because the filesystem is read-only. Mutation tests were assessed from source, not executed. Changed Go files pass `gofmt`; `git diff --check` is clean. No files were edited, reviewers spawned, or full suites run. |
| + |
| +Apply the P2 within round 1 without reopening the review, retaining the required security-change check on the resulting fix. |
| + |
| +READY AFTER FIXES |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-staticcheck-sa1019.md b/docs/superpowers/reviews/REVIEW-BRIEF-staticcheck-sa1019.md| new file mode 100644 |
| index 000000000..27f8f405a |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-staticcheck-sa1019.md |
| @@ -0,0 +1,41 @@ |
| +# Review brief: branch staticcheck-sa1019, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `staticcheck-sa1019`, commit 2af919b117dabd4645d386aa5d5349bbae63f4ea. |
| +Under review: the diff `origin/main...2af919b117dabd4645d386aa5d5349bbae63f4ea` (base 5048247f). |
| +Authorities: the Go code-health plan (batch 3), AGENTS.md ("The census", |
| +"Stopping rules"). |
| + |
| +You are the independent reviewer and census reviewer (card: |
| +`docs/superpowers/notes/census-proposal-staticcheck-sa1019.md`). The branch |
| +migrates some deprecated APIs and suppresses the rest with 41 lint:ignore |
| +comments (16 production, 25 test), then turns SA1019 on. |
| + |
| +## What to check |
| + |
| +1. **internal/console/apidbclaim.go (ecdsa raw coordinates replaced).** A |
| + secret or handle derived from a public key must come out byte-for-byte |
| + the same as before for every key, including coordinates with leading |
| + zeros. A change here would invalidate existing DB handles or claims. |
| +2. **internal/demobuild/source.go (tar.TypeRegA).** Same accept and refuse |
| + set for tar entries as before, the NUL typeflag included; no new way |
| + for a tenant-supplied archive to pass (links, devices, path handling). |
| +3. **Each lint:ignore in production** (edge/tunnel.go, tunnelclient/ |
| + upgrade.go, awsmanaged/storage.go, console/store_gate.go): is the |
| + stated blocker true, and is the suppression as narrow as it can be? Is |
| + any one of them easily migratable, so that it should be migrated now? |
| +4. The ReverseProxy Director change is claimed to be test-only: confirm no |
| + production proxy changed. |
| +5. New tests pin behaviour; each fails under the mutation claimed? |
| +6. Census verdicts. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Follow-up list only. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix. Then |
| +census verdicts. End with exactly one verdict: READY, READY AFTER FIXES, |
| +or NOT READY. Do not edit files, spawn reviewers or run full suites. |
diff --git a/internal/activator/claimgen_test.go b/internal/activator/claimgen_test.go| index 4a0c4272b..bdf42f15c 100644 |
| --- a/internal/activator/claimgen_test.go |
| +++ b/internal/activator/claimgen_test.go |
| @@ -5,9 +5,7 @@ import ( |
| "errors" |
| "fmt" |
| "go/ast" |
| - "go/parser" |
| "go/token" |
| - "io/fs" |
| "os/exec" |
| "strings" |
| "testing" |
| @@ -426,27 +424,21 @@ func TestEveryClaimsBackedSwapIsRefusedBeforeItsSideEffects(t *testing.T) { |
| func TestClaimSpawnIsATestSeam(t *testing.T) { |
| t.Parallel() |
| fset := token.NewFileSet() |
| - pkgs, err := parser.ParseDir(fset, ".", func(fi fs.FileInfo) bool { return !strings.HasSuffix(fi.Name(), "_test.go") }, 0) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - for _, pkg := range pkgs { |
| - for name, file := range pkg.Files { |
| - ast.Inspect(file, func(n ast.Node) bool { |
| - switch x := n.(type) { |
| - case *ast.AssignStmt: |
| - for _, l := range x.Lhs { |
| - if sel, ok := l.(*ast.SelectorExpr); ok && sel.Sel.Name == "claimSpawn" { |
| - t.Errorf("%s: %s assigns claimSpawn", name, fset.Position(x.Pos())) |
| - } |
| - } |
| - case *ast.KeyValueExpr: |
| - if id, ok := x.Key.(*ast.Ident); ok && id.Name == "claimSpawn" { |
| - t.Errorf("%s: %s sets claimSpawn in a literal", name, fset.Position(x.Pos())) |
| + for name, file := range nonTestGoFiles(t, fset) { |
| + ast.Inspect(file, func(n ast.Node) bool { |
| + switch x := n.(type) { |
| + case *ast.AssignStmt: |
| + for _, l := range x.Lhs { |
| + if sel, ok := l.(*ast.SelectorExpr); ok && sel.Sel.Name == "claimSpawn" { |
| + t.Errorf("%s: %s assigns claimSpawn", name, fset.Position(x.Pos())) |
| } |
| } |
| - return true |
| - }) |
| - } |
| + case *ast.KeyValueExpr: |
| + if id, ok := x.Key.(*ast.Ident); ok && id.Name == "claimSpawn" { |
| + t.Errorf("%s: %s sets claimSpawn in a literal", name, fset.Position(x.Pos())) |
| + } |
| + } |
| + return true |
| + }) |
| } |
| } |
diff --git a/internal/activator/tenancies_test.go b/internal/activator/tenancies_test.go| index 217edd0c6..09bed7b31 100644 |
| --- a/internal/activator/tenancies_test.go |
| +++ b/internal/activator/tenancies_test.go |
| @@ -5,7 +5,7 @@ import ( |
| "go/ast" |
| "go/parser" |
| "go/token" |
| - "io/fs" |
| + "os" |
| "strings" |
| "testing" |
| "time" |
| @@ -120,49 +120,65 @@ func TestTenanciesRouteChangedInPlace(t *testing.T) { |
| } |
| } |
| +// nonTestGoFiles parses every non-test .go file in the package directory, |
| +// keyed by name. Build tags do not narrow it: a guard here reads the files |
| +// this platform's build leaves out too. |
| +func nonTestGoFiles(t *testing.T, fset *token.FileSet) map[string]*ast.File { |
| + t.Helper() |
| + entries, err := os.ReadDir(".") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + files := map[string]*ast.File{} |
| + for _, e := range entries { |
| + name := e.Name() |
| + if e.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { |
| + continue |
| + } |
| + f, err := parser.ParseFile(fset, name, nil, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + files[name] = f |
| + } |
| + return files |
| +} |
| + |
| // TestEntriesEnterThroughPutEntryLocked: putEntryLocked is how the host's |
| // tenants are recorded, so an entry inserted any other way would be a |
| // tenant Tenancies never saw. Fails on any other assignment into |
| // a.entries in the package's production code. |
| func TestEntriesEnterThroughPutEntryLocked(t *testing.T) { |
| fset := token.NewFileSet() |
| - pkgs, err := parser.ParseDir(fset, ".", func(fi fs.FileInfo) bool { |
| - return !strings.HasSuffix(fi.Name(), "_test.go") |
| - }, 0) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| found := 0 |
| - for _, pkg := range pkgs { |
| - for _, f := range pkg.Files { |
| - for _, d := range f.Decls { |
| - fn, ok := d.(*ast.FuncDecl) |
| - if !ok || fn.Body == nil { |
| - continue |
| + for _, f := range nonTestGoFiles(t, fset) { |
| + for _, d := range f.Decls { |
| + fn, ok := d.(*ast.FuncDecl) |
| + if !ok || fn.Body == nil { |
| + continue |
| + } |
| + ast.Inspect(fn.Body, func(n ast.Node) bool { |
| + as, ok := n.(*ast.AssignStmt) |
| + if !ok { |
| + return true |
| } |
| - ast.Inspect(fn.Body, func(n ast.Node) bool { |
| - as, ok := n.(*ast.AssignStmt) |
| + for _, lhs := range as.Lhs { |
| + ix, ok := lhs.(*ast.IndexExpr) |
| if !ok { |
| - return true |
| + continue |
| } |
| - for _, lhs := range as.Lhs { |
| - ix, ok := lhs.(*ast.IndexExpr) |
| - if !ok { |
| - continue |
| - } |
| - sel, ok := ix.X.(*ast.SelectorExpr) |
| - if !ok || sel.Sel.Name != "entries" { |
| - continue |
| - } |
| - if fn.Name.Name == "putEntryLocked" { |
| - found++ |
| - continue |
| - } |
| - t.Errorf("%s: %s assigns into entries directly; use putEntryLocked", fset.Position(as.Pos()), fn.Name.Name) |
| + sel, ok := ix.X.(*ast.SelectorExpr) |
| + if !ok || sel.Sel.Name != "entries" { |
| + continue |
| } |
| - return true |
| - }) |
| - } |
| + if fn.Name.Name == "putEntryLocked" { |
| + found++ |
| + continue |
| + } |
| + t.Errorf("%s: %s assigns into entries directly; use putEntryLocked", fset.Position(as.Pos()), fn.Name.Name) |
| + } |
| + return true |
| + }) |
| } |
| } |
| if found != 1 { |
diff --git a/internal/activator/tunnel_refuse_test.go b/internal/activator/tunnel_refuse_test.go| index 1f10e8c4c..2222a3dcd 100644 |
| --- a/internal/activator/tunnel_refuse_test.go |
| +++ b/internal/activator/tunnel_refuse_test.go |
| @@ -34,8 +34,9 @@ func (b *stoppedOutsideBackend) StoppedOutside(string) bool { return b.stopped.L |
| // streams arriving from a fake hub's ClientConn (cc). Its instance waits in |
| // awaitStartup (a.Startup open) until the test stops the activator. |
| type refuseBox struct { |
| - a *Service |
| - b *stoppedOutsideBackend |
| + a *Service |
| + b *stoppedOutsideBackend |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc *http2.ClientConn |
| drain chan struct{} |
| entered chan struct{} |
| @@ -59,6 +60,7 @@ func newRefuseBox(t *testing.T, rt registry.Route) *refuseBox { |
| } |
| x.a = New(Config{Bucket: "test-bucket", Idle: time.Hour}, x.b, reg) |
| x.a.Startup = make(chan struct{}) |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| conns := make(chan *http2.ClientConn, 1) |
| hub := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| conn, bufrw, err := w.(http.Hijacker).Hijack() |
| @@ -68,6 +70,7 @@ func newRefuseBox(t *testing.T, rt registry.Route) *refuseBox { |
| } |
| fmt.Fprintf(bufrw, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: carlos-tunnel/1\r\nConnection: Upgrade\r\n\r\n") |
| bufrw.Flush() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(conn) |
| if err != nil { |
| t.Errorf("h2 client: %v", err) |
diff --git a/internal/apppolicy/writers_test.go b/internal/apppolicy/writers_test.go| index d6d144331..1d9a71865 100644 |
| --- a/internal/apppolicy/writers_test.go |
| +++ b/internal/apppolicy/writers_test.go |
| @@ -314,6 +314,7 @@ func scanFile(fset *token.FileSet, f *ast.File, rel string, seen map[string]int) |
| return out |
| } |
| +//lint:ignore SA1019 this scan resolves names one file at a time; go/types would have to load every package it reads |
| func isTopFunc(o *ast.Object) bool { |
| fd, ok := o.Decl.(*ast.FuncDecl) |
| return o.Kind == ast.Fun && ok && fd.Recv == nil |
diff --git a/internal/awsmanaged/storage.go b/internal/awsmanaged/storage.go| index fee899674..da47174fb 100644 |
| --- a/internal/awsmanaged/storage.go |
| +++ b/internal/awsmanaged/storage.go |
| @@ -428,6 +428,7 @@ func fleetLifecycleRule() s3types.LifecycleRule { |
| // S3 reads it back (an empty filter may come back with or without Prefix). |
| func isFleetLifecycleRule(r s3types.LifecycleRule) bool { |
| f := r.Filter |
| + //lint:ignore SA1019 S3 can still return a rule scoped by the legacy Prefix, and such a rule does not cover the whole bucket |
| return aws.ToString(r.ID) == lifecycleRuleID && r.Status == s3types.ExpirationStatusEnabled && r.Prefix == nil && |
| f != nil && f.And == nil && f.Tag == nil && f.ObjectSizeGreaterThan == nil && f.ObjectSizeLessThan == nil && aws.ToString(f.Prefix) == "" && |
| r.Expiration == nil && len(r.Transitions) == 0 && len(r.NoncurrentVersionTransitions) == 0 && |
diff --git a/internal/awsmanaged/storage_test.go b/internal/awsmanaged/storage_test.go| index 85d9c1108..b56b46bb4 100644 |
| --- a/internal/awsmanaged/storage_test.go |
| +++ b/internal/awsmanaged/storage_test.go |
| @@ -550,6 +550,12 @@ func TestAWSFleetBucketContract(t *testing.T) { |
| r.NoncurrentVersionExpiration = &s3types.NoncurrentVersionExpiration{NoncurrentDays: aws.Int32(30)} |
| w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{r}} |
| }}, |
| + "our rule scoped by the legacy top-level prefix": {testRegion, func(w *fakeS3World, b string) { |
| + r := fleetLifecycleRule() |
| + //lint:ignore SA1019 S3 can still return this field, and the rule that sets it is not ours |
| + r.Prefix = aws.String("logs/") |
| + w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{r}} |
| + }}, |
| "our rule plus another": {testRegion, func(w *fakeS3World, b string) { |
| w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{fleetLifecycleRule(), |
| {ID: aws.String("x"), Status: s3types.ExpirationStatusDisabled, Filter: &s3types.LifecycleRuleFilter{}}}} |
diff --git a/internal/boxroles/imports_test.go b/internal/boxroles/imports_test.go| index 8f481bb0e..adad1417b 100644 |
| --- a/internal/boxroles/imports_test.go |
| +++ b/internal/boxroles/imports_test.go |
| @@ -3,6 +3,8 @@ package boxroles |
| import ( |
| "go/parser" |
| "go/token" |
| + "os" |
| + "path/filepath" |
| "strconv" |
| "strings" |
| "testing" |
| @@ -10,17 +12,23 @@ import ( |
| func TestAdmissionCoreImports(t *testing.T) { |
| for _, dir := range []string{".", "../groupadmission"} { |
| - pkgs, err := parser.ParseDir(token.NewFileSet(), dir, nil, parser.ImportsOnly) |
| + entries, err := os.ReadDir(dir) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - for _, p := range pkgs { |
| - for name, f := range p.Files { |
| - for _, imp := range f.Imports { |
| - path, _ := strconv.Unquote(imp.Path.Value) |
| - if strings.Contains(path, "aws") || strings.HasSuffix(path, "/release") { |
| - t.Errorf("%s imports %s", name, path) |
| - } |
| + for _, e := range entries { |
| + if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") { |
| + continue |
| + } |
| + name := filepath.Join(dir, e.Name()) |
| + f, err := parser.ParseFile(token.NewFileSet(), name, nil, parser.ImportsOnly) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, imp := range f.Imports { |
| + path, _ := strconv.Unquote(imp.Path.Value) |
| + if strings.Contains(path, "aws") || strings.HasSuffix(path, "/release") { |
| + t.Errorf("%s imports %s", name, path) |
| } |
| } |
| } |
diff --git a/internal/console/apidbclaim.go b/internal/console/apidbclaim.go| index 99ca385ff..24e97ad0d 100644 |
| --- a/internal/console/apidbclaim.go |
| +++ b/internal/console/apidbclaim.go |
| @@ -53,8 +53,25 @@ type dbFileHandle struct { |
| SnapshotCRC64 *uint64 `json:"snapshot_crc64,omitempty"` |
| } |
| +// dbHandleSecret derives the handle key from the signing key's scalar, held |
| +// at 32 bytes so handles already issued keep verifying. Bytes pads to the |
| +// curve's width, so on a wider curve the excess leading bytes are zero |
| +// whenever the value fits. A key whose value does not fit, or that cannot |
| +// be encoded, panics: NewServer calls this once, at startup. |
| func dbHandleSecret(key *ecdsa.PrivateKey) []byte { |
| - mac := hmac.New(sha256.New, key.D.FillBytes(make([]byte, 32))) |
| + scalar, err := key.Bytes() |
| + if err != nil { |
| + panic("console: database handle key: " + err.Error()) |
| + } |
| + for len(scalar) > 32 { |
| + if scalar[0] != 0 { |
| + panic("console: database handle key: the signing key's scalar does not fit in 32 bytes") |
| + } |
| + scalar = scalar[1:] |
| + } |
| + padded := make([]byte, 32) |
| + copy(padded[32-len(scalar):], scalar) |
| + mac := hmac.New(sha256.New, padded) |
| mac.Write([]byte("carlos-db-handle-key-v1\x00")) |
| return mac.Sum(nil) |
| } |
diff --git a/internal/console/apidbclaim_test.go b/internal/console/apidbclaim_test.go| index 898057e82..0953f5738 100644 |
| --- a/internal/console/apidbclaim_test.go |
| +++ b/internal/console/apidbclaim_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "crypto/ecdsa" |
| "crypto/elliptic" |
| "crypto/rand" |
| + "encoding/hex" |
| "encoding/json" |
| "errors" |
| "io" |
| @@ -99,6 +100,56 @@ func cloneDoorClaim(c *hostclaim.Claim) *hostclaim.Claim { |
| return &out |
| } |
| +// TestDBHandleSecretIsStable: a handle signed before a deploy has to verify |
| +// after it, so the secret derived from the signing key is pinned to exact |
| +// bytes. The scalar's value is always held in 32 bytes: a short one is padded |
| +// on the left, and only a value that needs more than 32 bytes is refused, |
| +// whatever the width of the curve it is on. |
| +func TestDBHandleSecretIsStable(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + curve elliptic.Curve |
| + scalar string |
| + want string |
| + }{ |
| + {"p256", elliptic.P256(), "c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721", "8714a34444d6b53233f72d189cac8f2f38d0798f20bc93eddebfcf0785958575"}, |
| + {"p256 leading zeros", elliptic.P256(), "00000000000000000000000000000000000000000000000000000000000000a7", "80d5e0a5531a5e5fb1905ca93b00476515363c9a08b53c006a2409feb7bc8933"}, |
| + {"p224 padded to 32 bytes", elliptic.P224(), "f220266e1105bfe3083e03ec2a1a2fbb8dcb1d2a1f2e3d4c5b6a7988", "e1f9ace4df16f326b5a6743db65924cf2abd0eefe1387c4a574f4ca9f5038cca"}, |
| + {"p384 scalar that fits", elliptic.P384(), "00000000000000000000000000000000c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721", "8714a34444d6b53233f72d189cac8f2f38d0798f20bc93eddebfcf0785958575"}, |
| + {"p384 scalar of one", elliptic.P384(), "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "130fa6293b53ed4f6ab2786ad4e431338c77729222cd70777da6ad4f511a9f55"}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + raw, err := hex.DecodeString(tc.scalar) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + key, err := ecdsa.ParseRawPrivateKey(tc.curve, raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := hex.EncodeToString(dbHandleSecret(key)); got != tc.want { |
| + t.Fatalf("secret = %s, want %s", got, tc.want) |
| + } |
| + }) |
| + } |
| + t.Run("p384 scalar one bit past 32 bytes refused", func(t *testing.T) { |
| + raw, err := hex.DecodeString("00000000000000000000000000000001c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + key, err := ecdsa.ParseRawPrivateKey(elliptic.P384(), raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer func() { |
| + if recover() == nil { |
| + t.Fatal("a scalar that needs 33 bytes produced a secret") |
| + } |
| + }() |
| + dbHandleSecret(key) |
| + }) |
| +} |
| + |
| func TestDoorPlanHandles(t *testing.T) { |
| key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| if err != nil { |
diff --git a/internal/console/keymail_test.go b/internal/console/keymail_test.go| index efab8f993..8a6a5f592 100644 |
| --- a/internal/console/keymail_test.go |
| +++ b/internal/console/keymail_test.go |
| @@ -473,10 +473,9 @@ func testVerify(b64pub string, msg []byte, b64sig string) bool { |
| if err != nil || len(raw) != 65 || raw[0] != 4 { |
| return false |
| } |
| - pub := &ecdsa.PublicKey{ |
| - Curve: elliptic.P256(), |
| - X: new(big.Int).SetBytes(raw[1:33]), |
| - Y: new(big.Int).SetBytes(raw[33:65]), |
| + pub, err := ecdsa.ParseUncompressedPublicKey(elliptic.P256(), raw) |
| + if err != nil { |
| + return false |
| } |
| sig, err := base64.StdEncoding.DecodeString(b64sig) |
| if err != nil || len(sig) != 64 { |
diff --git a/internal/console/opshots_test.go b/internal/console/opshots_test.go| index 415fa2636..04d85306d 100644 |
| --- a/internal/console/opshots_test.go |
| +++ b/internal/console/opshots_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "bytes" |
| "context" |
| "io" |
| + "net" |
| "net/http" |
| "net/http/httptest" |
| "net/http/httputil" |
| @@ -11,6 +12,7 @@ import ( |
| "os" |
| "os/exec" |
| "path/filepath" |
| + "slices" |
| "strconv" |
| "strings" |
| "testing" |
| @@ -40,6 +42,122 @@ var opShotPages = []struct{ name, path string }{ |
| {"backups", "/fleet/backups"}, |
| } |
| +// opShotsProxy fronts the console for the screenshot browser: every request |
| +// carries the signed-in cookies in place of the browser's own, and asks for |
| +// an uncompressed body so a dark shot can edit the page. |
| +func opShotsProxy(target *url.URL, cookies []*http.Cookie) *httputil.ReverseProxy { |
| + return &httputil.ReverseProxy{Rewrite: func(pr *httputil.ProxyRequest) { |
| + pr.SetURL(target) |
| + pr.Out.Host = pr.In.Host // SetURL would send the target's |
| + // Rewrite starts with the forwarding headers removed: carry the |
| + // client's through, and add its address to X-Forwarded-For. |
| + for _, name := range []string{"Forwarded", "X-Forwarded-Host", "X-Forwarded-Proto"} { |
| + if v, ok := pr.In.Header[name]; ok { |
| + pr.Out.Header[name] = v |
| + } |
| + } |
| + if ip, _, err := net.SplitHostPort(pr.In.RemoteAddr); err == nil { |
| + if prior := pr.In.Header["X-Forwarded-For"]; len(prior) > 0 { |
| + ip = strings.Join(prior, ", ") + ", " + ip |
| + } |
| + pr.Out.Header.Set("X-Forwarded-For", ip) |
| + } |
| + pr.Out.Header.Del("Accept-Encoding") |
| + pr.Out.Header.Del("Cookie") |
| + for _, c := range cookies { |
| + pr.Out.AddCookie(c) |
| + } |
| + }} |
| +} |
| + |
| +// TestOpShotsProxyRequestHeaders pins what the console receives through |
| +// opShotsProxy: the browser's Host, the signed-in cookie alone, and the |
| +// forwarding headers kept with the client's address appended. |
| +func TestOpShotsProxyRequestHeaders(t *testing.T) { |
| + type seen struct { |
| + host, uri string |
| + header http.Header |
| + } |
| + got := make(chan seen, 1) |
| + upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + got <- seen{r.Host, r.RequestURI, r.Header.Clone()} |
| + })) |
| + defer upstream.Close() |
| + target, err := url.Parse(upstream.URL + "/base") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + front := httptest.NewServer(opShotsProxy(target, []*http.Cookie{{Name: "sid", Value: "signed-in"}})) |
| + defer front.Close() |
| + |
| + for _, tc := range []struct { |
| + name string |
| + in http.Header |
| + want http.Header |
| + }{ |
| + { |
| + name: "first proxy", |
| + in: http.Header{}, |
| + want: http.Header{"X-Forwarded-For": {"127.0.0.1"}}, |
| + }, |
| + { |
| + name: "behind another proxy", |
| + in: http.Header{ |
| + "X-Forwarded-For": {"203.0.113.9", "198.51.100.7"}, |
| + "X-Forwarded-Host": {"shop.example.com"}, |
| + "X-Forwarded-Proto": {"https"}, |
| + "Forwarded": {"for=203.0.113.9"}, |
| + }, |
| + want: http.Header{ |
| + "X-Forwarded-For": {"203.0.113.9, 198.51.100.7, 127.0.0.1"}, |
| + "X-Forwarded-Host": {"shop.example.com"}, |
| + "X-Forwarded-Proto": {"https"}, |
| + "Forwarded": {"for=203.0.113.9"}, |
| + }, |
| + }, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + req, err := http.NewRequest(http.MethodGet, front.URL+"/fleet?page=2", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Host = "console.example.com" |
| + req.Header = tc.in.Clone() |
| + req.Header.Set("User-Agent", "shots") |
| + req.Header.Set("Accept-Encoding", "br") |
| + req.Header.Set("Cookie", "browser=own") |
| + req.Header.Set("Connection", "X-Hop") |
| + req.Header.Set("X-Hop", "dropped") |
| + req.Header.Set("X-Kept", "kept") |
| + resp, err := http.DefaultTransport.RoundTrip(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + resp.Body.Close() |
| + r := <-got |
| + if r.host != "console.example.com" || r.uri != "/base/fleet?page=2" { |
| + t.Errorf("host %q uri %q", r.host, r.uri) |
| + } |
| + for name, want := range map[string]string{ |
| + "Cookie": "sid=signed-in", |
| + "Accept-Encoding": "gzip", // the proxy's transport asks for its own |
| + "User-Agent": "shots", |
| + "X-Kept": "kept", |
| + "X-Hop": "", |
| + } { |
| + if v := r.header.Get(name); v != want { |
| + t.Errorf("%s = %q, want %q", name, v, want) |
| + } |
| + } |
| + for _, name := range []string{"X-Forwarded-For", "X-Forwarded-Host", "X-Forwarded-Proto", "Forwarded"} { |
| + if !slices.Equal(r.header[name], tc.want[name]) { |
| + t.Errorf("%s = %q, want %q", name, r.header[name], tc.want[name]) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| // seedOperatorShotExtras gives the moved pages something to show: an |
| // hour of one box's metrics with a unit, the economics fixture |
| // (seedEconomicsGolden) and a bill on file for this month. |
| @@ -118,16 +236,7 @@ func TestOperatorScreenshots(t *testing.T) { |
| t.Fatal("the signed-in browser holds no cookie") |
| } |
| front := func(dark bool) *httptest.Server { |
| - proxy := httputil.NewSingleHostReverseProxy(target) |
| - director := proxy.Director |
| - proxy.Director = func(r *http.Request) { |
| - director(r) |
| - r.Header.Del("Accept-Encoding") |
| - r.Header.Del("Cookie") |
| - for _, c := range cookies { |
| - r.AddCookie(c) |
| - } |
| - } |
| + proxy := opShotsProxy(target, cookies) |
| if dark { |
| proxy.ModifyResponse = func(resp *http.Response) error { |
| if !strings.HasPrefix(resp.Header.Get("Content-Type"), "text/html") { |
diff --git a/internal/console/store_gate.go b/internal/console/store_gate.go| index dfcfbfa82..f9032badb 100644 |
| --- a/internal/console/store_gate.go |
| +++ b/internal/console/store_gate.go |
| @@ -1542,7 +1542,8 @@ func (s *claimStmt) ExecContext(ctx context.Context, args []driver.NamedValue) ( |
| if err != nil { |
| return nil, err |
| } |
| - return s.inner.Exec(vals) //nolint:staticcheck // legacy driver path |
| + //lint:ignore SA1019 the only way to run a statement on a driver without StmtExecContext, as database/sql does |
| + return s.inner.Exec(vals) |
| } |
| func (s *claimStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { |
| @@ -1567,7 +1568,8 @@ func (s *claimStmt) QueryContext(ctx context.Context, args []driver.NamedValue) |
| if verr != nil { |
| return nil, verr |
| } |
| - rows, err = s.inner.Query(vals) //nolint:staticcheck // legacy driver path |
| + //lint:ignore SA1019 the only way to run a statement on a driver without StmtQueryContext, as database/sql does |
| + rows, err = s.inner.Query(vals) |
| } |
| if err != nil { |
| return nil, err |
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go| index 3493b034f..7fd82b1bd 100644 |
| --- a/internal/console/svcroutes_test.go |
| +++ b/internal/console/svcroutes_test.go |
| @@ -946,24 +946,26 @@ func scanCLISource(t *testing.T) *cliSource { |
| func parseConsoleSource(t *testing.T) (*token.FileSet, []*ast.File) { |
| t.Helper() |
| fset := token.NewFileSet() |
| - pkgs, err := parser.ParseDir(fset, ".", func(fi os.FileInfo) bool { |
| - return !strings.HasSuffix(fi.Name(), "_test.go") |
| - }, 0) |
| + entries, err := os.ReadDir(".") |
| if err != nil { |
| t.Fatalf("parse package: %v", err) |
| } |
| - pkg, ok := pkgs["console"] |
| - if !ok { |
| - t.Fatal("package console not found by the parser") |
| - } |
| - names := make([]string, 0, len(pkg.Files)) |
| - for name := range pkg.Files { |
| - names = append(names, name) |
| + var files []*ast.File // in name order: ReadDir sorts |
| + for _, e := range entries { |
| + name := e.Name() |
| + if e.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { |
| + continue |
| + } |
| + f, err := parser.ParseFile(fset, name, nil, 0) |
| + if err != nil { |
| + t.Fatalf("parse package: %v", err) |
| + } |
| + if f.Name.Name == "console" { |
| + files = append(files, f) |
| + } |
| } |
| - sort.Strings(names) |
| - files := make([]*ast.File, 0, len(names)) |
| - for _, name := range names { |
| - files = append(files, pkg.Files[name]) |
| + if len(files) == 0 { |
| + t.Fatal("package console not found by the parser") |
| } |
| return fset, files |
| } |
diff --git a/internal/demobuild/source.go b/internal/demobuild/source.go| index bcbfc5927..6dcf9f363 100644 |
| --- a/internal/demobuild/source.go |
| +++ b/internal/demobuild/source.go |
| @@ -237,6 +237,10 @@ func forbiddenFile(name string, isDir bool) bool { |
| return false |
| } |
| +// tarTypeRegNUL is the typeflag old tar writers use for a regular file. |
| +// plainTar reads raw records, before archive/tar turns it into TypeReg. |
| +const tarTypeRegNUL = '\x00' |
| + |
| func plainTar(b []byte) bool { |
| for len(b) >= 512 { |
| h := b[:512] |
| @@ -252,7 +256,7 @@ func plainTar(b []byte) bool { |
| } |
| return true |
| } |
| - if h[156] != tar.TypeReg && h[156] != tar.TypeRegA && h[156] != tar.TypeDir { |
| + if h[156] != tar.TypeReg && h[156] != tarTypeRegNUL && h[156] != tar.TypeDir { |
| return false |
| } |
| // NUL is a terminator in USTAR, never a way to smuggle another name. |
diff --git a/internal/demobuild/source_test.go b/internal/demobuild/source_test.go| index 40c072664..f0045386f 100644 |
| --- a/internal/demobuild/source_test.go |
| +++ b/internal/demobuild/source_test.go |
| @@ -194,6 +194,18 @@ func TestDemoSourceLimits(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// TestDemoSourceAcceptsNULTypeflag: old tar writers mark a regular file with |
| +// a NUL typeflag, and the physical record check has to let it through. |
| +func TestDemoSourceAcceptsNULTypeflag(t *testing.T) { |
| + es := starter(t) |
| + offset := len(tarBytes(t, es)) - 1024 |
| + b := tarBytes(t, append(es, archiveEntry{"extra.go", "package main\n", tar.TypeReg})) |
| + b[offset+156] = 0 |
| + fixHeaderChecksum(b[offset:]) |
| + validate(t, gzipBytes(t, b), true) |
| +} |
| + |
| func TestDemoSourceCannotEscapeLock(t *testing.T) { |
| for _, tc := range []struct { |
| kind byte |
diff --git a/internal/edge/certsync_e2e_test.go b/internal/edge/certsync_e2e_test.go| index 03de19a88..3dedbe096 100644 |
| --- a/internal/edge/certsync_e2e_test.go |
| +++ b/internal/edge/certsync_e2e_test.go |
| @@ -388,11 +388,11 @@ func jwkThumbprintFromJSON(raw json.RawMessage) (string, error) { |
| if err != nil { |
| return "", fmt.Errorf("jwk y: %w", err) |
| } |
| - return acme.JWKThumbprint(&ecdsa.PublicKey{ |
| - Curve: elliptic.P256(), |
| - X: new(big.Int).SetBytes(x), |
| - Y: new(big.Int).SetBytes(y), |
| - }) |
| + pub, err := ecdsa.ParseUncompressedPublicKey(elliptic.P256(), append(append([]byte{4}, x...), y...)) |
| + if err != nil { |
| + return "", fmt.Errorf("jwk point: %w", err) |
| + } |
| + return acme.JWKThumbprint(pub) |
| } |
| // ---- two edges ----------------------------------------------------------- |
diff --git a/internal/edge/demo_countdown_test.go b/internal/edge/demo_countdown_test.go| index 5c050607c..e21db2073 100644 |
| --- a/internal/edge/demo_countdown_test.go |
| +++ b/internal/edge/demo_countdown_test.go |
| @@ -51,7 +51,7 @@ func TestDemoBannerCountdownBrowser(t *testing.T) { |
| for _, remaining := range []int64{7230, 270} { |
| expiry := time.Now().Unix() + remaining |
| e := &Edge{demoReportOrigin: "https://console.example.com"} |
| - proxy := e.demoProxy(&httputil.ReverseProxy{Director: func(r *http.Request) {}, Transport: demoBannerRoundTrip(func(r *http.Request) (*http.Response, error) { |
| + proxy := e.demoProxy(&httputil.ReverseProxy{Rewrite: func(*httputil.ProxyRequest) {}, Transport: demoBannerRoundTrip(func(r *http.Request) (*http.Response, error) { |
| return &http.Response{StatusCode: 200, Header: http.Header{"Content-Type": {"text/html"}}, Body: io.NopCloser(strings.NewReader(`<!doctype html><html><head><meta name="viewport" content="width=device-width,initial-scale=1"><title>Demo</title></head><body><main>Demo app</main></body></html>`))}, nil |
| })}, registry.Route{Host: "shop.example.com", DemoExpiresAt: expiry}) |
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
diff --git a/internal/edge/demo_forward_test.go b/internal/edge/demo_forward_test.go| index cb4a7417a..edf934c88 100644 |
| --- a/internal/edge/demo_forward_test.go |
| +++ b/internal/edge/demo_forward_test.go |
| @@ -156,7 +156,7 @@ func TestDemoTrafficForwardFailure(t *testing.T) { |
| rt.FleetLabel = "box" |
| rt.Socket = "" |
| rt.Hibernate = false |
| - p := &httputil.ReverseProxy{Director: func(r *http.Request) { r.URL.Scheme = "http"; r.URL.Host = "example.com" }, Transport: roundTripperFunc(func(*http.Request) (*http.Response, error) { return nil, context.DeadlineExceeded })} |
| + p := &httputil.ReverseProxy{Rewrite: func(pr *httputil.ProxyRequest) { pr.Out.URL.Scheme = "http"; pr.Out.URL.Host = "example.com" }, Transport: roundTripperFunc(func(*http.Request) (*http.Response, error) { return nil, context.DeadlineExceeded })} |
| demoSetProxy(e, rt, p) |
| rec := httptest.NewRecorder() |
| e.ServeHTTP(rec, httptest.NewRequest("GET", "https://"+rt.Host+"/", nil)) |
diff --git a/internal/edge/replica_reach_test.go b/internal/edge/replica_reach_test.go| index 7bb01688b..18f4dab7f 100644 |
| --- a/internal/edge/replica_reach_test.go |
| +++ b/internal/edge/replica_reach_test.go |
| @@ -122,6 +122,7 @@ func replicaFramerBox(t *testing.T, hub *TunnelHub, p *replicaProber, host, box, |
| } |
| }() |
| wire := &tunnelWire{Conn: a, closed: make(chan struct{})} |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(wire) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/edge/replicaproxy_test.go b/internal/edge/replicaproxy_test.go| index aff35006d..93f42ae18 100644 |
| --- a/internal/edge/replicaproxy_test.go |
| +++ b/internal/edge/replicaproxy_test.go |
| @@ -35,6 +35,7 @@ func replicaProxyFixture(t *testing.T, handlers ...http.HandlerFunc) (*TunnelHub |
| tunnelclient.ServeWith(b, tunnelclient.Mark(handler), tunnelclient.DefaultLimits) |
| }() |
| wire := &tunnelWire{Conn: a, closed: make(chan struct{})} |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(wire) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/edge/tunnel.go b/internal/edge/tunnel.go| index fb8f97050..f5df7668c 100644 |
| --- a/internal/edge/tunnel.go |
| +++ b/internal/edge/tunnel.go |
| @@ -98,8 +98,9 @@ type tunnelConn struct { |
| generation uint64 |
| probeBoot string // first valid platform answer on this connection; guarded by hub.mu |
| closed <-chan struct{} |
| - cc *http2.ClientConn |
| - raw net.Conn |
| + //lint:ignore SA1019 net/http's ClientConn has no Ping or Closing state, which pingLoop and tunnelConnLost need |
| + cc *http2.ClientConn |
| + raw net.Conn |
| // dynamic records that this conn authenticated against the registry-backed |
| // (fleet) credential source rather than the static env map — the one fact |
| // ServeHTTP knows and pingLoop needs for pingCadence. |
| @@ -281,7 +282,9 @@ func (h *TunnelHub) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| } |
| wire := &tunnelWire{Conn: conn, closed: make(chan struct{})} |
| conn = wire |
| + //lint:ignore SA1019 net/http's Transport.NewClientConn dials an address and cannot adopt this hijacked conn |
| tr := &http2.Transport{} |
| + //lint:ignore SA1019 net/http's Transport.NewClientConn dials an address and cannot adopt this hijacked conn |
| cc, err := tr.NewClientConn(conn) |
| if err != nil { |
| log.Printf("edge: tunnel %s: h2 client conn: %v", name, err) |
| @@ -392,6 +395,8 @@ func (h *TunnelHub) recordLinkSeen(name, linkID string, tc *tunnelConn, connecte |
| // dynamic carries the credential source through from ServeHTTP: fleet |
| // channels reap on a tighter bound because that bound is their failover |
| // window (see pingCadence). |
| +// |
| +//lint:ignore SA1019 net/http's ClientConn has no Ping |
| func (h *TunnelHub) pingLoop(name string, cc *http2.ClientConn, raw net.Conn, dynamic bool) { |
| every, timeout := pingCadence(dynamic) |
| for { |
| @@ -940,6 +945,7 @@ func (h *TunnelHub) replicaRoundTrip(channel string, req *http.Request) (*http.R |
| switch { |
| case err == nil || resp != nil: |
| return resp, reachMaybe, err |
| + //lint:ignore SA1019 x/net's ClientConn still honours Request.Cancel, so a caller's Cancel can end the attempt with the context live |
| case !wrote.Load() && req.Context().Err() == nil && req.Cancel == nil: |
| return nil, reachNotWritten, err |
| case refusedByBox(err): |
diff --git a/internal/edge/upgrades_test.go b/internal/edge/upgrades_test.go| index cbf405454..9e9214b62 100644 |
| --- a/internal/edge/upgrades_test.go |
| +++ b/internal/edge/upgrades_test.go |
| @@ -290,11 +290,14 @@ func (c *stuckConn) Read(p []byte) (int, error) { |
| // stuckPair serves handler (through Mark, as Loop does) on a tunnel whose |
| // box end can be made to stop reading. |
| +// |
| +//lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| func stuckPair(t *testing.T, handler http.Handler) (*http2.ClientConn, *stuckConn) { |
| t.Helper() |
| boxEnd, hubEnd := net.Pipe() |
| sc := &stuckConn{Conn: boxEnd, stuck: make(chan struct{}), absorbed: make(chan struct{}), unstick: make(chan struct{})} |
| go tunnelclient.ServeWith(sc, tunnelclient.Mark(handler), tunnelclient.DefaultLimits) |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(hubEnd) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/groupadmission/state_test.go b/internal/groupadmission/state_test.go| index 11a63cbd1..d089ed999 100644 |
| --- a/internal/groupadmission/state_test.go |
| +++ b/internal/groupadmission/state_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "errors" |
| "go/parser" |
| "go/token" |
| + "os" |
| "strconv" |
| "strings" |
| "sync" |
| @@ -124,17 +125,22 @@ func TestAdmissionCloseWins(t *testing.T) { |
| } |
| } |
| func TestAdmissionCoreImports(t *testing.T) { |
| - pkgs, err := parser.ParseDir(token.NewFileSet(), ".", nil, parser.ImportsOnly) |
| + entries, err := os.ReadDir(".") |
| if err != nil { |
| t.Fatal(err) |
| } |
| - for _, p := range pkgs { |
| - for _, f := range p.Files { |
| - for _, imp := range f.Imports { |
| - v, _ := strconv.Unquote(imp.Path.Value) |
| - if strings.Contains(v, "aws") { |
| - t.Fatal(v) |
| - } |
| + for _, e := range entries { |
| + if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") { |
| + continue |
| + } |
| + f, err := parser.ParseFile(token.NewFileSet(), e.Name(), nil, parser.ImportsOnly) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, imp := range f.Imports { |
| + v, _ := strconv.Unquote(imp.Path.Value) |
| + if strings.Contains(v, "aws") { |
| + t.Fatal(v) |
| } |
| } |
| } |
diff --git a/internal/host/pagearm_test.go b/internal/host/pagearm_test.go| index 81d218b6f..ae37605f6 100644 |
| --- a/internal/host/pagearm_test.go |
| +++ b/internal/host/pagearm_test.go |
| @@ -137,6 +137,7 @@ func TestRunAgentWiresCurrentInputs(t *testing.T) { |
| } |
| // declaredBy reports whether id was declared by an assignment whose one |
| // right-hand side satisfies rhs. |
| + //lint:ignore SA1019 this witness parses agent.go alone; go/types would have to load internal/host's whole import graph |
| declaredBy := func(e ast.Expr, rhs func(ast.Expr) bool) (*ast.Object, bool) { |
| id, ok := e.(*ast.Ident) |
| if !ok || id.Obj == nil { |
| @@ -169,6 +170,7 @@ func TestRunAgentWiresCurrentInputs(t *testing.T) { |
| return ok && selector(cl.Type, "activator", "ExecBackend") |
| } |
| var wires []*ast.CallExpr |
| + //lint:ignore SA1019 this witness parses agent.go alone; go/types would have to load internal/host's whole import graph |
| var served *ast.Object |
| var wiredAt, servedAt token.Pos |
| ast.Inspect(run, func(n ast.Node) bool { |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 6323e4e43..f34c52319 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -249,3 +249,4 @@ plan14-root-reads-staticcheck-sa4006.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc82 |
| plan14-root-reads-aws-followups-1143.tsv 33e5eaaa9b2d80f6f8f5de8d04e908e39ecfc820c5fe7b44c870e671565e1063 |
| plan14-root-reads-fix-dbforward-reuse-1032.tsv ec3c40098ec0a652c735d54925f334b9b9680c9e2b6cd0c3d9497b8a615fb86f |
| plan14-root-reads-staticcheck-sa1012.tsv 5fcd060180e923773dad3faee7cc60ee250779a242b1dc14f4576f413dc8a774 |
| +plan14-root-reads-staticcheck-sa1019.tsv f9be26c06eb1c844b91a75f65faa51997048cb2900f3ed078be2ae28c65c0e98 |
diff --git a/internal/provision/testdata/plan14-root-reads-staticcheck-sa1019.tsv b/internal/provision/testdata/plan14-root-reads-staticcheck-sa1019.tsv| new file mode 100644 |
| index 000000000..3b23d155d |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-staticcheck-sa1019.tsv |
| @@ -0,0 +1,8 @@ |
| +# Census overlay staticcheck-sa1019, written by census-propose (#369). census-ruling-staticcheck-sa1019, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-staticcheck-sa1019.md. |
| +# 1 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy b3f7c622d723e37514f15d82d6b5155ebb1e5b4c511850c7ce454dbd02e91ded staticcheck.conf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-audit-gate-vet-staticcheck;basis=new: staticcheck configuration at the module root (which SA checks run). Read only by the staticcheck tool in CI and make staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa4006;basis=Turns SA4006 on (drops -SA4006 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa1012;basis=SA1012 removed from the excluded checks and the comment updated; a lint setting, no code path changes;rev3=census-ruling-staticcheck-sa1019;basis=Turns SA1019 on (drops -SA1019 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added. file:external@0 026e422e3a356a604729f1c0952905581389b5855bf2d653e6839960b2194804 |
| +staticcheck.conf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-audit-gate-vet-staticcheck;basis=new: staticcheck configuration at the module root (which SA checks run). Read only by the staticcheck tool in CI and make staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa4006;basis=Turns SA4006 on (drops -SA4006 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added.;rev3=census-ruling-staticcheck-sa1012;basis=SA1012 removed from the excluded checks and the comment updated; a lint setting, no code path changes;rev3=census-ruling-staticcheck-sa1019;basis=Turns SA1019 on (drops -SA1019 from checks) and rewrites its comment. Read only by staticcheck; nothing in the root binary reads it. No read added. file:external@0 026e422e3a356a604729f1c0952905581389b5855bf2d653e6839960b2194804 |
| +@coverage . cdb32052a1d63c6f0ea37edfda391786ef21f9b9f1940276b163a832f6ec1518 |
| +@coverage internal/demobuild 8caa19e57a3df145f1cf04e9b0c912c7ad14cdb150c2b9b0886b8d823675659c |
| +@coverage internal/edge aa9393a4d8b825f15f266abc0474016f2eecfa4865a76f3a8cf334549f7007a0 |
| +@coverage internal/tunnelclient 123f6069a8eebc7f4a0ab08a68014f4f2afb283776a9e21e414ebfffad834df3 |
diff --git a/internal/tunnelclient/drain_test.go b/internal/tunnelclient/drain_test.go| index 6976c8824..015af0402 100644 |
| --- a/internal/tunnelclient/drain_test.go |
| +++ b/internal/tunnelclient/drain_test.go |
| @@ -20,6 +20,7 @@ import ( |
| // dialing again. A drain closed before Loop starts dials nothing. |
| func TestLoopDrain(t *testing.T) { |
| var registrations atomic.Int32 |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| conns := make(chan *http2.ClientConn, 4) |
| edge := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| registrations.Add(1) |
| @@ -30,6 +31,7 @@ func TestLoopDrain(t *testing.T) { |
| } |
| fmt.Fprintf(bufrw, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: carlos-tunnel/1\r\nConnection: Upgrade\r\n\r\n") |
| bufrw.Flush() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(conn) |
| if err != nil { |
| t.Errorf("h2 client: %v", err) |
| @@ -56,6 +58,7 @@ func TestLoopDrain(t *testing.T) { |
| defer close(done) |
| Loop(context.Background(), Config{URL: edge.URL, Name: "pi/box-1", Token: "t", Handler: handler, Drain: drain, Logf: t.Logf}) |
| }() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| var cc *http2.ClientConn |
| select { |
| case cc = <-conns: |
diff --git a/internal/tunnelclient/refuse_test.go b/internal/tunnelclient/refuse_test.go| index 027c2e9f0..8cf5b2ce0 100644 |
| --- a/internal/tunnelclient/refuse_test.go |
| +++ b/internal/tunnelclient/refuse_test.go |
| @@ -17,11 +17,14 @@ import ( |
| // refuseRig is a box h2 server (serveConn with a drain) and the hub's |
| // ClientConn on the other end of a pipe. |
| +// |
| +//lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| func refuseRig(t *testing.T, handler http.Handler, drain <-chan struct{}) *http2.ClientConn { |
| t.Helper() |
| a, b := net.Pipe() |
| done := make(chan struct{}) |
| go func() { defer close(done); serveConn(b, handler, DefaultLimits, drain) }() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(a) |
| if err != nil { |
| t.Fatal(err) |
| @@ -30,6 +33,7 @@ func refuseRig(t *testing.T, handler http.Handler, drain <-chan struct{}) *http2 |
| return cc |
| } |
| +//lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| func refuseDo(t *testing.T, cc *http2.ClientConn, method, body string) (*http.Response, error) { |
| t.Helper() |
| var rd io.Reader |
| @@ -131,8 +135,10 @@ func TestStreamGateRefusesOnceDraining(t *testing.T) { |
| done := make(chan struct{}) |
| go func() { |
| defer close(done) |
| + //lint:ignore SA1019 serves the tunnel with the x/net server serveConn uses in production |
| (&http2.Server{}).ServeConn(rc, &http2.ServeConnOpts{Handler: streamGate{h: http.HandlerFunc(func(http.ResponseWriter, *http.Request) { calls.Add(1) }), drain: drain, conn: rc}}) |
| }() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(a) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/tunnelclient/tlsstate_test.go b/internal/tunnelclient/tlsstate_test.go| index 0f4963f30..c7f3d94d3 100644 |
| --- a/internal/tunnelclient/tlsstate_test.go |
| +++ b/internal/tunnelclient/tlsstate_test.go |
| @@ -57,6 +57,7 @@ func TestFleetTunnelKeepsHTTPS(t *testing.T) { |
| edge.ServeHTTP(w, r) |
| }) |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| conns := make(chan *http2.ClientConn, 1) |
| hub := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| conn, bufrw, err := w.(http.Hijacker).Hijack() |
| @@ -66,6 +67,7 @@ func TestFleetTunnelKeepsHTTPS(t *testing.T) { |
| } |
| fmt.Fprintf(bufrw, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: carlos-tunnel/1\r\nConnection: Upgrade\r\n\r\n") |
| bufrw.Flush() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(conn) |
| if err != nil { |
| t.Errorf("h2 client: %v", err) |
| @@ -90,6 +92,7 @@ func TestFleetTunnelKeepsHTTPS(t *testing.T) { |
| Loop(ctx, Config{URL: hub.URL, Name: "pi/box-1", Token: "t", Handler: handler, Drain: drain, Logf: t.Logf}) |
| }() |
| defer func() { cancel(); <-done }() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| var cc *http2.ClientConn |
| select { |
| case cc = <-conns: |
diff --git a/internal/tunnelclient/tunnelclient_test.go b/internal/tunnelclient/tunnelclient_test.go| index 64e448cb5..d8488eab1 100644 |
| --- a/internal/tunnelclient/tunnelclient_test.go |
| +++ b/internal/tunnelclient/tunnelclient_test.go |
| @@ -30,6 +30,7 @@ func fakeTunnelEdge(t *testing.T, wantToken, wantName string) (*httptest.Server, |
| } |
| fmt.Fprintf(bufrw, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: carlos-tunnel/1\r\nConnection: Upgrade\r\n\r\n") |
| bufrw.Flush() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(conn) |
| if err != nil { |
| t.Errorf("h2 client: %v", err) |
diff --git a/internal/tunnelclient/upgrade.go b/internal/tunnelclient/upgrade.go| index d5630e8ed..774e132bf 100644 |
| --- a/internal/tunnelclient/upgrade.go |
| +++ b/internal/tunnelclient/upgrade.go |
| @@ -114,12 +114,17 @@ func ServeWith(conn net.Conn, handler http.Handler, l Limits) { |
| // connection only once they are done (goAwayTimeout after the last), or |
| // the process exits under them, as before. |
| func serveConn(conn net.Conn, handler http.Handler, l Limits, drain <-chan struct{}) { |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| srv := &http2.Server{ |
| - MaxConcurrentStreams: l.MaxStreams, |
| - MaxUploadBufferPerStream: l.StreamWindow, |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| + MaxConcurrentStreams: l.MaxStreams, |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| + MaxUploadBufferPerStream: l.StreamWindow, |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| MaxUploadBufferPerConnection: l.ConnWindow, |
| } |
| if drain == nil { |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| srv.ServeConn(conn, &http2.ServeConnOpts{Handler: handler}) |
| return |
| } |
| @@ -130,6 +135,7 @@ func serveConn(conn net.Conn, handler http.Handler, l Limits, drain <-chan struc |
| registered := make(chan struct{}) |
| var once sync.Once |
| base := &http.Server{ConnState: func(net.Conn, http.ConnState) { once.Do(func() { close(registered) }) }} |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| if err := http2.ConfigureServer(base, srv); err != nil { |
| conn.Close() |
| return |
| @@ -152,6 +158,7 @@ func serveConn(conn net.Conn, handler http.Handler, l Limits, drain <-chan struc |
| _ = base.Shutdown(context.Background()) |
| }() |
| rc := newRefusingConn(conn) |
| + //lint:ignore SA1019 moving to http.Server.Serve changes how drain's GOAWAY and stream refusal reach this conn |
| srv.ServeConn(servedConn(rc), &http2.ServeConnOpts{Handler: streamGate{h: handler, drain: drain, conn: rc}, BaseConfig: base}) |
| } |
| @@ -477,6 +484,8 @@ var hookHandshake func() |
| // or after the 101. x/net alone does not watch the context while it waits |
| // on an open request body, so the context's end fails the pipe, which |
| // x/net answers with RST_STREAM. |
| +// |
| +//lint:ignore SA1019 the hub's tunnel connection is x/net's ClientConn (internal/edge/tunnel.go) |
| func RoundTripUpgrade(ctx context.Context, cc *http2.ClientConn, req *http.Request) (*http.Response, error) { |
| tok := req.Header.Get("Upgrade") |
| if !ValidUpgradeToken(tok) { |
diff --git a/internal/tunnelclient/upgrade_box_test.go b/internal/tunnelclient/upgrade_box_test.go| index f276f909d..5f1937dbe 100644 |
| --- a/internal/tunnelclient/upgrade_box_test.go |
| +++ b/internal/tunnelclient/upgrade_box_test.go |
| @@ -20,6 +20,8 @@ import ( |
| // h2Pair serves handler with ServeWith on one end of an in-memory pipe and |
| // returns an HTTP/2 client conn on the other: the box half of the tunnel |
| // with nothing between the test and Mark but x/net. |
| +// |
| +//lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| func h2Pair(t *testing.T, handler http.Handler) *http2.ClientConn { |
| t.Helper() |
| box, hub := net.Pipe() |
| @@ -28,6 +30,7 @@ func h2Pair(t *testing.T, handler http.Handler) *http2.ClientConn { |
| defer close(done) |
| ServeWith(box, handler, DefaultLimits) |
| }() |
| + //lint:ignore SA1019 drives the x/net ClientConn the hub uses in production (internal/edge/tunnel.go) |
| cc, err := (&http2.Transport{}).NewClientConn(hub) |
| if err != nil { |
| t.Fatalf("h2 client: %v", err) |
diff --git a/move_offline_run_test.go b/move_offline_run_test.go| index 93a5505ea..ce557b0b9 100644 |
| --- a/move_offline_run_test.go |
| +++ b/move_offline_run_test.go |
| @@ -1335,10 +1335,22 @@ func TestMoveOfflineRunGateBoundaries(t *testing.T) { |
| // added on this side fails here. |
| func TestRunDoorsWireIsSingleShot(t *testing.T) { |
| fset := token.NewFileSet() |
| - pkgs, err := parser.ParseDir(fset, ".", func(fi os.FileInfo) bool { return !strings.HasSuffix(fi.Name(), "_test.go") }, 0) |
| + entries, err := os.ReadDir(".") |
| if err != nil { |
| t.Fatal(err) |
| } |
| + files := map[string]*ast.File{} |
| + for _, e := range entries { |
| + name := e.Name() |
| + if e.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { |
| + continue |
| + } |
| + f, err := parser.ParseFile(fset, name, nil, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + files[name] = f |
| + } |
| recv := func(fn *ast.FuncDecl) string { |
| if fn.Recv == nil || len(fn.Recv.List) == 0 { |
| return "" |
| @@ -1360,66 +1372,64 @@ func TestRunDoorsWireIsSingleShot(t *testing.T) { |
| return false |
| } |
| roundTrips, httpDos := map[string]int{}, 0 |
| - for _, pkg := range pkgs { |
| - for name, f := range pkg.Files { |
| - run := name == "move_offline_run.go" |
| - for _, decl := range f.Decls { |
| - fn, ok := decl.(*ast.FuncDecl) |
| - if !ok || fn.Body == nil { |
| - continue |
| + for name, f := range files { |
| + run := name == "move_offline_run.go" |
| + for _, decl := range f.Decls { |
| + fn, ok := decl.(*ast.FuncDecl) |
| + if !ok || fn.Body == nil { |
| + continue |
| + } |
| + where := recv(fn) + "." + fn.Name.Name |
| + ast.Inspect(fn.Body, func(n ast.Node) bool { |
| + if n == nil { |
| + return true |
| } |
| - where := recv(fn) + "." + fn.Name.Name |
| - ast.Inspect(fn.Body, func(n ast.Node) bool { |
| - if n == nil { |
| + if loop(n) && ((run && where != ".ctrlC") || where == "mover.roundTrip") { |
| + t.Errorf("%s: %s has a loop", name, where) |
| + } |
| + switch n := n.(type) { |
| + case *ast.SelectStmt: |
| + if run && where != ".ctrlC" { |
| + t.Errorf("%s: %s selects: the run waits only in the Runner's loop", name, where) |
| + } |
| + case *ast.SelectorExpr: |
| + if id, ok := n.X.(*ast.Ident); run && ok && id.Name == "http" && strings.HasPrefix(n.Sel.Name, "Method") && |
| + (n.Sel.Name != "MethodGet" || (where != "runWire.Do" && where != ".probeOnce")) { |
| + t.Errorf("%s: %s names http.%s: the doors choose what is sent", name, where, n.Sel.Name) |
| + } |
| + case *ast.CallExpr: |
| + sel, ok := n.Fun.(*ast.SelectorExpr) |
| + if !ok { |
| return true |
| } |
| - if loop(n) && ((run && where != ".ctrlC") || where == "mover.roundTrip") { |
| - t.Errorf("%s: %s has a loop", name, where) |
| + if where == "mover.roundTrip" && sel.Sel.Name == "Do" { |
| + httpDos++ |
| } |
| - switch n := n.(type) { |
| - case *ast.SelectStmt: |
| - if run && where != ".ctrlC" { |
| - t.Errorf("%s: %s selects: the run waits only in the Runner's loop", name, where) |
| - } |
| - case *ast.SelectorExpr: |
| - if id, ok := n.X.(*ast.Ident); run && ok && id.Name == "http" && strings.HasPrefix(n.Sel.Name, "Method") && |
| - (n.Sel.Name != "MethodGet" || (where != "runWire.Do" && where != ".probeOnce")) { |
| - t.Errorf("%s: %s names http.%s: the doors choose what is sent", name, where, n.Sel.Name) |
| - } |
| - case *ast.CallExpr: |
| - sel, ok := n.Fun.(*ast.SelectorExpr) |
| - if !ok { |
| - return true |
| - } |
| - if where == "mover.roundTrip" && sel.Sel.Name == "Do" { |
| - httpDos++ |
| - } |
| - if !run { |
| - return true |
| - } |
| - switch sel.Sel.Name { |
| - case "roundTrip": |
| - roundTrips[where]++ |
| - case "Post", "Nudge", "Status", "Do": |
| - if where == ".probeOnce" && sel.Sel.Name == "Do" { |
| - break // the probe's one GET of the instance, not a door |
| - } |
| - t.Errorf("%s: %s calls .%s: only the Runner's gate and the doors may", name, where, sel.Sel.Name) |
| - case "sleep", "interval", "get", "getReply", "send", "mutate", "poll", "post", "follow", "readFlat", "readDetail": |
| - t.Errorf("%s: %s calls the mover's .%s, which waits or sends again", name, where, sel.Sel.Name) |
| - case "Sleep", "After", "NewTimer", "NewTicker", "Tick", "AfterFunc": |
| - if id, ok := sel.X.(*ast.Ident); ok && id.Name == "time" { |
| - t.Errorf("%s: %s calls time.%s", name, where, sel.Sel.Name) |
| - } |
| + if !run { |
| + return true |
| + } |
| + switch sel.Sel.Name { |
| + case "roundTrip": |
| + roundTrips[where]++ |
| + case "Post", "Nudge", "Status", "Do": |
| + if where == ".probeOnce" && sel.Sel.Name == "Do" { |
| + break // the probe's one GET of the instance, not a door |
| } |
| - case *ast.Ident: |
| - if n.Name == "runWire" && !run { |
| - t.Errorf("%s reaches runWire", name) |
| + t.Errorf("%s: %s calls .%s: only the Runner's gate and the doors may", name, where, sel.Sel.Name) |
| + case "sleep", "interval", "get", "getReply", "send", "mutate", "poll", "post", "follow", "readFlat", "readDetail": |
| + t.Errorf("%s: %s calls the mover's .%s, which waits or sends again", name, where, sel.Sel.Name) |
| + case "Sleep", "After", "NewTimer", "NewTicker", "Tick", "AfterFunc": |
| + if id, ok := sel.X.(*ast.Ident); ok && id.Name == "time" { |
| + t.Errorf("%s: %s calls time.%s", name, where, sel.Sel.Name) |
| } |
| } |
| - return true |
| - }) |
| - } |
| + case *ast.Ident: |
| + if n.Name == "runWire" && !run { |
| + t.Errorf("%s reaches runWire", name) |
| + } |
| + } |
| + return true |
| + }) |
| } |
| } |
| if len(roundTrips) != 1 || roundTrips["runWire.Do"] != 1 { |
diff --git a/staticcheck.conf b/staticcheck.conf| index 2ef49a409..90842daad 100644 |
| --- a/staticcheck.conf |
| +++ b/staticcheck.conf |
| @@ -7,16 +7,14 @@ |
| # them: ST1005 118, U1000 68, ST1013 35, S1038 26. Turning one on is its |
| # own branch, with the tree cleaned first, so the gate stays green. |
| # |
| -# One SA check is off too, a family too large to fix safely in the |
| -# branch that added this file. The count is from that branch's run on |
| -# 15b1ee6b, with -tags rootrunner,carlos_cutover_witness. A follow-up |
| -# owns it: fix the sites, then delete the line here. |
| +# Every SA check is on. Three families were off when this file was added, |
| +# each too large to fix safely in that branch. |
| # |
| -# SA1019 70 sites (20 outside tests): deprecated APIs, mostly |
| -# golang.org/x/net/http2's ClientConn, Transport and Server |
| -# (moved into net/http), then go/parser.ParseDir, |
| -# httputil.ReverseProxy's Director and ecdsa's raw key |
| -# coordinates. Each needs a real migration, not a rename. |
| +# SA1019 (use of a deprecated API) was off here, with 70 sites. Branch |
| +# staticcheck-sa1019 migrated what could move without changing behaviour |
| +# and turned it on. The sites left carry a lint:ignore naming what blocks |
| +# them, most of them because net/http has no replacement yet for what the |
| +# tunnel uses in golang.org/x/net/http2. |
| # |
| # SA1012 (a nil context.Context passed to a function) was off here too, |
| # with 177 sites, 153 of them in internal/registry. Branch |
| @@ -33,4 +31,4 @@ |
| # Deliberate cases of an enabled check carry a `//lint:ignore <check> |
| # <reason>` on the line above them (the empty critical sections that are |
| # barriers, for instance). staticcheck ignores `//nolint` comments. |
| -checks = ["SA*", "-SA1019"] |
| +checks = ["SA*"] |