hostedimage: path rules, V7 tar and the RPM budget in the payload scan
Task 10 review round 3. The payload detector sees each member's path again, so path-scoped rules run, while every path condition is taken out of its global and per-rule allowlists. A tar is known by its header checksum, V7 included, and an input named as an archive must read as one. Each RPM payload file is charged against the expansion budget before it is read, the walk stops at the first over a limit, and the decompressed stream is bounded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+285
−32
Makefile+1 −1docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+40 −0internal/hostedimage/hostedimagetest/hostedimagetest.go+38 −0internal/hostedimage/nested.go+60 −8internal/hostedimage/rpm.go+19 −14internal/hostedimage/scan.go+51 −9internal/hostedimage/scan_test.go+76 −0
diff --git a/Makefile b/Makefile| index 25a69925..c74ab6de 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -228,7 +228,7 @@ gitleaks: |
| # AWS call. .amadan/ci.d/15-hosted-image runs it on CI. |
| hosted-image-check: |
| go run $(GITLEAKS) dir --no-banner --redact --config .gitleaks.toml infra/hosted/image |
| - CGO_ENABLED=0 go test ./internal/hostedimage -run '^(TestManifestPinsEverything|TestBuildReproducible|TestBuildChecksPins|TestImageInputsHaveNoSecrets|TestBuildScansPayload|TestScanAllowExact|TestBuildNeedsGitleaksConfig|TestImageLayoutMatchesContainmentSuite|TestScanIgnoresGitleaksAllowances|TestScanRPMScriptlets|TestScanNestedArchives)$$' -count=1 |
| + CGO_ENABLED=0 go test ./internal/hostedimage -run '^(TestManifestPinsEverything|TestBuildReproducible|TestBuildChecksPins|TestImageInputsHaveNoSecrets|TestBuildScansPayload|TestScanAllowExact|TestBuildNeedsGitleaksConfig|TestImageLayoutMatchesContainmentSuite|TestScanIgnoresGitleaksAllowances|TestScanRPMScriptlets|TestScanNestedArchives|TestScanPathRules|TestScanV7Tar|TestRPMExpansionBudget)$$' -count=1 |
| # Rastrillo v0.30.0's CLI assumes a single internal app directory. The |
| # runner protocol is a second package, so call the same dump.Compute API |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index f2ae2fbb..93c0254d 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -641,3 +641,43 @@ Also run: |
| - `CGO_ENABLED=0 go test ./internal/hostedimage/... ./internal/isolatedjob/... ./cmd/equipo-hosted-image -count=1`: ok. |
| - `make budget build vet hosted-image-check`: ok. The make target now runs the three new tests. |
| - staticcheck v0.7.0, gitleaks `dir` on `internal/hostedimage`, lanes-check, gofmt and `git diff --check`: clean. |
| + |
| +### Task 10 review round 3 (t10-r3.md: the three Important findings fixed; no further Astra round) |
| + |
| +1. **Path rules fire, and paths suppress nothing.** Fragments carry the member's path again (`<input>/<member>`), so rules that need a path, such as `kubernetes-secret-yaml`, run. |
| + - `payloadDetector` copies the configuration and passes the global and every per-rule allowlist through `pathFree`: |
| + - an allowlist with no path condition is kept; |
| + - an AND allowlist with a path is dropped, because without its path it would allow more; |
| + - an OR allowlist keeps its regexes, stopwords and commits, and is dropped if it has none. |
| + - The cached configuration itself is never changed. |
| + - New TestScanPathRules: a Kubernetes Secret at `go/share/deployment.yaml` is refused. |
| + - TestScanIgnoresGitleaksAllowances (vendor, node_modules, `*.bin`) still passes with the path given. |
| +2. **Tar by checksum.** |
| + - `isTar` accepts a 512-byte header whose checksum field holds, signed or unsigned. That covers ustar, GNU and PAX, and V7, which has no magic. |
| + - An input named as an archive must be one. A `.tar.gz` input that is not gzip, or whose content is not a tar, is `unreadable-container`; so is a `.rpm` input that is not an RPM. |
| + - New TestScanV7Tar: |
| + - a V7 Go tarball with `go/.ssh/id_ed25519`; |
| + - a nested V7 tar holding a deflated zip with a key; |
| + - a gzip that is no tarball, and a package that is no RPM. |
| +3. **RPM payload budget.** |
| + - Each cpio body is charged with `spend` before it is read, and a body over `maxMember` is a finding. Either one ends that payload's walk at once: nothing after it is read or skipped. |
| + - The decompressed stream is bounded to `maxExpanded` plus `cpioFraming` (64 MiB for headers and names). |
| + - `maxMember` and `maxExpanded` are now vars, so tests can set small limits. |
| + - New TestRPMExpansionBudget: |
| + - with a 1000-byte budget, three 400-byte files then a credential: `over-limit` at the third, and the credential never read; |
| + - with a 500-byte member limit, a 600-byte file then a credential: `over-limit` at the first, and nothing read after it. |
| + |
| +Mutation checks. Each was applied by script and the named test run with `CGO_ENABLED=0 go test ./internal/hostedimage -run '^<Test>$' -count=1`. Every run compiled and failed on its assertion, and the file was restored and checked by SHA-256. |
| + |
| +54. Member path not given to gitleaks. TestScanPathRules: FAIL, `scan_test.go:364: findings [...:go/share/deployment.yaml line 7 (generic-api-key)], want the Kubernetes Secret`. Rerun after the fixture value was split for the repository's own gitleaks: same failure. Restored. |
| +55. Path conditions kept in the allowlists (the detector built from the original configuration). TestScanIgnoresGitleaksAllowances: FAIL, `scan_test.go:269: Build = <nil>, want a payload scan refusal`. Restored. |
| +56. Tar known only by the ustar marker. TestScanV7Tar: FAIL, `scan_test.go:375: V7 Go tarball: findings [go1.26.11.linux-amd64.tar.gz (unreadable-container)], want the forbidden name`. Restored. |
| +57. A Go tarball that is no tarball scanned as bytes. TestScanV7Tar: FAIL, `scan_test.go:386: Build = <nil>, want a payload scan refusal`. Restored. |
| +58. A package that is no RPM scanned as bytes. TestScanV7Tar: FAIL, `scan_test.go:391: Build = <nil>, want a payload scan refusal`. Restored. |
| +59. cpio bodies not charged. TestRPMExpansionBudget: FAIL, `scan_test.go:416: over the aggregate budget: findings [... pkgs/git-core-...rpm:d line 1 (aws-access-token)], want over-limit at c and nothing read after it`. Restored. |
| +60. Walk goes on past an oversized file (skip and continue). TestRPMExpansionBudget: FAIL, `scan_test.go:424: an oversized file: findings [... :a (over-limit) ...:z line 1 (aws-access-token)], want over-limit at a and nothing read after it`. Restored. |
| + |
| +Also run: |
| +- `CGO_ENABLED=0 go test ./internal/hostedimage/... ./internal/isolatedjob/... ./cmd/equipo-hosted-image -count=1`: ok. |
| +- `make budget build vet hosted-image-check`: ok. The make target now runs the three new tests. |
| +- staticcheck v0.7.0, gitleaks `dir` on `internal/hostedimage` (after the fixture value was split), lanes-check, gofmt and `git diff --check`: clean. |
diff --git a/internal/hostedimage/hostedimagetest/hostedimagetest.go b/internal/hostedimage/hostedimagetest/hostedimagetest.go| index 4221b188..bce76fc1 100644 |
| --- a/internal/hostedimage/hostedimagetest/hostedimagetest.go |
| +++ b/internal/hostedimage/hostedimagetest/hostedimagetest.go |
| @@ -192,6 +192,44 @@ func Tar(files map[string][]byte) []byte { |
| return b.Bytes() |
| } |
| +// V7Tar is a tarball in the old V7 format: headers with a checksum and |
| +// no "ustar" magic, regular files only. |
| +func V7Tar(files map[string][]byte) []byte { |
| + var b bytes.Buffer |
| + for _, name := range slices.Sorted(mapKeys(files)) { |
| + h := make([]byte, 512) |
| + copy(h[0:100], name) |
| + copy(h[100:108], "0000644\x00") |
| + copy(h[108:116], "0000000\x00") |
| + copy(h[116:124], "0000000\x00") |
| + copy(h[124:136], fmt.Sprintf("%011o\x00", len(files[name]))) |
| + copy(h[136:148], "00000000000\x00") |
| + h[156] = '0' |
| + copy(h[148:156], " ") |
| + sum := 0 |
| + for _, c := range h { |
| + sum += int(c) |
| + } |
| + copy(h[148:156], fmt.Sprintf("%06o\x00 ", sum)) |
| + b.Write(h) |
| + b.Write(files[name]) |
| + if pad := (512 - len(files[name])%512) % 512; pad > 0 { |
| + b.Write(make([]byte, pad)) |
| + } |
| + } |
| + b.Write(make([]byte, 1024)) |
| + return b.Bytes() |
| +} |
| + |
| +// Gzip compresses b. |
| +func Gzip(b []byte) []byte { |
| + var out bytes.Buffer |
| + w := gzip.NewWriter(&out) |
| + _, _ = w.Write(b) |
| + _ = w.Close() |
| + return out.Bytes() |
| +} |
| + |
| // Zip is a deflated zip of files. |
| func Zip(files map[string][]byte) []byte { |
| var b bytes.Buffer |
diff --git a/internal/hostedimage/nested.go b/internal/hostedimage/nested.go| index a36fab59..fc413644 100644 |
| --- a/internal/hostedimage/nested.go |
| +++ b/internal/hostedimage/nested.go |
| @@ -9,6 +9,7 @@ import ( |
| "errors" |
| "io" |
| "path" |
| + "strconv" |
| "strings" |
| "github.com/klauspost/compress/zstd" |
| @@ -23,11 +24,16 @@ const ( |
| // pinned input itself, when it is a container (the Go tarball, an |
| // RPM), is the first. |
| maxDepth = 3 |
| - // maxExpanded bounds the bytes one input expands to, all members |
| - // and decompressed streams together. |
| - maxExpanded = 4 << 30 |
| ) |
| +// maxExpanded bounds the bytes one input expands to, all members and |
| +// decompressed streams together. A var so tests can use a small one. |
| +var maxExpanded int64 = 4 << 30 |
| + |
| +// cpioFraming is what an RPM payload stream may hold beyond its charged |
| +// bodies: cpio headers, names and padding. |
| +const cpioFraming = 64 << 20 |
| + |
| // walk is the scan of one pinned input. |
| type walk struct { |
| s *scanner |
| @@ -64,13 +70,59 @@ func (w *walk) spend(member string, n int64) bool { |
| return true |
| } |
| -// scanInput scans one pinned input, held in memory. |
| +// scanInput scans one pinned input, held in memory. An input whose name |
| +// declares an archive (the Go tarball, a package) must be one: a gzip |
| +// tarball, an RPM. |
| func (s *scanner) scanInput(input string, b []byte) error { |
| w := &walk{s: s, input: input} |
| + switch { |
| + case strings.HasSuffix(input, ".tar.gz"): |
| + if sniff(b) != kindGzip { |
| + w.finding("", sha256Hex(b), "unreadable-container") |
| + return nil |
| + } |
| + out, ok := w.expand("", sha256Hex(b), kindGzip, b) |
| + if !ok { |
| + return nil |
| + } |
| + if sniff(out) != kindTar { |
| + w.finding("", sha256Hex(b), "unreadable-container") |
| + return nil |
| + } |
| + w.blob("", out, 0) |
| + return nil |
| + case strings.HasSuffix(input, ".rpm"): |
| + if sniff(b) != kindRPM { |
| + w.finding("", sha256Hex(b), "unreadable-container") |
| + return nil |
| + } |
| + } |
| w.blob("", b, 0) |
| return nil |
| } |
| +// isTar reports whether b starts with a tar header whose checksum holds: |
| +// ustar, GNU and PAX archives and the old V7 format, which has no magic. |
| +func isTar(b []byte) bool { |
| + if len(b) < 512 || b[0] == 0 { |
| + return false |
| + } |
| + field := strings.Trim(string(b[148:156]), " \x00") |
| + want, err := strconv.ParseInt(field, 8, 64) |
| + if err != nil || field == "" { |
| + return false |
| + } |
| + var unsigned, signed int64 |
| + for i, c := range b[:512] { |
| + if i >= 148 && i < 156 { |
| + c = ' ' |
| + } |
| + unsigned += int64(c) |
| + signed += int64(int8(c)) |
| + } |
| + return want == unsigned || want == signed |
| +} |
| + |
| // member scans a file found at member inside a container opened at |
| // level: its name, then its bytes. |
| func (w *walk) member(member string, body []byte, level int) { |
| @@ -104,7 +156,7 @@ func sniff(b []byte) int { |
| return kindZstd |
| case has(0, "BZh") && has(4, "1AY&SY"): |
| return kindBzip2 |
| - case has(257, "ustar"): |
| + case isTar(b): |
| return kindTar |
| case has(0, "PK\x03\x04"), has(0, "PK\x05\x06"): |
| return kindZip |
| @@ -186,7 +238,7 @@ func (w *walk) expand(member, sum string, kind int, b []byte) ([]byte, bool) { |
| w.finding(member, sum, "unreadable-container") |
| return nil, false |
| } |
| - if len(out) > maxMember { |
| + if int64(len(out)) > maxMember { |
| w.finding(member, sum, "over-limit") |
| return nil, false |
| } |
| @@ -258,7 +310,7 @@ func (w *walk) zip(member, sum string, b []byte, level int) { |
| w.s.scanName(w.input, join(member, name), "") |
| continue |
| } |
| - if f.UncompressedSize64 > maxMember { |
| + if f.UncompressedSize64 > uint64(maxMember) { |
| w.finding(join(member, name), "", "over-limit") |
| continue |
| } |
| @@ -272,7 +324,7 @@ func (w *walk) zip(member, sum string, b []byte, level int) { |
| } |
| body, err := io.ReadAll(io.LimitReader(rc, maxMember+1)) |
| rc.Close() |
| - if err != nil || len(body) > maxMember { |
| + if err != nil || int64(len(body)) > maxMember { |
| w.finding(member, sum, "unreadable-container") |
| return |
| } |
diff --git a/internal/hostedimage/rpm.go b/internal/hostedimage/rpm.go| index aae8dbfa..6a505396 100644 |
| --- a/internal/hostedimage/rpm.go |
| +++ b/internal/hostedimage/rpm.go |
| @@ -200,7 +200,10 @@ func (w *walk) rpm(member string, b []byte, level int) { |
| return |
| } |
| seen := map[string]bool{} |
| - if err := w.cpio(member, bufio.NewReader(pr), seen, level); err != nil { |
| + // The stream is bounded too, so no amount of cpio framing around the |
| + // charged bodies can make it expand without end. |
| + bounded := io.LimitReader(pr, maxExpanded+cpioFraming) |
| + if err := w.cpio(member, bufio.NewReader(bounded), seen, level); err != nil { |
| w.finding(member, sum, "unreadable-container") |
| return |
| } |
| @@ -262,22 +265,24 @@ func (w *walk) cpio(member string, r io.Reader, seen map[string]bool, level int) |
| } |
| name = strings.TrimPrefix(path.Clean(strings.TrimPrefix(name, ".")), "/") |
| seen[name] = true |
| + // Each body is charged before it is read or skipped; the first |
| + // one over a limit ends the walk of this payload. |
| if size > maxMember { |
| w.finding(join(member, name), "", "over-limit") |
| - if err := skip(size); err != nil { |
| - return err |
| - } |
| + return nil |
| + } |
| + if !w.spend(join(member, name), size) { |
| + return nil |
| + } |
| + body := make([]byte, size) |
| + if _, err := io.ReadFull(r, body); err != nil { |
| + return err |
| + } |
| + pos += size |
| + if mode&0o170000 == 0o100000 { // a regular file |
| + w.member(join(member, name), body, level) |
| } else { |
| - body := make([]byte, size) |
| - if _, err := io.ReadFull(r, body); err != nil { |
| - return err |
| - } |
| - pos += size |
| - if mode&0o170000 == 0o100000 { // a regular file |
| - w.member(join(member, name), body, level) |
| - } else { |
| - w.s.scanName(w.input, join(member, name), "") |
| - } |
| + w.s.scanName(w.input, join(member, name), "") |
| } |
| if err := pad4(); err != nil { |
| return err |
diff --git a/internal/hostedimage/scan.go b/internal/hostedimage/scan.go| index ea4690ad..89fca40b 100644 |
| --- a/internal/hostedimage/scan.go |
| +++ b/internal/hostedimage/scan.go |
| @@ -125,14 +125,55 @@ func loadDetector(path string) (*detect.Detector, error) { |
| } |
| // payloadDetector is a detector for the payload scan: an inline |
| -// "gitleaks:allow" in a pinned file suppresses nothing. Only ScanAllow |
| -// may. |
| +// "gitleaks:allow" in a pinned file suppresses nothing, and neither does |
| +// a member's path, since every path condition is taken out of the global |
| +// and the per-rule allowlists (pathFree). Only ScanAllow may suppress. |
| func payloadDetector(cfg config.Config) *detect.Detector { |
| - d := detect.NewDetector(cfg) |
| + c := cfg |
| + c.Allowlists = pathFree(cfg.Allowlists) |
| + c.Rules = make(map[string]config.Rule, len(cfg.Rules)) |
| + for id, r := range cfg.Rules { |
| + r.Allowlists = pathFree(r.Allowlists) |
| + c.Rules[id] = r |
| + } |
| + d := detect.NewDetector(c) |
| d.IgnoreGitleaksAllow = true |
| return d |
| } |
| +// pathFree is as without path conditions. An allowlist with none is kept; |
| +// one that needs a path and something else (AND) is dropped, since |
| +// without its path it would allow more; one that allows by path or |
| +// something else (OR) keeps the something else, or is dropped when there |
| +// is nothing else. |
| +func pathFree(as []*config.Allowlist) []*config.Allowlist { |
| + var out []*config.Allowlist |
| + for _, a := range as { |
| + if len(a.Paths) == 0 { |
| + out = append(out, a) |
| + continue |
| + } |
| + if a.MatchCondition == config.AllowlistMatchAnd || len(a.Commits)+len(a.Regexes)+len(a.StopWords) == 0 { |
| + continue |
| + } |
| + n := &config.Allowlist{Description: a.Description, MatchCondition: a.MatchCondition, Commits: a.Commits, |
| + RegexTarget: a.RegexTarget, Regexes: a.Regexes, StopWords: a.StopWords} |
| + if n.Validate() == nil { |
| + out = append(out, n) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// fragmentPath is the path gitleaks sees for a member: the input and the |
| +// member's place inside it. |
| +func fragmentPath(input, member string) string { |
| + if member == "" { |
| + return input |
| + } |
| + return input + "/" + member |
| +} |
| + |
| // scanner collects findings over the inputs. |
| type scanner struct { |
| d *detect.Detector |
| @@ -154,11 +195,12 @@ func (s *scanner) scanBytes(input, member string, b []byte) { |
| seen := map[string]bool{} |
| for start := 0; ; start += scanChunk { |
| end := min(start+scanChunk+scanOverlap, len(b)) |
| - // No FilePath: gitleaks' path allowlists (the defaults skip |
| - // vendor/, node_modules/, *.bin and the like) match only a path, |
| - // so with none they suppress nothing. Only ScanAllow may. |
| + // The member's path goes with the bytes, so rules that need a |
| + // path (a Kubernetes Secret in a .yaml) fire. The payload |
| + // detector's allowlists hold no path (payloadDetector), so the |
| + // path suppresses nothing. Only ScanAllow may. |
| //lint:ignore SA1019 Detect takes this type in gitleaks v8; v9 renames it. |
| - for _, f := range s.d.Detect(detect.Fragment{Raw: string(b[start:end])}) { |
| + for _, f := range s.d.Detect(detect.Fragment{Raw: string(b[start:end]), FilePath: fragmentPath(input, member)}) { |
| key := f.RuleID + "\x00" + f.Match |
| if seen[key] { |
| continue // the same match in an overlap |
| @@ -174,8 +216,8 @@ func (s *scanner) scanBytes(input, member string, b []byte) { |
| } |
| // maxMember bounds one archive member, or one decompressed stream, read |
| -// into memory. |
| -const maxMember = 1 << 30 |
| +// into memory. A var so tests can use a small one. |
| +var maxMember int64 = 1 << 30 |
| // judge drops the findings allow covers and returns what is left, plus |
| // any allowance that matched nothing. |
diff --git a/internal/hostedimage/scan_test.go b/internal/hostedimage/scan_test.go| index 87231707..185d6997 100644 |
| --- a/internal/hostedimage/scan_test.go |
| +++ b/internal/hostedimage/scan_test.go |
| @@ -350,3 +350,79 @@ func gz(b []byte) []byte { |
| _ = w.Close() |
| return out.Bytes() |
| } |
| + |
| +// TestScanPathRules (review round 3): rules that need a path fire on a |
| +// member's bytes. A Kubernetes Secret in a .yaml member is refused, |
| +// though its name passes ForbiddenPath. |
| +func TestScanPathRules(t *testing.T) { |
| + // The value is assembled here so this file's own text holds no |
| + // credential-shaped line. |
| + secret := "apiVersion: v1\nkind: Secret\nmetadata:\n name: db\ntype: Opaque\ndata:\n password: " + "c3VwZXJzZWNy" + "ZXRwYXNzd29yZDEy\n" |
| + m := fixture(t) |
| + plantGo(t, &m, map[string][]byte{"go/share/deployment.yaml": []byte(secret)}) |
| + if fs := buildFindings(t, m); !hasFinding(fs, goInput+":go/share/deployment.yaml", "kubernetes-secret-yaml") { |
| + t.Fatalf("findings %v, want the Kubernetes Secret", fs) |
| + } |
| +} |
| + |
| +// TestScanV7Tar (review round 3): a tar is known by its header checksum, |
| +// V7 included, not by the ustar marker; an input named as an archive that |
| +// does not read as one is refused. |
| +func TestScanV7Tar(t *testing.T) { |
| + key := []byte(hostedimagetest.PrivateKey) |
| + m := fixture(t) |
| + setInput(t, &m, goInput, hostedimagetest.Gzip(hostedimagetest.V7Tar(map[string][]byte{ |
| + "go/bin/go": []byte("fake go\n"), "go/.ssh/id_ed25519": []byte("x\n")}))) |
| + if fs := buildFindings(t, m); !hasFinding(fs, goInput+":go/.ssh/id_ed25519", "forbidden-path") { |
| + t.Fatalf("V7 Go tarball: findings %v, want the forbidden name", fs) |
| + } |
| + |
| + m = fixture(t) |
| + plantGo(t, &m, map[string][]byte{"go/x.tar": hostedimagetest.V7Tar(map[string][]byte{"in.zip": hostedimagetest.Zip(map[string][]byte{"k": key})})}) |
| + if fs := buildFindings(t, m); !hasFinding(fs, goInput+":go/x.tar!/in.zip!/k", "private-key") { |
| + t.Fatalf("nested V7 tar: findings %v, want the key in the zip", fs) |
| + } |
| + |
| + m = fixture(t) |
| + setInput(t, &m, goInput, hostedimagetest.Gzip([]byte("not a tarball\n"))) |
| + if fs := buildFindings(t, m); !hasFinding(fs, goInput, "unreadable-container") { |
| + t.Fatalf("a Go tarball that is no tarball: findings %v", fs) |
| + } |
| + m = fixture(t) |
| + setInput(t, &m, "pkgs/"+m.Packages[0].Name, []byte("not a package\n")) |
| + if fs := buildFindings(t, m); !hasFinding(fs, "pkgs/"+m.Packages[0].Name, "unreadable-container") { |
| + t.Fatalf("a package that is no RPM: findings %v", fs) |
| + } |
| +} |
| + |
| +// withLimits sets the scan's size limits for one test. |
| +func withLimits(t *testing.T, member, expanded int64) { |
| + oldM, oldE := maxMember, maxExpanded |
| + maxMember, maxExpanded = member, expanded |
| + t.Cleanup(func() { maxMember, maxExpanded = oldM, oldE }) |
| +} |
| + |
| +// TestRPMExpansionBudget (review round 3): an RPM payload's files count |
| +// against the input's expansion budget before each is read; the walk |
| +// stops at the first one over a limit, so nothing after it is read. |
| +func TestRPMExpansionBudget(t *testing.T) { |
| + late := []byte("aws_access_key_id = " + hostedimagetest.AWSKey + "\n") |
| + pkg := func(m Manifest) string { return "pkgs/" + m.Packages[0].Name } |
| + fill := bytes.Repeat([]byte("x"), 400) |
| + |
| + withLimits(t, 1<<20, 1000) |
| + m := fixture(t) |
| + setInput(t, &m, pkg(m), hostedimagetest.RPM(map[string][]byte{"/a": fill, "/b": fill, "/c": fill, "/d": late, "/usr/bin/git": []byte("g\n")}, "gzip")) |
| + fs := buildFindings(t, m) |
| + if !hasFinding(fs, pkg(m)+":c", "over-limit") || hasFinding(fs, pkg(m)+":d", "aws-access-token") { |
| + t.Fatalf("over the aggregate budget: findings %v, want over-limit at c and nothing read after it", fs) |
| + } |
| + |
| + withLimits(t, 500, 1<<20) |
| + m = fixture(t) |
| + setInput(t, &m, pkg(m), hostedimagetest.RPM(map[string][]byte{"/a": bytes.Repeat([]byte("x"), 600), "/z": late, "/usr/bin/git": []byte("g\n")}, "gzip")) |
| + fs = buildFindings(t, m) |
| + if !hasFinding(fs, pkg(m)+":a", "over-limit") || hasFinding(fs, pkg(m)+":z", "aws-access-token") { |
| + t.Fatalf("an oversized file: findings %v, want over-limit at a and nothing read after it", fs) |
| + } |
| +} |