Webhook icon
Schedule icon
Request icon
Get icon
Script icon
If icon
Create icon
SlackIncomingWebhook icon
Fail icon
Set icon
Log icon

CodeQL Alert Regression Gate with Baseline Tracking

Track CodeQL regressions in Kestra: diff open high/critical code-scanning alerts against a stored baseline and escalate new findings to GitHub and Slack.

Categories
CoreInfrastructure

CodeQL findings have a way of piling up: a repository turns on default setup, six months later the security tab holds hundreds of open alerts, and nobody can tell which of them shipped this week. This blueprint treats the alert list as a regression signal rather than a backlog. A webhook fires when an analysis completes, the GitHub code-scanning API returns every open alert, and a Python step filters those alerts to high and critical severity and compares them against the numbers recorded by the last clean run. New findings escalate three ways at once: a labeled GitHub issue with direct links to each alert, a Slack notice, and a failed execution. A clean run stores the current alert set in Kestra's KV store, so the baseline only moves when the gate is green and a regression can never quietly become the new normal.

How it works

  1. The on_analysis_webhook trigger (io.kestra.plugin.core.trigger.Webhook) exposes a keyed URL for your GitHub hook or CI to POST to when an analysis completes or on push. The daily_sweep Schedule trigger ships disabled as a nightly safety net.
  2. fetch_open_alerts (io.kestra.plugin.core.http.Request) calls GET /repos/{owner}/{repo}/code-scanning/alerts?state=open with an Authorization: Bearer header built from the GITHUB_TOKEN secret and the application/vnd.github+json Accept header.
  3. fetch_latest_analysis (io.kestra.plugin.core.http.Request, allowFailure: true) pulls the newest entry from /code-scanning/analyses for triage context: which tool ran and on which ref.
  4. read_baseline (io.kestra.plugin.core.kv.Get) loads the alert numbers stored by the previous clean run with errorOnMissing: false, so the very first run absorbs existing alerts into the baseline instead of blocking the world.
  5. assess (io.kestra.plugin.scripts.python.Script) filters alerts to security_severity_level critical or high (checking the rule as a fallback), splits them into new versus baseline-known, and emits verdict, counts, and a structured new_high_critical list through the outputs protocol.
  6. gate (io.kestra.plugin.core.flow.If) branches on the blocked verdict. Over threshold, open_issue (io.kestra.plugin.github.issues.Create) opens an issue labeled security and codeql listing every new alert with its link, alert_slack posts the count and summary, and fail_the_run (io.kestra.plugin.core.execution.Fail) turns the execution red. Under threshold, advance_baseline (io.kestra.plugin.core.kv.Set) records the current high and critical numbers and log_clean writes the all-clear.
  7. The errors block alerts Slack when the gate itself breaks, because a dead gate looks exactly like a clean repository.

What you get

  • New high and critical CodeQL findings caught the day they appear instead of at the next audit.
  • Regression semantics: pre-existing alerts are counted and reported but do not block, so the gate is adoptable on day one.
  • Escalation where engineers already work: a labeled GitHub issue with alert links, plus a Slack ping.
  • A baseline stored in Kestra KV that only advances on a green run.
  • Typed outputs (verdict, total_open, new_high_critical) a parent pipeline can branch on, and a dated execution history for every gate run.

Who it's for

  • Security engineers who need a "no new high or critical findings" policy enforced on every push and every night.
  • Platform teams already running Kestra who want the security tab to stop being a surprise.
  • Repository owners adopting code scanning who need a gate that does not fail on day one for alerts that predate the gate.

Why orchestrate this with Kestra

Fetching a GitHub API list is easy; remembering what was there yesterday is the hard part. Kestra supplies the durable KV store for the baseline, the branch that only advances it on a green run, the keyed webhook that CI can call without extra infrastructure, and typed outputs a release pipeline can consume. The same gate written as a cron script becomes a state file nobody trusts, an alert channel nobody watches, and a check everyone bypasses after the first noisy week. Because every run is a dated execution with recorded inputs and outputs, answering when a given alert number appeared takes one look at the execution history.

Prerequisites

  • A GitHub repository with code scanning enabled (default setup or Advanced setup), and a token that can read code-scanning alerts (classic PAT scope security_events, or fine-grained Code scanning alerts read plus Issues write for the escalation issue).
  • A Kestra KV store available to the namespace, since the baseline lives there.
  • A Slack incoming webhook for regression and failure alerts.
  • The python:3.12-slim image pullable by the worker for the assess step, or swap containerImage for a process task runner if Python is on the host.

Secrets

  • GITHUB_TOKEN: token used to read the code-scanning alerts API and to open the escalation issue.
  • CODEQL_WEBHOOK_KEY: key segment guarding the webhook URL, anyone with it can trigger a gate run, so treat it as a secret.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL.

Quick start

  1. Add the three secrets above to your Kestra namespace and make sure the KV store is enabled.
  2. Set repository to the owner/repo you want gated.
  3. Point your GitHub webhook (push events or code scanning analysis) at /api/v1/{tenant}/executions/webhook/{namespace}/github-codeql-sarif-gate/CODEQL_WEBHOOK_KEY, or trigger the webhook manually. For the nightly sweep, enable the shipped Schedule trigger (cron 0 6 * * *).
  4. Run the flow once to record the starting baseline: the first run always passes and absorbs existing high or critical alerts.
  5. Introduce a new high or critical alert (or wait for one) and confirm the GitHub issue, the Slack notice, and the failed execution.

How to extend

  • Fan the gate across every repository by wrapping this flow in a parent that calls it as a subflow per owner/repo.
  • Raise alert_threshold above zero to tolerate a small burn-down window while the existing backlog is fixed.
  • Mirror regressions into your ticket system with io.kestra.plugin.jira.issues.Create next to open_issue.
  • Derive repository from the webhook payload with {{ fromJson(trigger.body).repository.full_name }} for multi-repo setups.
  • Widen the severity set in the assess script to include medium alerts, or filter to one CodeQL query by rule id.
  • Snapshot each regression list to object storage with io.kestra.plugin.aws.s3.Upload for long-term trend reporting.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.