Webhook icon
Schedule icon
WorkingDirectory icon
Clone icon
Commands icon
Docker icon
Script icon
Process icon
If icon
Create icon
SlackIncomingWebhook icon
Log icon

Gate Your Push Pipeline on Semgrep Static Analysis Findings

Run Semgrep SAST on every push, parse the report, and escalate findings with a labeled GitHub issue and a Slack alert in Kestra.

Categories
Infrastructure

Secrets scanners catch leaked keys, but they say nothing about SQL injection, command injection, unsafe deserialization, or the dozen other classes of flaw that live in application source. This blueprint wires Semgrep into your push pipeline. CI POSTs to a keyed webhook, the repository is checked out into a shared working directory, Semgrep runs in its official container with the community p/security-audit pack, and a small Python step turns the JSON report into a verdict with a findings count, the rules that fired, and the scan timestamp. When findings exist the flow opens a labeled GitHub issue and alerts Slack, so SAST debt lands in the team's existing backlog instead of a report nobody opens. A clean scan records the all-clear with a pointer to the stored report, and a disabled daily schedule ships as a net for pushes whose webhook was skipped.

How it works

  1. The on_push trigger (io.kestra.plugin.core.trigger.Webhook) exposes a keyed URL for your CI push hook to POST to with the repository, ref, and commit.
  2. daily_net (io.kestra.plugin.core.trigger.Schedule) is a 06:00 UTC daily run shipped disabled. Remove disabled: true once the webhook is proven so a missed hook cannot silently skip the gate.
  3. workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared filesystem for everything that follows, so the scanner sees the clone and the parser sees the report.
  4. clone_repository (io.kestra.plugin.git.Clone) checks out {{ inputs.repository }} at {{ inputs.ref }}, authenticating with the GITHUB_TOKEN secret.
  5. run_semgrep (io.kestra.plugin.scripts.shell.Commands on the io.kestra.plugin.scripts.runner.docker.Docker runner, image semgrep/semgrep:latest) executes semgrep scan --config p/security-audit --json --output semgrep-report.txt || true. The trailing || true absorbs the non-zero exit Semgrep returns when findings exist, the JSON report is always written, and the parsed report drives the gate.
  6. parse_report (io.kestra.plugin.scripts.python.Script on the Process runner) reads the report and emits verdict, findings_count, error_count, top_rules, top_rules_summary, and scan_time as a single-line ::{"outputs": ...}:: JSON payload. A missing or unparseable report yields verdict: error rather than a false clean.
  7. check_findings (io.kestra.plugin.core.flow.If) branches on findings_count. Over zero, create_issue (io.kestra.plugin.github.issues.Create) opens an issue titled with the repository and the count and labeled security and sast, and alert_slack posts the count and top rules. At zero, log_clean records the all-clear with the stored report URI.
  8. The errors block alerts Slack when the scan itself fails - clone error, image pull failure, parser crash - because a broken scanner looks exactly like a clean repository.

What you get

  • A SAST verdict on every push instead of a weekly report someone forgets to read.
  • A labeled GitHub issue carrying the finding count, top rules, scan time, and a link to the raw report.
  • A Slack escalation so the security channel sees findings while the commit is still fresh.
  • verdict, findings_count, top_rules, and report_uri as flow outputs, ready for status checks and dashboards.
  • A scan trail: every execution, clean or dirty, is a dated record in Kestra history with the report archived.
  • A disabled daily schedule as defense in depth against skipped webhooks.

Who it's for

  • Development teams that want Semgrep gating in CI without maintaining CI YAML for it.
  • Security engineers who need every push checked against the security-audit pack with findings tracked as issues.
  • Platform teams already running Kestra who want one declarative file for scan, gate, and escalation.

Why orchestrate this with Kestra

Semgrep is an excellent scanner, but a scanner nobody configures catches nothing. Kestra supplies the loop around it: an event trigger for every push, a hermetic Docker runner so the tool version lives in the flow, a branch that separates escalation from the all-clear, retries and execution history for every run, and alert routing into GitHub and Slack from one file. A CI job running Semgrep gives developers none of that - it only protects the repositories whose pipelines someone remembered to update, and skipped runs vanish without a trace.

Prerequisites

  • A worker with Docker access for the Semgrep container and Python 3 on the host for the report parser, or switch parse_report to a Docker task runner.
  • A GitHub repository that allows cloning and issue creation with the provided token (classic PAT scope repo, or fine-grained Contents: read plus Issues: write).
  • A Slack incoming webhook for the findings escalation and the failure alert.
  • A CI hook that POSTs push events to the webhook URL.

Secrets

  • GITHUB_TOKEN: personal access token used both to clone the repository and to open the issue on findings.
  • SAST_WEBHOOK_KEY: key segment guarding the webhook URL - anyone with it can trigger a scan, so treat it as a secret.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for escalation and failure alerts.

Quick start

  1. Add the three secrets to your Kestra namespace.
  2. Set repository to the owner/repo you want gated and ref if it is not main.
  3. Point your CI push hook at /api/v1/{tenant}/executions/webhook/{namespace}/semgrep-sast-pr-gate/{SAST_WEBHOOK_KEY}, or trigger the webhook manually.
  4. Confirm a clean run, then push a commit containing a deliberate weakness (for example an os.system call on user input) and confirm the issue, the Slack alert, and the fail verdict.
  5. Once the webhook is trusted, remove disabled: true from daily_net so skipped pushes still get scanned.

How to extend

  • Derive the repository and ref from the push payload instead of inputs with {{ fromJson(trigger.body).repository.full_name }} for multi-repo setups.
  • Swap --config p/security-audit for a committed .semgrep.yml or a different registry pack per repository.
  • Tighten the gate by failing the execution in the then branch with io.kestra.plugin.core.execution.Fail so branch protection blocks the merge.
  • Fan out across many repositories with io.kestra.plugin.core.flow.Loop over a repository list.
  • Archive the report to S3 with io.kestra.plugin.aws.s3.Upload after the parse step for long-term retention.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.