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,60 @@
|
||||
package main
|
||||
|
||||
// Semgrep's command line, kept apart from the Dagger calls so it can be tested
|
||||
// without an engine (ADR-0093 §8, WP-09).
|
||||
//
|
||||
// Two modes:
|
||||
//
|
||||
// - rules from the `sast-rules` content pack (the scan of record, air-gap
|
||||
// safe): `--config=/rules --metrics=off`, never `auto`. Nothing is fetched
|
||||
// from the Semgrep registry and nothing is reported to it.
|
||||
// - no pack given: the legacy `--config=auto`, which fetches the registry
|
||||
// rules (Semgrep Rules License v1.0: the tenant's own internal use, from the
|
||||
// tenant's own CI) and sends the project URL. It cannot run air-gapped.
|
||||
// `--metrics=off` is NOT added here: semgrep refuses that pair outright
|
||||
// ("Cannot create auto config when metrics are off", exit 2), so adding it
|
||||
// would turn every existing pipeline red rather than make it private.
|
||||
|
||||
// semgrepRulesMount is where the pack's rules/ tree is mounted in the container.
|
||||
const semgrepRulesMount = "/rules"
|
||||
|
||||
// semgrepRulesSubdir is the directory of the pack that holds the rule files.
|
||||
// The pack root also carries LICENSES.yaml, which semgrep would try to load as
|
||||
// a rule file, so only this subdirectory is mounted.
|
||||
const semgrepRulesSubdir = "rules"
|
||||
|
||||
// semgrepArgs is the exec line for one semgrep run writing SARIF to sarifPath.
|
||||
//
|
||||
// For the scan of record (disableNosem, ADR-0093 §4, WP-05) it also ignores
|
||||
// inline `nosemgrep` comments: a change could otherwise mark its own finding
|
||||
// as not a finding.
|
||||
func semgrepArgs(sarifPath string, rulesFromPack, disableNosem bool) []string {
|
||||
args := []string{"semgrep", "scan"}
|
||||
if rulesFromPack {
|
||||
args = append(args, "--config="+semgrepRulesMount, "--metrics=off")
|
||||
} else {
|
||||
args = append(args, "--config=auto")
|
||||
}
|
||||
args = append(args, "--error", "--sarif", "--output", sarifPath)
|
||||
if disableNosem {
|
||||
// `--no-git-ignore` too: a committed file listed in the repository's
|
||||
// own .gitignore is still the repository's code, and a .gitignore line
|
||||
// would otherwise drop it from the scan as a .semgrepignore line did.
|
||||
args = append(args, "--disable-nosem", "--no-git-ignore")
|
||||
}
|
||||
return append(args, ".")
|
||||
}
|
||||
|
||||
// semgrepEnv is the environment of a pack run: no metrics and no version
|
||||
// check (both are calls to semgrep.dev, which an air-gapped runner cannot make
|
||||
// and a private one should not). Empty for the legacy `auto` run, for the
|
||||
// reason in the file comment.
|
||||
func semgrepEnv(rulesFromPack bool) [][2]string {
|
||||
if !rulesFromPack {
|
||||
return nil
|
||||
}
|
||||
return [][2]string{
|
||||
{"SEMGREP_SEND_METRICS", "off"},
|
||||
{"SEMGREP_ENABLE_VERSION_CHECK", "0"},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user