Skip to content

Commit 7764681

Browse files
Merge pull request #1361 from stlaz/psa_alerts
Bug 2100155: Add new alert on Pod Security violations
2 parents 08973b8 + 30b9bb0 commit 7764681

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: PrometheusRule
3+
metadata:
4+
name: podsecurity
5+
namespace: openshift-kube-apiserver
6+
spec:
7+
groups:
8+
- name: pod-security-violation
9+
rules:
10+
- alert: PodSecurityViolation
11+
annotations:
12+
summary: One or more workloads users created in the cluster don't match their Pod Security profile
13+
description: >-
14+
A workload (pod, deployment, deamonset, ...) was created somewhere in the cluster but it
15+
did not match the PodSecurity "{{ $labels.policy_level }}" profile defined by its namespace either via the cluster-wide
16+
configuration (which triggers on a "restricted" profile violations) or by the namespace
17+
local Pod Security labels.
18+
Refer to Kubernetes documentation on Pod Security Admission to learn more about these
19+
violations.
20+
expr: |
21+
sum(increase(pod_security_evaluations_total{decision="deny",mode="audit"}[1d])) by (policy_level) > 0
22+
labels:
23+
namespace: openshift-kube-apiserver
24+
severity: info

pkg/operator/starter.go

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
155155
"assets/alerts/cpu-utilization.yaml",
156156
"assets/alerts/kube-apiserver-requests.yaml",
157157
"assets/alerts/kube-apiserver-slos-basic.yaml",
158+
"assets/alerts/podsecurity-violations.yaml",
158159
}
159160
infrastructure, err := configClient.ConfigV1().Infrastructures().Get(ctx, "cluster", metav1.GetOptions{})
160161
if err != nil {

pkg/test/assets_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func readAllYaml(path string, t *testing.T) {
2626
!strings.HasSuffix(info.Name(), "servicemonitor-apiserver.yaml") &&
2727
// there is an alert message containing $labels strings that cause the reader to fail.
2828
!strings.HasSuffix(info.Name(), "api-usage.yaml") &&
29+
// there is an alert message containing $labels strings that cause the reader to fail.
30+
!strings.HasSuffix(info.Name(), "podsecurity-violations.yaml") &&
2931
// the kas's pod manifest contains go template values and fails compilation
3032
!strings.HasSuffix(info.Name(), "pod.yaml")
3133

0 commit comments

Comments
 (0)