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
+40
-14
@@ -45,6 +45,8 @@ type ScanResult struct {
|
||||
Report string `json:"report,omitempty"`
|
||||
Skipped bool `json:"skipped"`
|
||||
Success bool `json:"success"`
|
||||
// Suppression files the scan of record removed from the scanned copy.
|
||||
IgnoredSuppressions []string `json:"ignored_suppressions,omitempty"`
|
||||
}
|
||||
|
||||
// Scan runs an IaC misconfiguration pass over the source directory with the
|
||||
@@ -70,8 +72,24 @@ func (m *IacScan) Scan(
|
||||
// Version (commit SHA / image tag) the scan applies to
|
||||
// +optional
|
||||
version string,
|
||||
// The analysis job of record (ADR-0093 §4, WP-05): the repository's
|
||||
// suppression files (trivy.yaml, .trivyignore[.yaml], .checkov.yaml, ...)
|
||||
// are removed from the scanned copy and Trivy reads no configuration from
|
||||
// the tree. Off for every other caller.
|
||||
// +optional
|
||||
scanOfRecord bool,
|
||||
) (*ScanResult, error) {
|
||||
result := &ScanResult{Tool: tool}
|
||||
if scanOfRecord {
|
||||
var err error
|
||||
source, result.IgnoredSuppressions, err = dropSuppression(ctx, source,
|
||||
func(ctx context.Context, pattern string) ([]string, error) { return source.Glob(ctx, pattern) },
|
||||
func(d *dagger.Directory, paths []string) *dagger.Directory { return d.WithoutFiles(paths) },
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
report string
|
||||
@@ -84,7 +102,7 @@ func (m *IacScan) Scan(
|
||||
result.Success = true
|
||||
return result, nil
|
||||
case "trivy":
|
||||
report, err = m.runTrivyConfig(ctx, source)
|
||||
report, err = m.runTrivyConfig(ctx, source, scanOfRecord)
|
||||
case "checkov":
|
||||
report, err = m.runCheckov(ctx, source)
|
||||
default:
|
||||
@@ -120,22 +138,15 @@ func (m *IacScan) Scan(
|
||||
// runTrivyConfig runs "trivy config" over the source directory in JSON mode.
|
||||
// Trivy exits non-zero when misconfigurations are present; we force
|
||||
// --exit-code 0 and read the JSON report rather than relying on the exit code.
|
||||
func (m *IacScan) runTrivyConfig(ctx context.Context, source *dagger.Directory) (string, error) {
|
||||
const reportPath = "/tmp/iac-report.json"
|
||||
func (m *IacScan) runTrivyConfig(ctx context.Context, source *dagger.Directory, scanOfRecord bool) (string, error) {
|
||||
report, err := dag.Container().
|
||||
From("aquasec/trivy:0.58.1").
|
||||
From("aquasec/trivy:0.76.1").
|
||||
// Persist Trivy's misconfig/policy DB across runs (avoids re-downloading it).
|
||||
WithMountedCache("/root/.cache/trivy", dag.CacheVolume("trivy-db")).
|
||||
WithMountedDirectory("/src", source).
|
||||
WithWorkdir("/src").
|
||||
WithExec([]string{
|
||||
"trivy", "config",
|
||||
"--format", "json",
|
||||
"--output", reportPath,
|
||||
"--exit-code", "0",
|
||||
".",
|
||||
}).
|
||||
File(reportPath).
|
||||
WithExec(iacTrivyArgs(scanOfRecord)).
|
||||
File(iacReportPath).
|
||||
Contents(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read trivy config JSON output: %w", err)
|
||||
@@ -143,6 +154,20 @@ func (m *IacScan) runTrivyConfig(ctx context.Context, source *dagger.Directory)
|
||||
return report, nil
|
||||
}
|
||||
|
||||
const iacReportPath = "/tmp/iac-report.json"
|
||||
|
||||
// iacTrivyArgs is the `trivy config` argv; the scan of record adds
|
||||
// trustedConfigArgs before the target.
|
||||
func iacTrivyArgs(scanOfRecord bool) []string {
|
||||
return withTrustedConfig([]string{
|
||||
"trivy", "config",
|
||||
"--format", "json",
|
||||
"--output", iacReportPath,
|
||||
"--exit-code", "0",
|
||||
".",
|
||||
}, scanOfRecord)
|
||||
}
|
||||
|
||||
// runCheckov runs Checkov over the source directory in JSON mode. Checkov
|
||||
// exits non-zero when failed checks are present, so we tolerate the exit code
|
||||
// and read the JSON emitted on stdout.
|
||||
@@ -195,8 +220,9 @@ func (m *IacScan) postResults(
|
||||
"medium_count": result.Medium,
|
||||
"low_count": result.Low,
|
||||
"report_data": map[string]any{
|
||||
"iac_critical": result.Critical,
|
||||
"iac_high": result.High,
|
||||
"iac_critical": result.Critical,
|
||||
"iac_high": result.High,
|
||||
"ignored_suppressions": result.IgnoredSuppressions,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user