Alert on vulnerabilities ¶
Use Nais workload metrics to alert your team when vulnerabilities exceed your chosen thresholds. Each vulnerability is counted once per workload and canonical ID, using its highest severity. Suppressed vulnerabilities are excluded.
Use max, not sum, across replicas: each replica exports counts for the same workloads.
Prerequisites ¶
- Your workload has an SBOM generated via nais/docker-build-push
- You are familiar with basic Prometheus alerting
Alert on critical vulnerabilities ¶
Create a PrometheusRule in your namespace that triggers an alert when the number of critical vulnerabilities exceeds zero.
.nais/alert-vulnerabilities.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: vulnerability-alerts
namespace: <MY-TEAM>
labels:
team: <MY-TEAM>
spec:
groups:
- name: vulnerability-alerts
rules:
- alert: CriticalVulnerability
expr: max by (environment, team, workload) (nais_workload_vulnerabilities{severity="CRITICAL", team="<MY-TEAM>"}) > 0
for: 10m
annotations:
summary: "Critical vulnerability detected in {{ $labels.workload }} ({{ $labels.environment }})"
consequence: "The workload is running with one or more critical vulnerabilities."
action: "Go to Nais Console and handle the vulnerability for {{ $labels.workload }}."
labels:
namespace: <MY-TEAM>
severity: criticalAlert on known exploitation ¶
Use nais_workload_vulnerabilities_kev to alert on vulnerabilities listed in the CISA KEV catalog .
The KEV series is absent until the catalog is loaded. An absent series does not mean zero known exploited vulnerabilities.
.nais/alert-kev-vulnerabilities.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: kev-vulnerability-alerts
namespace: <MY-TEAM>
labels:
team: <MY-TEAM>
spec:
groups:
- name: kev-vulnerability-alerts
rules:
- alert: KnownExploitedVulnerability
expr: max by (environment, team, workload) (nais_workload_vulnerabilities_kev{team="<MY-TEAM>"}) > 0
for: 10m
annotations:
summary: "Known exploited vulnerability detected in {{ $labels.workload }} ({{ $labels.environment }})"
consequence: "The workload has one or more vulnerabilities with known exploitation."
action: "Open Nais Console and handle the vulnerability for {{ $labels.workload }}."
labels:
namespace: <MY-TEAM>
severity: criticalActivate alerts ¶
Add the rule file to your application repository and deploy it with Nais GitHub Action.
Apply the rule file you created, for example:
kubectl apply -f .nais/alert-kev-vulnerabilities.yamlSend alerts to a dedicated Slack channel ¶
By default, alerts are sent to your team's standard Slack channel. If you want to send vulnerability alerts to a dedicated channel, create an AlertmanagerConfig.
See Advanced Prometheus alerting for a complete example with a custom Slack channel and webhook.
Create alerts in Grafana ¶
Alternatively, you can create alerts directly in Grafana without deploying Kubernetes resources:
- Open Grafana and go to Alerting → Alert rules
- Click New alert rule
- Select the Prometheus/Mimir data source that contains
nais_workload_*metrics and use e.g.:promqlmax by (environment, team, workload) (nais_workload_vulnerabilities_kev{team="<MY-TEAM>"}) - Set the threshold and connect to a Slack contact point
See Create alert in Grafana for a complete step-by-step guide.
Check metric coverage ¶
Check scan coverage in Nais Console before treating a missing series as a clean workload. Workloads without a scanned image have no series. Scanned workloads export all five severity values (CRITICAL, HIGH, MEDIUM, LOW, UNKNOWN), including zeros.
Metric update delay
New scans and suppressions appear in metrics at the next successful refresh, up to 5 minutes later, plus normal metrics propagation time. Alerts clear only after Prometheus collects the updated metrics. New advisories appear after the next vulnerability database update and rescan, followed by a metrics refresh.