id: break-glass-privileged-account-use-watchdog
namespace: company.team
description: |
Watch break-glass privileged accounts for use without a matching approval record. The flow
takes a list of break-glass accounts, a JSON array of audit events, and a JSON array of
approval records, then classifies every break-glass use as approved or unapproved. A use
counts as approved only when an approval record names the same account and its validity
window covers the event time. Anything else (no record, an expired window, a window that
has not started yet, or an event that cannot be attributed to an account) counts as
unapproved, and the flow alerts Slack and fails. The bundled demo data shows one approved
use, one use with no approval, and one use outside its approval window, so a first run
exercises the alert path end to end. In production the flow fetches the audit events and the
approval records from real feed URLs on each run instead of taking them as pasted JSON, opens a
GitHub incident naming who used which account and when, and pauses for a reviewer to confirm the
use was expected; only a reviewer confirmation lets the run complete, otherwise it fails.
What it does: it turns break-glass use into a classified verdict, so unapproved privileged use is
an incident with a reviewer decision, not a log line nobody reads. Prerequisites: a list of
break-glass accounts, audit events and approval records (pasted JSON for a first run, real feed
URLs in production), plus namespace secrets for the Slack channel and the GitHub incident
repository. How it works: the daily schedule fetches the real feeds, classifies every break-glass
use against its approval window, and on unapproved use alerts Slack, opens a GitHub incident, and
pauses for reviewer confirmation, failing the run unless the reviewer confirms. How to adapt it:
point the feed URLs at your audit and approval exports, set the account list per environment, and
archive the unapproved details for your audit history.
triggers:
- id: daily_break_glass_watch
type: io.kestra.plugin.core.trigger.Schedule
description: "Daily 08:00 UTC check. Shipped disabled; enable it once
audit_events_json and approvals_json point at real audit and approval
feeds and a manual run has been verified."
cron: "0 8 * * *"
disabled: true
inputs:
- id: break_glass_accounts
type: STRING
displayName: "Break-Glass Accounts"
defaults: "bg-admin,bg-root"
description: Comma-separated list of break-glass privileged account names.
Matching is exact after trimming whitespace.
- id: audit_events_json
type: STRING
displayName: "Audit Events JSON"
defaults: |
[
{"account": "bg-admin", "timestamp": "2026-10-20T09:15:00Z", "action": "console-login"},
{"account": "bg-admin", "timestamp": "2026-10-20T14:30:00Z", "action": "policy-change"},
{"account": "bg-root", "timestamp": "2026-10-21T02:05:00Z", "action": "console-login"},
{"account": "alice", "timestamp": "2026-10-20T10:00:00Z", "action": "console-login"}
]
description: JSON array of audit events. Each event needs an account, an ISO
8601 timestamp, and an action. Events for accounts outside the break-glass
list are ignored.
- id: approvals_json
type: STRING
displayName: "Approvals JSON"
defaults: |
[
{"account": "bg-admin", "valid_from": "2026-10-20T09:00:00Z", "valid_until": "2026-10-20T10:00:00Z", "ticket": "CHG-1042", "approver": "sec-lead"},
{"account": "bg-root", "valid_from": "2026-10-19T00:00:00Z", "valid_until": "2026-10-19T23:59:59Z", "ticket": "CHG-1031", "approver": "sec-lead"}
]
description: JSON array of approval records. Each record needs an account, a
valid_from timestamp, and a valid_until timestamp. Ticket and approver are
recorded in the verdict for traceability.
- id: audit_events_url
type: STRING
displayName: "Audit Events URL"
defaults: ''
description: URL of a JSON audit feed export (cloud audit log export or identity
provider audit export) fetched on every run. Empty keeps the
audit_events_json input path, which is for demos and first runs only.
- id: approvals_url
type: STRING
displayName: "Approvals URL"
defaults: ''
description: URL of a JSON approval records export fetched on every run. Empty
keeps the approvals_json input path, which is for demos and first runs
only.
- id: github_repository
type: STRING
displayName: "GitHub Repository"
defaults: acme/platform-security
description: Repository that receives the tracking incident issue when
unapproved break-glass use is found.
tasks:
- id: fetch_real_feeds
type: io.kestra.plugin.scripts.python.Script
description: Fetch the audit events and approval records from their real feed
URLs when those inputs are set, otherwise pass the JSON inputs through
unchanged. A set URL that cannot be fetched fails the task, so a broken
feed can never silently fall back to demo data.
taskRunner:
type: io.kestra.plugin.core.runner.Process
env:
AUDIT_EVENTS_URL: '{{ inputs.audit_events_url }}'
APPROVALS_URL: '{{ inputs.approvals_url }}'
AUDIT_EVENTS_JSON: '{{ inputs.audit_events_json }}'
APPROVALS_JSON: '{{ inputs.approvals_json }}'
script: |
import json
import os
import urllib.error
import urllib.request
from kestra import Kestra
def fetch_or_passthrough(url, fallback):
url = (url or "").strip()
if not url:
return fallback
request = urllib.request.Request(url, method="GET")
try:
with urllib.request.urlopen(request, timeout=30) as response:
body = response.read().decode("utf-8")
status = response.status
except urllib.error.HTTPError as err:
raise RuntimeError(f"feed fetch failed for {url}: HTTP {err.code}") from err
except Exception as err:
raise RuntimeError(f"feed fetch failed for {url}: {err}") from err
if status != 200:
raise RuntimeError(f"feed fetch failed for {url}: HTTP {status}")
json.loads(body)
return body
audit_events = fetch_or_passthrough(
os.environ.get("AUDIT_EVENTS_URL", ""),
os.environ.get("AUDIT_EVENTS_JSON", "[]"),
)
approvals = fetch_or_passthrough(
os.environ.get("APPROVALS_URL", ""),
os.environ.get("APPROVALS_JSON", "[]"),
)
Kestra.outputs({
"audit_events_json": audit_events,
"approvals_json": approvals,
"audit_source": "url" if os.environ.get("AUDIT_EVENTS_URL", "").strip() else "input",
"approvals_source": "url" if os.environ.get("APPROVALS_URL", "").strip() else "input",
})
- id: evaluate_break_glass_use
type: io.kestra.plugin.scripts.python.Script
description: Classifies every break-glass use in the audit events against the
approval records. Approved requires an exact account match plus an event
time inside the approval window. Unapproved covers no record, an expired
window, a window not yet started, and events that cannot be attributed to
an account. Emits total_uses, approved_uses, unapproved_uses, and
unapproved_details through Kestra.outputs.
taskRunner:
type: io.kestra.plugin.core.runner.Process
env:
BREAK_GLASS_ACCOUNTS: "{{ inputs.break_glass_accounts }}"
AUDIT_EVENTS_JSON: "{{ outputs.fetch_real_feeds.vars.audit_events_json }}"
APPROVALS_JSON: "{{ outputs.fetch_real_feeds.vars.approvals_json }}"
script: |
import json
import os
from datetime import datetime, timezone
from kestra import Kestra
def parse_time(value):
if not isinstance(value, str):
return None
text = value.strip()
if not text:
return None
if text.endswith("Z"):
text = text[:-1] + "+00:00"
try:
parsed = datetime.fromisoformat(text)
except ValueError:
return None
if parsed.tzinfo is None:
parsed = parsed.replace(tzinfo=timezone.utc)
return parsed
accounts = {a.strip() for a in os.environ.get("BREAK_GLASS_ACCOUNTS", "").split(",") if a.strip()}
try:
events = json.loads(os.environ.get("AUDIT_EVENTS_JSON", "[]"))
except json.JSONDecodeError:
events = []
try:
approvals = json.loads(os.environ.get("APPROVALS_JSON", "[]"))
except json.JSONDecodeError:
approvals = []
if not isinstance(events, list):
events = []
if not isinstance(approvals, list):
approvals = []
approved = []
unapproved = []
for event in events:
if not isinstance(event, dict):
unapproved.append({"event": event, "reason": "malformed event, not an object"})
continue
account = event.get("account")
timestamp = event.get("timestamp")
action = event.get("action")
if not isinstance(account, str) or not account.strip():
unapproved.append({"event": event, "reason": "unattributable event, no account"})
continue
account = account.strip()
if account not in accounts:
continue
event_time = parse_time(timestamp)
if event_time is None:
unapproved.append({"account": account, "timestamp": timestamp, "action": action, "reason": "unparseable timestamp, cannot prove approval"})
continue
matching = [a for a in approvals if isinstance(a, dict) and a.get("account") == account]
covering = None
for record in matching:
start = parse_time(record.get("valid_from"))
end = parse_time(record.get("valid_until"))
if start is not None and end is not None and start <= event_time <= end:
covering = record
break
if covering is not None:
approved.append({"account": account, "timestamp": timestamp, "action": action, "ticket": covering.get("ticket"), "approver": covering.get("approver")})
continue
if not matching:
reason = "no approval record for this account"
elif any(parse_time(r.get("valid_until")) is not None and event_time > parse_time(r.get("valid_until")) for r in matching):
reason = "approval window expired before this use"
elif any(parse_time(r.get("valid_from")) is not None and event_time < parse_time(r.get("valid_from")) for r in matching):
reason = "approval window had not started at this use"
else:
reason = "no approval record covers this use"
unapproved.append({"account": account, "timestamp": timestamp, "action": action, "reason": reason})
verdict = "ALERT" if unapproved else "CLEAN"
Kestra.outputs({
"total_uses": len(approved) + len(unapproved),
"approved_uses": len(approved),
"unapproved_uses": len(unapproved),
"unapproved_details": unapproved,
"verdict": verdict,
})
- id: alert_on_unapproved_use
type: io.kestra.plugin.core.flow.If
description: Alerts Slack and fails the execution when any break-glass use lacks
a covering approval. A clean run only logs the verdict.
condition: "{{ outputs.evaluate_break_glass_use.vars.unapproved_uses > 0 }}"
then:
- id: alert_security_channel
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Pages the security channel with the unapproved break-glass use
count and details, so an unapproved privileged use is visible
immediately.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "ALERT: {{ outputs.evaluate_break_glass_use.vars.unapproved_uses }} unapproved break-glass privileged account use(s) out of {{ outputs.evaluate_break_glass_use.vars.total_uses }} total (verdict {{ outputs.evaluate_break_glass_use.vars.verdict }}, execution {{ execution.id }}). Details: {{ outputs.evaluate_break_glass_use.vars.unapproved_details | toJson }}. Treat as unauthorized privileged access until an approver confirms otherwise."
}
- id: open_incident
type: io.kestra.plugin.github.issues.Create
description: Open one incident issue naming who used which break-glass account
and when, with the action and the reason each use is unapproved, so
the incident is tracked work and not just a chat alert.
jwtToken: "{{ secret('GITHUB_TOKEN') }}"
repository: "{{ inputs.github_repository }}"
title: "Unapproved break-glass use: {{
outputs.evaluate_break_glass_use.vars.unapproved_uses }} use(s)
(execution {{ execution.id }})"
labels:
- security-incident
- break-glass
body: |
## Unapproved break-glass privileged account use
The watchdog found **{{ outputs.evaluate_break_glass_use.vars.unapproved_uses }}** unapproved use(s) out of **{{ outputs.evaluate_break_glass_use.vars.total_uses }}** total break-glass uses (execution {{ execution.id }}).
Unapproved uses (account, timestamp, action, reason):
{{ outputs.evaluate_break_glass_use.vars.unapproved_details | toJson }}
A reviewer must confirm whether each use was expected. Until then, treat every use above as unauthorized privileged access.
- id: pause_for_reviewer_confirmation
type: io.kestra.plugin.core.flow.Pause
description: Pause for a reviewer to confirm the unapproved use was expected.
The reviewer answers from the incident issue, and only a confirmation
lets the run complete, anything else fails it.
timeout: PT24H
onResume:
- id: confirmed_expected
type: BOOL
description: Confirm the unapproved break-glass use was expected and approved
out of band.
defaults: false
- id: reviewer_notes
type: STRING
description: Reviewer notes on why the use was expected, or why it was not.
defaults: ''
- id: confirm_or_fail
type: io.kestra.plugin.core.flow.If
description: Complete the run only when the reviewer confirmed the use was
expected; otherwise fail it, so unapproved use never reads as a pass.
condition: "{{
outputs.pause_for_reviewer_confirmation.onResume.confirmed_expected ==
true }}"
then:
- id: log_reviewer_confirmed
type: io.kestra.plugin.core.log.Log
description: Record that a reviewer confirmed the unapproved use was expected.
The incident issue stays open as the audit record.
message: "Break-glass watchdog: reviewer confirmed the unapproved use was
expected. Notes: {{
outputs.pause_for_reviewer_confirmation.onResume.reviewer_notes
}}. Incident issue remains open as the audit record."
else:
- id: fail_on_unapproved_use
type: io.kestra.plugin.core.execution.Fail
description: Fails the execution so an unapproved break-glass use can never read
as a passing check.
errorMessage: "Unapproved break-glass privileged account use detected. See the
Slack alert, the incident issue, and unapproved_details output."
else:
- id: log_clean_verdict
type: io.kestra.plugin.core.log.Log
description: Records a clean run when every break-glass use had a covering approval.
message: "Break-glass watchdog verdict CLEAN: {{
outputs.evaluate_break_glass_use.vars.total_uses }} use(s), all
approved."
- id: log_watchdog_complete
type: io.kestra.plugin.core.log.Log
description: Runs last on clean runs and on reviewer-confirmed runs, printing
the headline counts. It does not run when the execution fails on
unconfirmed unapproved use, by design.
message: "Break-glass watchdog complete. Total uses: {{
outputs.evaluate_break_glass_use.vars.total_uses }}, approved: {{
outputs.evaluate_break_glass_use.vars.approved_uses }}, unapproved: {{
outputs.evaluate_break_glass_use.vars.unapproved_uses }}, verdict: {{
outputs.evaluate_break_glass_use.vars.verdict }}."
errors:
- id: alert_watchdog_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alerts Slack if the watchdog itself fails, so a broken check never
reads as no unapproved use.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Break-glass privileged account watchdog FAILED (flow {{ flow.id }}, execution {{ execution.id }}). The check did not complete, so unapproved use cannot be ruled out. Investigate before trusting the last verdict."
}