Files

sast-scan

UNVERIFIED SCAFFOLD — run dagger develop + dagger functions + test against a matching Dagger engine (engineVersion v0.15.0) before use. The Go in main.go has NOT been compiled or validated by Dagger codegen in this environment (dagger develop is unavailable, and the dag global plus the *Directory / *Container / *File types are generated). Do not assume it works as-is.

IntegraCI SAST (Static Application Security Testing) Dagger module. Runs Semgrep over a source directory, emits a SARIF report, counts findings, and optionally POSTs the result to the IntegraCI API.

It mirrors the structure and idioms of the sibling security-scan module.

Functions

scan

Runs Semgrep static analysis and returns a ScanResult.

Param Required Default Description
source yes — Source directory to scan
tool no semgrep SAST tool to run; none skips scanning
api-url no — IntegraCI API URL for posting results
token no — JWT token for API authentication
service-id no — Service ID to link scan results

When tool=none, the scan is skipped and a result with skipped=true is returned. Results are POSTed to the API only when both api-url and token are set.

Air-gapped rules (--rules-dir, ADR-0093 §8)

semgrep --config=auto fetches its rules from the Semgrep registry and sends the project URL, so it cannot run air-gapped. Pass --rules-dir with the extracted sast-rules content pack (catalog/sast-rules, ADR-0078) and the module runs semgrep scan --config=/rules --metrics=off with SEMGREP_SEND_METRICS=off and SEMGREP_ENABLE_VERSION_CHECK=0. auto is never used then. The argument builder is semgrep_args.go, tested without an engine in semgrep_args_test.go.

Without --rules-dir the legacy --config=auto run is unchanged and does NOT get --metrics=off: semgrep refuses that pair ("Cannot create auto config when metrics are off", exit 2).

Licences: the pack holds only in-house or permissively licensed rule files (the Semgrep-maintained registry rules are under the Semgrep Rules License v1.0, which forbids redistribution). The semgrep engine (LGPL-2.1) is never bundled by IntegraCI; the customer's mirror pulls semgrep/semgrep from upstream.

dagger call sarif --source . --rules-dir ./sast-rules export --path=integraci-sarif/sast.sarif

Which ruleset ran (#2908)

--rules-dir accepts any directory, and SARIF does not say which rule files produced it. scan therefore digests the directory it mounts at /rules (ruleset.go: for each non-hidden file in byte order of its relative path, <path>\0<sha256 hex>\n, then sha256: + the sha256 of those lines) and posts it as report_data.sast_ruleset_digest. The platform computes the digest of the pack it ships (catalog/sast-rules/rules) itself and compares; where the gate point and the sast family both enforce, a SAST scan of record with no digest (no --rules-dir, CodeQL) or another one is unknown. The posted value is never taken as the pack's digest. Paths with a hidden segment (.gitkeep) are skipped on both sides. The API image and the pack the runners mount must be deployed together: a pack revision the API image does not carry reads unknown.

Usage

These commands are illustrative and have NOT been run here. Verify against a live Dagger engine first.

# Scan and post results to the IntegraCI API
dagger call scan \
  --source . \
  --api-url http://localhost:8000 \
  --token "$TOKEN" \
  --service-id "$SVC_ID"

# Scan only (no API post)
dagger call scan --source .

# Skip scanning
dagger call scan --source . --tool none

Verifying the scaffold

dagger develop      # generate the SDK + codegen
dagger functions    # confirm the 'scan' function is exposed
gofmt -l main.go    # confirm formatting (should print nothing)