Schedule icon
Webhook icon
Script icon
If icon
PushFlows icon
Create icon
SlackIncomingWebhook icon
Log icon
Fail icon

Kestra Namespace Governance Drift Guard with Auto PR

Scan Kestra namespaces against label, id, and description policy; open a governance pull request and Slack alert when drift appears.

Categories
Infrastructure

How it works

  1. weekly_governance_scan (Schedule, shipped disabled) or on_demand_scan (event-based Webhook) starts the sweep.
  2. scan_and_evaluate (scripts.python.Script, Python standard library only) pages GET /api/v1/main/flows/search with basic auth (KESTRA_USERNAME/KESTRA_PASSWORD) filtered by filters[namespace][STARTS_WITH], then evaluates each flow: a description must exist when require_description is set, the flow id must match id_pattern, and every label in required_labels must be present. Label handling accepts both map-shaped and {key, value} list-shaped API responses, and a malformed regex in the policy is reported as a violation rather than crashing the scan. Results return through Kestra's ::json:: outputs protocol as violations, counts, and a report_markdown table.
  3. drift_gate (core.flow.If) branches only when violations exist: export_namespace (git.PushFlows, shape from github-push-and-create-pr) writes every flow in the namespace to the branch input with a commit message naming the execution and violation count, then open_pull_request (github.pulls.Create) opens a PR from that branch to main whose body is the violations table, and announce_drift posts the summary plus {{ outputs.open_pull_request.pullRequestUrl }} to Slack via messageText. Clean scans take the else branch and just log.
  4. fail_gate (second core.flow.If) turns drift into a red execution via core.execution.Fail when fail_on_violations is true - after the PR is already filed, so the alert and the ticket exist before the run goes red.
  5. Outputs expose violation_count, checked_count, violations, report_markdown, and pull_request_url (with an is defined guard falling back to no-drift); errors posts to Slack with wording that reminds readers an errored scan is not a clean scan.

What you get

  • Convention drift (missing labels, id naming, empty descriptions) surfaced on a schedule instead of at audit time.
  • A pull request that carries the exact violations table, so fixing drift is normal review work in Git.
  • A red execution when violations exist, wiring governance into the same failure channels as everything else.
  • A policy that lives as a flow input - change required labels without touching code.

Who it's for

Platform teams operating Kestra for many squads who need guardrails at the namespace level, and anyone preparing for audits who wants evidence that conventions were checked weekly.

Why orchestrate this with Kestra

The alternative is a cron job that greps YAML in the Git mirror - which nobody notices when it breaks, and which cannot open a PR by itself. Kestra gives the scan durable credentials, a reviewable Git and GitHub trail, a human-readable Slack message, and a failure state that pages like any other workflow.

Prerequisites

  • A reachable Kestra API with basic-auth credentials for a user that can list flows.
  • A GitHub repository receiving the export plus a token with push and pull-request rights.
  • A Slack incoming webhook.
  • The policy input tuned to your conventions (required_labels, id_pattern, require_description).

Secrets

  • KESTRA_USERNAME: Kestra API username for the flows search endpoint.
  • KESTRA_PASSWORD: matching password.
  • GITHUB_USERNAME: Git username for PushFlows authentication.
  • GITHUB_ACCESS_TOKEN: GitHub token with contents write and pull-request create.
  • SLACK_WEBHOOK_URL: Slack incoming webhook for drift and failure alerts.

Quick start

  1. Set the five secrets in your Kestra namespace.
  2. Point namespace_prefix at the namespace to govern and repository/pr_repository at the Git mirror.
  3. Run with on_demand_scan and read violations plus report_markdown in the outputs.
  4. Confirm the branch export, the pull request, and the Slack message; merge or close as you would any PR.
  5. Enable weekly_governance_scan and keep fail_on_violations: true so drift shows up in your schedule's failure alerts.

How to extend

  • Add rules to evaluate - forbidden task types, missing errors blocks, or secrets referenced outside secret().
  • Auto-apply safe fixes before export: rewrite labels in the flow definitions via the Kestra API, then PushFlows so the PR contains real fixes, not just a report.
  • Fan violations out per owning team with a Subflow and Slack mentions.
  • Feed report_markdown into a quarterly evidence pack stored in S3.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.