Skip to content

Commit faf2954

Browse files
author
Christian Stark
committed
added placement tolerations
Signed-off-by: Christian Stark <cstark@cstark-thinkpadx1carbongen11.muc.csb>
1 parent e38c610 commit faf2954

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
object-templates-raw: |
3+
{{/* ## Gather all Placements from the hub cluster ## */}}
4+
{{- $unreachableToleration := "cluster.open-cluster-management.io/unreachable" }}
5+
{{- $unavailableToleration := "cluster.open-cluster-management.io/unavailable" }}
6+
7+
{{- range $pt := (lookup "cluster.open-cluster-management.io/v1beta1" "Placement" "" "").items }}
8+
{{- $hasUnreachable := false }}
9+
{{- $hasUnavailable := false }}
10+
11+
- complianceType: musthave
12+
objectDefinition:
13+
apiVersion: cluster.open-cluster-management.io/v1beta1
14+
kind: Placement
15+
metadata:
16+
name: {{ $pt.metadata.name }}
17+
namespace: {{ $pt.metadata.namespace }}
18+
spec:
19+
tolerations:
20+
{{- range $t := $pt.spec.tolerations }}
21+
{{/* ## check if the toleration is unavailable or unreachable ## */}}
22+
{{- if eq $t.key $unreachableToleration }}
23+
{{- $hasUnreachable = true }}
24+
{{- else if eq $t.key $unavailableToleration }}
25+
{{- $hasUnavailable = true }}
26+
{{- end }}
27+
- key: {{ $t.key }}
28+
operator: {{ $t.operator }}
29+
{{- if not (empty $t.value) }}
30+
value: {{ $t.value }}
31+
{{- end }}
32+
{{- if not (empty $t.tolerationSeconds) }}
33+
tolerationSeconds: {{ $t.tolerationSeconds }}
34+
{{- end }}
35+
{{- end }}
36+
37+
{{- if not $hasUnreachable }}
38+
- key: {{ $unreachableToleration }}
39+
operator: Exists
40+
{{- end }}
41+
42+
{{- if not $hasUnavailable }}
43+
- key: {{ $unavailableToleration }}
44+
operator: Exists
45+
{{- end }}
46+
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: cluster.open-cluster-management.io/v1beta1
2+
kind: Placement
3+
metadata:
4+
name: placement-openshift-plus-hub
5+
namespace: policies
6+
spec:
7+
predicates:
8+
- requiredClusterSelector:
9+
labelSelector:
10+
matchExpressions:
11+
- {key: "local-cluster", operator: In, values: ["true"]}

policygenerator/policy-sets/community/ocp-best-practices/input/placement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ spec:
99
labelSelector:
1010
matchExpressions:
1111
- {key: vendor, operator: In, values: ["OpenShift"]}
12+
- {key: "local-cluster", operator: NotIn, values: ["true"]}

policygenerator/policy-sets/community/ocp-best-practices/policyGenerator.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ policyDefaults:
1212
namespace: policies
1313
policySets:
1414
- openshift-best-practices
15+
- openshift-best-practices-hub
1516
remediationAction: enforce
1617
severity: medium
1718
standards:
@@ -26,6 +27,8 @@ policies:
2627
manifests:
2728
- path: input-admin/policy-remove-kubeadmin.yaml
2829
remediationAction: "inform"
30+
policySets:
31+
- openshift-best-practices
2932
- name: policy-config-audit
3033
categories:
3134
- AU Audit and Accountability
@@ -34,6 +37,9 @@ policies:
3437
manifests:
3538
- path: input-audit/policy-config-audit.yaml
3639
remediationAction: "enforce"
40+
policySets:
41+
- openshift-best-practices-hub
42+
- openshift-best-practices
3743
#- name: policy-cert-ocp4
3844
# categories:
3945
# - SC System and Communications Protection
@@ -45,15 +51,24 @@ policies:
4551
manifests:
4652
- path: input-compliance/policy-compliance-operator-install.yaml
4753
remediationAction: "enforce"
54+
policySets:
55+
- openshift-best-practices-hub
56+
- openshift-best-practices
4857
- name: policy-compliance-operator-moderate-scan
4958
manifests:
5059
- path: input-compliance/policy-compliance-operator-moderate-scan.yaml
5160
remediationAction: "enforce"
61+
policySets:
62+
- openshift-best-practices-hub
63+
- openshift-best-practices
5264
- name: policy-compliance-operator-moderate-scan-results
5365
complianceType: "mustnothave"
5466
manifests:
5567
- path: input-compliance/policy-compliance-operator-scan-results.yaml
5668
remediationAction: "inform"
69+
policySets:
70+
- openshift-best-practices-hub
71+
- openshift-best-practices
5772
#- name: policy-etcd-backup
5873
# manifests:
5974
# - path: input-etcd/policy-etcd-backup.yaml
@@ -66,6 +81,9 @@ policies:
6681
manifests:
6782
- path: input-etcd/policy-etcdencryption.yaml
6883
remediationAction: "enforce"
84+
policySets:
85+
- openshift-best-practices-hub
86+
- openshift-best-practices
6987
- name: policy-file-integrity-operator
7088
categories:
7189
- SC System and Communications Protection
@@ -74,6 +92,8 @@ policies:
7492
manifests:
7593
- path: input-files/policy-file-integrity-operator.yaml
7694
remediationAction: "enforce"
95+
policySets:
96+
- openshift-best-practices
7797
- name: policy-file-integrity-node-status
7898
complianceType: "mustnothave"
7999
categories:
@@ -83,6 +103,9 @@ policies:
83103
manifests:
84104
- path: input-files/policy-file-integrity-node-status.yaml
85105
remediationAction: "inform"
106+
policySets:
107+
- openshift-best-practices-hub
108+
- openshift-best-practices
86109
- name: policy-checkfipscompliance
87110
categories:
88111
- CA Security Assessment and Authorization
@@ -91,11 +114,17 @@ policies:
91114
manifests:
92115
- path: input-fips/policy-check-fips.yaml
93116
remediationAction: "inform"
117+
policySets:
118+
- openshift-best-practices-hub
119+
- openshift-best-practices
94120
- name: policy-checkclusteroperator
95121
complianceType: "mustnothave"
96122
manifests:
97123
- path: input-operators/
98124
remediationAction: "inform"
125+
policySets:
126+
- openshift-best-practices-hub
127+
- openshift-best-practices
99128
- name: policy-scc-restricted
100129
categories:
101130
- SC System and Communications Protection
@@ -104,8 +133,19 @@ policies:
104133
manifests:
105134
- path: input-scc/
106135
remediationAction: "inform"
136+
- name: policy-placement-tolerations
137+
severity: critical
138+
remediationAction: inform
139+
manifests:
140+
- path: input-tolerations/placement-tolerations.yaml
141+
policySets:
142+
- openshift-best-practices-hub
107143
policySets:
108144
- description: Applies the OpenShift best practices for how to harden your OpenShift clusters.
109145
name: openshift-best-practices
110146
placement:
111147
placementPath: input/placement.yaml
148+
- description: Applies the OpenShift best practices for how to harden your OpenShift clusters on the hub.
149+
name: openshift-best-practices-hub
150+
placement:
151+
placementPath: input/hub-placement.yaml

0 commit comments

Comments
 (0)