chore: publish IntegraCI build modules a11ec75d3e09
This commit is contained in:
1 parent
694710104a
commit
3c2b80914e
78 files changed
+4982
-405
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package main
|
||||
|
||||
// The scan of record (ADR-0093 §4 condition 3, WP-05): the repository being
|
||||
// judged must not be able to steer the scanner that judges it. By default
|
||||
// Trivy reads trivy.yaml, .trivyignore[.yaml] and trivy-secret.yaml from the
|
||||
// tree it scans, so a change could ignore its own licence or misconfiguration
|
||||
// finding (WP-13 review, 2026-11-05, CONFIRMED). With --scan-of-record those
|
||||
// files are removed from the scanned copy (reported as ignored_suppressions)
|
||||
// and Trivy is told to read no configuration from the tree at all. Mirrors
|
||||
// security-scan's withoutSuppression / trustedConfigArgs.
|
||||
//
|
||||
// Pure where it can be: dropSuppression takes the tree's glob and "without"
|
||||
// as functions, so a test passes an in-memory tree and checks the tree that
|
||||
// comes back.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// suppressionFiles are the files Trivy (and Checkov) read from the scanned
|
||||
// tree and obey. Kept equal to security-scan's list by
|
||||
// apps/api/tests/test_analysis_of_record.py.
|
||||
var suppressionFiles = []string{
|
||||
".gitleaksignore",
|
||||
".gitleaks.toml",
|
||||
".trivyignore",
|
||||
".trivyignore.yaml",
|
||||
"trivy.yaml",
|
||||
"trivy.yml",
|
||||
".semgrepignore",
|
||||
".checkov.yaml",
|
||||
".checkov.yml",
|
||||
"trivy-secret.yaml",
|
||||
"trivy-secret.yml",
|
||||
}
|
||||
|
||||
// dropSuppression returns source minus every suppressionFiles entry, at any
|
||||
// depth, and the paths it removed. A tree that cannot be listed is an error:
|
||||
// a scan of record that could not drop the suppressions is not one.
|
||||
func dropSuppression[T any](
|
||||
ctx context.Context,
|
||||
source T,
|
||||
glob func(context.Context, string) ([]string, error),
|
||||
without func(T, []string) T,
|
||||
) (T, []string, error) {
|
||||
var found []string
|
||||
for _, name := range suppressionFiles {
|
||||
for _, pattern := range []string{name, "**/" + name} {
|
||||
matches, err := glob(ctx, pattern)
|
||||
if err != nil {
|
||||
var none T
|
||||
return none, nil, fmt.Errorf("list %s for the scan of record: %w", name, err)
|
||||
}
|
||||
found = append(found, matches...)
|
||||
}
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
var removed []string
|
||||
for _, p := range found {
|
||||
if !seen[p] {
|
||||
seen[p] = true
|
||||
removed = append(removed, p)
|
||||
}
|
||||
}
|
||||
if len(removed) == 0 {
|
||||
return source, nil, nil
|
||||
}
|
||||
return without(source, removed), removed, nil
|
||||
}
|
||||
|
||||
// trustedConfigArgs are the Trivy flags the scan of record adds: no
|
||||
// configuration, ignore file or secret configuration is read from the tree
|
||||
// it scans (Trivy 0.76, "Disabling configuration files").
|
||||
func trustedConfigArgs(scanOfRecord bool) []string {
|
||||
if !scanOfRecord {
|
||||
return nil
|
||||
}
|
||||
return []string{"--config=", "--ignorefile=", "--secret-config="}
|
||||
}
|
||||
|
||||
// withTrustedConfig inserts trustedConfigArgs before the final target
|
||||
// argument of a Trivy argv (the target must stay last).
|
||||
func withTrustedConfig(args []string, scanOfRecord bool) []string {
|
||||
extra := trustedConfigArgs(scanOfRecord)
|
||||
if len(extra) == 0 || len(args) == 0 {
|
||||
return args
|
||||
}
|
||||
out := append([]string{}, args[:len(args)-1]...)
|
||||
out = append(out, extra...)
|
||||
return append(out, args[len(args)-1])
|
||||
}
|
||||
Reference in new issue
Block a user