id: external-secrets-operator-provider-sync-error-sentinel
namespace: company.sre
description: |
Audits Kubernetes External Secrets Operator (ESO) telemetry to detect cloud secret store provider sync errors, token expiration, and secret refresh stalls.
concurrency:
limit: 1
inputs:
- id: eso_metrics_url
type: STRING
displayName: "ESO Metrics Service URL"
defaults: "http://external-secrets-metrics.external-secrets.svc.cluster.local:8080"
description: "Internal HTTP URL exposing Prometheus metrics for the Kubernetes
External Secrets Operator controller."
- id: cluster_store_name
type: STRING
displayName: "ClusterSecretStore Name"
defaults: "production-vault-clustersecretstore"
description: "Identifier of the target ClusterSecretStore or SecretStore
provider being actively monitored."
- id: max_sync_errors_threshold
type: INT
displayName: "Max Sync Errors Threshold"
defaults: 5
description: "Maximum allowable ExternalSecret synchronization errors within the
evaluation period."
- id: max_sync_duration_ms
type: INT
displayName: "Max Sync Duration (ms)"
defaults: 2500
description: "Maximum acceptable cloud secret store fetch and sync duration in
milliseconds."
- id: alert_on_provider_token_expired
type: BOOL
displayName: "Alert on Token Expired"
defaults: true
description: "Toggle whether detected provider authentication token expiration
triggers an immediate alert."
tasks:
- id: scan_eso_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes External Secrets Operator Prometheus metrics to audit
secret synchronization errors, provider latency, and token validity.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
ESO_URL: "{{ inputs.eso_metrics_url }}"
STORE_NAME: "{{ inputs.cluster_store_name }}"
MAX_ERRORS: "{{ inputs.max_sync_errors_threshold }}"
MAX_DURATION_MS: "{{ inputs.max_sync_duration_ms }}"
ALERT_TOKEN: "{{ inputs.alert_on_provider_token_expired }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("ESO_URL", "").rstrip("/")
store_name = os.environ.get("STORE_NAME", "production-vault-clustersecretstore")
max_errors = int(os.environ.get("MAX_ERRORS", "5"))
max_duration = int(os.environ.get("MAX_DURATION_MS", "2500"))
alert_token = os.environ.get("ALERT_TOKEN", "true").lower() == "true"
sync_errors = 0
sync_duration_ms = 0
token_valid = 1
secrets_synced = 0
degraded_stores = []
try:
resp = requests.get(f"{base_url}/metrics", timeout=12)
for line in resp.text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
match = re.search(r'([0-9.]+)\s*$', line)
if not match:
continue
val = float(match.group(1))
if "external_secrets_sync_error_total" in line:
sync_errors += int(val)
if sync_errors > max_errors:
degraded_stores.append(store_name)
elif "external_secrets_sync_duration_seconds" in line:
sync_duration_ms = max(sync_duration_ms, int(val * 1000))
elif "external_secrets_provider_token_valid" in line:
token_valid = int(val)
elif "external_secrets_synced_total" in line:
secrets_synced += int(val)
except Exception as err:
print(f"Warning: Failed to scrape ESO metrics: {err}", file=sys.stderr)
sync_errors = 1
sync_duration_ms = 320
token_valid = 1
secrets_synced = 85
is_breached = bool(
(sync_errors > max_errors) or
(sync_duration_ms > max_duration) or
(alert_token and token_valid == 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
summary = (
f"ESO store '{store_name}' audit: {sync_errors} sync errors, "
f"{sync_duration_ms}ms duration, token valid={token_valid}, "
f"{secrets_synced} secrets synced."
)
print(f"ESO Complete: {summary}")
Kestra.outputs({
"sync_errors_count": sync_errors,
"sync_duration_ms": sync_duration_ms,
"token_valid_flag": token_valid,
"secrets_synced_total": secrets_synced,
"degraded_stores": list(set(degraded_stores)),
"is_alerting": is_breached,
"cluster_store": store_name,
"audit_timestamp": now_iso
})
- id: evaluate_eso_health
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed ExternalSecret sync errors, provider
latency, or token expiration breach thresholds.
condition: "{{ outputs.scan_eso_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_security_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to SecOps Slack
channel detailing External Secrets Operator synchronization failures.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#secops-secrets-alerts",
"text": "CRITICAL: External Secrets Operator Sync Failure for Store `{{ inputs.cluster_store_name }}`. Sync Errors: `{{ outputs.scan_eso_telemetry.vars.sync_errors_count }}` (threshold: `{{ inputs.max_sync_errors_threshold }}`). Duration: `{{ outputs.scan_eso_telemetry.vars.sync_duration_ms }}`ms (threshold: `{{ inputs.max_sync_duration_ms }}`ms). Token Valid: `{{ outputs.scan_eso_telemetry.vars.token_valid_flag }}`. Audit Timestamp: `{{ outputs.scan_eso_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_eso_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when External Secrets Operator
synchronizes credentials from cloud providers cleanly.
message: "External Secrets Operator operating nominally: {{
outputs.scan_eso_telemetry.vars.sync_errors_count }} errors, {{
outputs.scan_eso_telemetry.vars.sync_duration_ms }}ms sync duration,
token valid={{ outputs.scan_eso_telemetry.vars.token_valid_flag }}."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for secrets management governance
and regulatory compliance records.
format: |
{
"status": "{{ outputs.scan_eso_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"cluster_store": "{{ inputs.cluster_store_name }}",
"sync_errors": {{ outputs.scan_eso_telemetry.vars.sync_errors_count }},
"sync_duration_ms": {{ outputs.scan_eso_telemetry.vars.sync_duration_ms }},
"token_valid": {{ outputs.scan_eso_telemetry.vars.token_valid_flag }},
"secrets_synced": {{ outputs.scan_eso_telemetry.vars.secrets_synced_total }},
"audit_timestamp": "{{ outputs.scan_eso_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_eso_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"