id: ai-agent-config-change-watchdog
namespace: company.team
labels:
team: security
use-case: ai-agent-config-change-watchdog
description: |
Watch the files that define what an AI agent may do, and flag changes that
nobody approved. Every day this flow reads the real commit history of a
configured GitHub repository through the GitHub API, picks out commits that
touch agent configuration (system prompts, agent definitions, tool
allowlists and MCP server configuration), and checks each one against an
approved author list. A change by an unapproved author to a tool allowlist
or an MCP server file is the highest risk finding; prompt changes rank
next, then other agent configuration. Flagged changes are recorded as one
evidence record per run, posted to Slack, and fail the execution when the
fail-closed inputs say so, so an unapproved agent change is never a green
run that nobody noticed.
triggers:
- id: daily_config_watch
type: io.kestra.plugin.core.trigger.Schedule
description: Daily sweep of the configured repository for agent configuration
changes in the lookback window. Shipped disabled. Enable it only after
pointing the repository input at your own agent repository, setting a
GitHub token, and setting an approved author list, then verifying a manual
run.
cron: "0 6 * * *"
disabled: true
inputs:
- id: repository
type: STRING
defaults: example-org/example-agent-repo
description: GitHub repository to watch, in owner/repo form. Placeholder only,
set this to your own agent repository before running. The flow ships with
no real repository configured.
validator: ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$
- id: branch
type: STRING
defaults: main
description: Branch whose commit history is scanned.
- id: lookback_days
type: INT
defaults: 1
description: How many days back the scan reaches. One day matches the daily
schedule; raise it after a missed run to cover the gap.
- id: watched_path_prefixes
type: ARRAY
itemType: STRING
defaults:
- prompts/
- agents/
- system-prompts/
- .cursor/
- mcp
- tools/allowlist
description: File path prefixes that count as agent configuration. A commit is
only examined when it touches at least one path starting with one of these
prefixes.
- id: approved_authors
type: ARRAY
itemType: STRING
defaults: []
description: GitHub logins allowed to change agent configuration without
flagging. Matching is on the GitHub login only, because a commit author
name can be set to anything, so a name never approves a change, and a
commit with no linked GitHub login is never pre-approved. Empty means
nobody is pre-approved, so every agent configuration change in the window
is flagged until an author list is set.
- id: fail_on_unapproved
type: BOOL
defaults: true
description: When true, any flagged change fails the execution. Set it to false
while triaging a noisy repository, so flagged changes alert without
failing the run.
- id: fail_on_inconclusive
type: BOOL
defaults: true
description: When true, a scan that cannot read the repository (network or auth
error) or cannot read a commit detail fails the execution instead of
passing quietly. The watchdog must not report a clean bill of health for a
repository it could not read.
tasks:
- id: scan_repo_history
type: io.kestra.plugin.scripts.python.Script
description: Read the real commit history of the configured repository from the
GitHub API, classify every touched agent configuration file, and emit one
evidence record per flagged commit. Nothing in this task is sample data.
The commits, authors, files and messages all come from the live repository
in the lookback window, and an empty window yields a clean PASS with zero
commits checked. The scan requires a GitHub token. With no token it fails
closed instead of reading the repository unauthenticated.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: python:3.12-slim
env:
REPOSITORY: "{{ inputs.repository }}"
BRANCH: "{{ inputs.branch }}"
LOOKBACK_DAYS: "{{ inputs.lookback_days }}"
WATCHED_PREFIXES_JSON: "{{ inputs.watched_path_prefixes | toJson }}"
APPROVED_AUTHORS_JSON: "{{ inputs.approved_authors | toJson }}"
FAIL_ON_UNAPPROVED: "{{ inputs.fail_on_unapproved }}"
FAIL_ON_INCONCLUSIVE: "{{ inputs.fail_on_inconclusive }}"
GITHUB_TOKEN: "{{ secret('GITHUB_TOKEN') }}"
script: |
import json
import os
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime, timedelta, timezone
def http_get(url, token):
headers = {
"Accept": "application/vnd.github+json",
"User-Agent": "kestra-ai-agent-config-change-watchdog",
}
if token:
headers["Authorization"] = "Bearer " + token
request = urllib.request.Request(url, method="GET", headers=headers)
try:
with urllib.request.urlopen(request, timeout=30) as response:
return response.status, response.read().decode("utf-8", "replace"), None
except urllib.error.HTTPError as err:
return err.code, err.read().decode("utf-8", "replace"), None
except Exception as err: # noqa: BLE001 - any transport failure is inconclusive
return None, "", str(err)
def classify(path):
lowered = path.lower()
if "mcp" in lowered or "allowlist" in lowered or "allowed-tools" in lowered:
return "tool-surface", 90
if "prompt" in lowered or "instructions" in lowered:
return "prompt", 70
if lowered.endswith((".yaml", ".yml", ".json", ".toml")) and (
"agent" in lowered or "config" in lowered
):
return "config", 50
return "watched-other", 30
def is_watched(path, prefixes):
return any(path.startswith(prefix) for prefix in prefixes)
def main():
repo = os.environ.get("REPOSITORY", "")
branch = os.environ.get("BRANCH", "main")
lookback = int(os.environ.get("LOOKBACK_DAYS", "1"))
prefixes = json.loads(os.environ.get("WATCHED_PREFIXES_JSON", "[]"))
approved = set(json.loads(os.environ.get("APPROVED_AUTHORS_JSON", "[]")))
fail_on_unapproved = os.environ.get("FAIL_ON_UNAPPROVED", "true") == "true"
fail_on_inconclusive = os.environ.get("FAIL_ON_INCONCLUSIVE", "true") == "true"
token = os.environ.get("GITHUB_TOKEN", "")
if not token:
evidence = [{"error": "GITHUB_TOKEN is not set: the scan requires a token and refuses to read the repository unauthenticated"}]
verdict = "BLOCKED" if fail_on_inconclusive else "REVIEW"
print("::" + json.dumps({"outputs": {
"verdict": verdict,
"flagged_count": 0,
"high_risk_count": 0,
"commits_checked": 0,
"inconclusive_count": 1,
"evidence": evidence,
}}) + "::")
return
since = (datetime.now(timezone.utc) - timedelta(days=lookback)).strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
list_url = (
"https://api.github.com/repos/%s/commits?sha=%s&since=%s&per_page=100"
% (repo, urllib.parse.quote(branch), urllib.parse.quote(since))
)
status, body, error = http_get(list_url, token)
if status != 200:
detail = error or body[:300]
evidence = [{"error": "could not list commits: %s" % detail}]
verdict = "BLOCKED" if fail_on_inconclusive else "REVIEW"
print("::" + json.dumps({"outputs": {
"verdict": verdict,
"flagged_count": 0,
"high_risk_count": 0,
"commits_checked": 0,
"inconclusive_count": 1,
"evidence": evidence,
}}) + "::")
return
commits = json.loads(body)
if not isinstance(commits, list):
commits = []
checked = 0
flagged = []
inconclusive_items = []
truncated = len(commits) >= 100
for commit in commits[:50]:
checked += 1
sha = commit.get("sha", "")[:12]
author_login = (commit.get("author") or {}).get("login")
author_name = ((commit.get("commit") or {}).get("author") or {}).get("name", "")
author = author_login or author_name
message = ((commit.get("commit") or {}).get("message") or "").split("\n")[0]
detail_url = commit.get("url", "")
detail_status, detail_body, detail_error = http_get(detail_url, token)
if detail_status != 200:
inconclusive_items.append({
"sha": sha,
"author": author,
"message": message,
"files": [],
"change_class": "unreadable",
"risk": 0,
"reason": "commit detail could not be read: %s" % (
detail_error or detail_body[:200]
),
})
continue
detail = json.loads(detail_body)
files = detail.get("files", []) if isinstance(detail, dict) else []
watched = []
best_class = None
best_risk = 0
for entry in files:
path = entry.get("filename", "")
if not is_watched(path, prefixes):
continue
change_class, risk = classify(path)
watched.append({
"path": path,
"status": entry.get("status", ""),
"change_class": change_class,
"risk": risk,
})
if risk > best_risk:
best_risk = risk
best_class = change_class
if not watched:
continue
if author_login and author_login in approved:
continue
flagged.append({
"sha": sha,
"author": author,
"message": message,
"files": watched,
"change_class": best_class,
"risk": best_risk,
"reason": "agent configuration changed by an unapproved author",
})
flagged_count = len(flagged)
high_risk = len([item for item in flagged if item.get("risk", 0) >= 70])
inconclusive = len(inconclusive_items)
if flagged_count > 0:
verdict = "BLOCKED" if fail_on_unapproved else "REVIEW"
elif inconclusive > 0:
verdict = "BLOCKED" if fail_on_inconclusive else "REVIEW"
else:
verdict = "PASS"
evidence = flagged + inconclusive_items
if truncated:
evidence = evidence + [{
"note": "commit list hit the 100 item page limit; raise lookback handling or narrow the window if runs truncate often",
}]
print("repo=%s verdict=%s checked=%d flagged=%d high_risk=%d inconclusive=%d" % (
repo, verdict, checked, flagged_count, high_risk, inconclusive))
print("::" + json.dumps({"outputs": {
"verdict": verdict,
"flagged_count": flagged_count,
"high_risk_count": high_risk,
"commits_checked": checked,
"inconclusive_count": inconclusive,
"evidence": evidence,
}}) + "::")
main()
- id: alert_on_flagged
type: io.kestra.plugin.core.flow.If
description: Alert the security channel whenever the watchdog does not pass,
naming the verdict, the flagged count and the full evidence record, so an
unapproved agent change is visible instead of silent. When nothing is
flagged, record the clean result in the execution log.
condition: "{{ outputs.scan_repo_history.vars.verdict != 'PASS' }}"
then:
- id: alert_security
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Tell the security channel about the flagged agent configuration
changes, with the verdict, the flagged and high risk counts, and the
per-commit evidence record.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "AI agent config watchdog {{ outputs.scan_repo_history.vars.verdict }} for {{ inputs.repository }} ({{ inputs.branch }}): {{ outputs.scan_repo_history.vars.commits_checked }} commits checked, {{ outputs.scan_repo_history.vars.flagged_count }} flagged, {{ outputs.scan_repo_history.vars.high_risk_count }} high risk, {{ outputs.scan_repo_history.vars.inconclusive_count }} inconclusive. Evidence: {{ outputs.scan_repo_history.vars.evidence | toJson }}. Execution {{ execution.id }}. Review every flagged commit before trusting the agent configuration."
}
- id: fail_when_blocked
type: io.kestra.plugin.core.flow.If
description: Fail the execution when the verdict is BLOCKED, so an unapproved
agent change can never read as a passing run. A REVIEW verdict only
alerts, by operator choice.
condition: "{{ outputs.scan_repo_history.vars.verdict == 'BLOCKED' }}"
then:
- id: fail_watchdog
type: io.kestra.plugin.core.execution.Fail
description: Fail the execution so a blocked agent configuration change is never
signed off by a green run.
errorMessage: "AI agent config watchdog BLOCKED for {{ inputs.repository }}: {{
outputs.scan_repo_history.vars.flagged_count }} flagged change(s),
{{ outputs.scan_repo_history.vars.high_risk_count }} high risk.
See the Slack alert and the evidence record. Clearance requires an
approved author or a reviewed change."
else:
- id: log_watchdog_clear
type: io.kestra.plugin.core.log.Log
description: Record the clean result so the execution history proves the
repository was actually scanned and nothing was flagged.
message: "AI agent config watchdog clear for {{ inputs.repository }} ({{
inputs.branch }}): verdict {{ outputs.scan_repo_history.vars.verdict
}}, {{ outputs.scan_repo_history.vars.commits_checked }} commits
checked, 0 flagged, evidence {{
outputs.scan_repo_history.vars.evidence | toJson }}."
errors:
- id: notify_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Escalate any failure of the watchdog itself to the security
channel, because a watchdog that dies silently looks exactly like a clean
repository.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "FAILED: AI agent config watchdog {{ flow.id }} execution {{ execution.id }} for {{ inputs.repository }}. The watchdog did not complete, so agent configuration stays unreviewed until it is re-run."
}
outputs:
- id: verdict
type: STRING
description: PASS when no agent configuration change by an unapproved author was
found, REVIEW when flagged changes or unreadable commits exist but the
fail-closed inputs are off, BLOCKED when flagged changes or unreadable
commits exist and the matching fail-closed input is on.
value: "{{ outputs.scan_repo_history.vars.verdict }}"
- id: flagged_count
type: INT
description: Number of commits in the window that changed agent configuration as
an unapproved author. Clearance requires zero, or a reviewed change.
value: "{{ outputs.scan_repo_history.vars.flagged_count }}"