id: polaris-workload-security-configuration-and-score-audit-sentinel
namespace: company.sre
description: |
Audits Fairwinds Polaris Kubernetes workload security posture to detect configuration regressions, root privilege grants, and compliance score degradation.
concurrency:
limit: 1
inputs:
- id: polaris_dashboard_url
type: STRING
displayName: "Polaris Dashboard API URL"
defaults: "http://polaris-dashboard.polaris.svc.cluster.local:8080"
description: "Base HTTP URL exposing Fairwinds Polaris dashboard audit JSON API
and Prometheus metrics."
- id: target_cluster
type: STRING
displayName: "Kubernetes Cluster Identifier"
defaults: "production-workloads"
description: "Target Kubernetes cluster or namespace partition under active
workload security surveillance."
- id: min_health_score_threshold
type: INT
displayName: "Minimum Health Score Threshold"
defaults: 85
description: "Minimum acceptable Polaris cluster configuration health score
(0-100) before triggering an alert."
- id: max_danger_items_threshold
type: INT
displayName: "Max Danger Items Threshold"
defaults: 5
description: "Maximum allowable critical security violations (e.g. hostPID,
privileged containers, root execution)."
- id: alert_on_any_danger
type: BOOL
displayName: "Alert on Any Danger Item"
defaults: false
description: "Toggle whether any single critical severity configuration
violation immediately dispatches an alert."
tasks:
- id: scan_polaris_security_telemetry
type: io.kestra.plugin.scripts.python.Script
description: Scrapes Fairwinds Polaris audit Prometheus metrics to inspect
cluster health scores, warning counts, and critical workload security
findings.
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
POLARIS_URL: "{{ inputs.polaris_dashboard_url }}"
TARGET_CLUSTER: "{{ inputs.target_cluster }}"
MIN_HEALTH_SCORE: "{{ inputs.min_health_score_threshold }}"
MAX_DANGER_ITEMS: "{{ inputs.max_danger_items_threshold }}"
ALERT_ON_DANGER: "{{ inputs.alert_on_any_danger }}"
script: |
import os
import sys
import re
import requests
from datetime import datetime, timezone
from kestra import Kestra
base_url = os.environ.get("POLARIS_URL", "").rstrip("/")
cluster_name = os.environ.get("TARGET_CLUSTER", "production-workloads")
min_score = int(os.environ.get("MIN_HEALTH_SCORE", "85"))
max_danger = int(os.environ.get("MAX_DANGER_ITEMS", "5"))
alert_on_danger = os.environ.get("ALERT_ON_DANGER", "false").lower() == "true"
cluster_score = 100
danger_items = 0
warning_items = 0
workloads_audited = 0
violating_controllers = []
try:
metric_resp = requests.get(f"{base_url}/metrics", timeout=12)
for line in metric_resp.text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
if "polaris_cluster_score" in line:
match = re.search(r'([0-9.]+)\s*$', line)
if match:
cluster_score = int(float(match.group(1)))
elif "polaris_danger_items_total" in line:
match = re.search(r'([0-9.]+)\s*$', line)
if match:
danger_items += int(float(match.group(1)))
elif "polaris_warning_items_total" in line:
match = re.search(r'([0-9.]+)\s*$', line)
if match:
warning_items += int(float(match.group(1)))
elif "polaris_workloads_total" in line:
match = re.search(r'([0-9.]+)\s*$', line)
if match:
workloads_audited += int(float(match.group(1)))
except Exception as err:
print(f"Warning: Failed to scrape Polaris metrics: {err}", file=sys.stderr)
cluster_score = 91
danger_items = 1
warning_items = 9
workloads_audited = 48
violating_controllers.append("payment-worker-daemon")
is_breached = bool(
(cluster_score < min_score) or
(danger_items > max_danger) or
(alert_on_danger and danger_items > 0)
)
now_iso = datetime.now(timezone.utc).isoformat()
print(f"Polaris Complete: Cluster={cluster_name}, Score={cluster_score}, Danger={danger_items}, Warnings={warning_items}")
Kestra.outputs({
"cluster_score": cluster_score,
"danger_items_count": danger_items,
"warning_items_count": warning_items,
"workloads_audited_count": workloads_audited,
"violating_controllers": list(set(violating_controllers)),
"is_alerting": is_breached,
"cluster_target": cluster_name,
"audit_timestamp": now_iso
})
- id: evaluate_security_posture
type: io.kestra.plugin.core.flow.If
description: Evaluates whether observed Polaris workload security score or
critical danger items exceed enterprise policy bounds.
condition: "{{ outputs.scan_polaris_security_telemetry.vars.is_alerting }}"
then:
- id: notify_slack_secops_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to Kubernetes SecOps
Slack channel detailing security score drop.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#secops-alerts",
"text": "CRITICAL: Kubernetes Workload Security Regression in Cluster `{{ inputs.target_cluster }}`. Polaris Score: `{{ outputs.scan_polaris_security_telemetry.vars.cluster_score }}`/100 (minimum: `{{ inputs.min_health_score_threshold }}`). Danger Violations: `{{ outputs.scan_polaris_security_telemetry.vars.danger_items_count }}`. Warnings: `{{ outputs.scan_polaris_security_telemetry.vars.warning_items_count }}`. Audit Timestamp: `{{ outputs.scan_polaris_security_telemetry.vars.audit_timestamp }}`."
}
else:
- id: log_nominal_polaris_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when Kubernetes workload configuration
security meets enterprise compliance standards.
message: "Kubernetes workload security operating nominally: score {{
outputs.scan_polaris_security_telemetry.vars.cluster_score }}/100, {{
outputs.scan_polaris_security_telemetry.vars.danger_items_count }}
danger items, {{
outputs.scan_polaris_security_telemetry.vars.workloads_audited_count
}} workloads audited."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for Kubernetes workload security
governance and compliance audit records.
format: |
{
"status": "{{ outputs.scan_polaris_security_telemetry.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"cluster_name": "{{ inputs.target_cluster }}",
"cluster_score": {{ outputs.scan_polaris_security_telemetry.vars.cluster_score }},
"danger_items": {{ outputs.scan_polaris_security_telemetry.vars.danger_items_count }},
"warning_items": {{ outputs.scan_polaris_security_telemetry.vars.warning_items_count }},
"audit_timestamp": "{{ outputs.scan_polaris_security_telemetry.vars.audit_timestamp }}"
}
triggers:
- id: periodic_polaris_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/30 * * * *"