Skip to content

Commit ee4d975

Browse files
Add policy for ArgoCD healthcheck configuration
Refs: - https://issues.redhat.com/browse/ACM-13094 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent a05e0ef commit ee4d975

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

stable/CM-Configuration-Management/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ Policy | Description | Prerequisites
1010
[policy-pod](../CM-Configuration-Management/policy-pod.yaml) | Ensures that a pod exists as specified. |
1111
[policy-zts-cmc](../CM-Configuration-Management/policy-zts-cmc.yaml) | This example deploys a replica of \`zts-cmc-deployment\`. | See the [Zettaset README.stable(https://github.com/zettaset/zettaset-public/) to learn more about Zettaset CMC Deployment.
1212
[Scan your cluster with the OpenShift CIS security profile](../CM-Configuration-Management/policy-compliance-operator-cis-scan.yaml) | This example creates a ScanSettingBinding that the ComplianceOperator uses to scan the cluster for compliance with the OpenShift CIS benchmark. | See the [Compliance Operator repository](https://github.com/openshift/compliance-operator) to learn more about the operator. **Note**: The Compliance Operator must be installed to use this policy. See the [Compliance operator policy](../CA-Security-Assessment-and-Authorization/policy-compliance-operator-install.yaml) to install the Compliance Operator with a policy.
13+
[Configure ArgoCD instances with Policy healthchecks](../CM-Configuration-Management/argocd-policy-healthchecks.yaml) | This policy configures healthchecks for open-cluster-management-io Policy kinds on any ArgoCD instances found on the cluster. | See the [Red Hat OpenShift GitOps documentation](https://docs.openshift.com/gitops/) for more information about this operator. |
1314

1415
You can contribute more policies that map to the Configuration Management catalog. See [Contibuting policies](https://github.com/open-cluster-management-io/policy-collection/blob/main/docs/CONTRIBUTING.md) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
apiVersion: policy.open-cluster-management.io/v1
2+
kind: Policy
3+
metadata:
4+
name: argocd-policy-healthchecks
5+
annotations:
6+
policy.open-cluster-management.io/standards: NIST SP 800-53
7+
policy.open-cluster-management.io/categories: CM Configuration Management
8+
policy.open-cluster-management.io/controls: CM-2 Baseline Configuration
9+
policy.open-cluster-management.io/description: >-
10+
This policy configures healthchecks for open-cluster-management-io Policy kinds on any ArgoCD
11+
instances found on the cluster.
12+
spec:
13+
remediationAction: inform
14+
disabled: false
15+
policy-templates:
16+
- objectDefinition:
17+
apiVersion: policy.open-cluster-management.io/v1
18+
kind: ConfigurationPolicy
19+
metadata:
20+
name: config-argocd-policy-healthchecks
21+
spec:
22+
severity: medium
23+
# Apply the healthcheck configuration to all ArgoCD instances that are
24+
# found - this helps it to work on different environments, and ensures
25+
# that the configuration is not applied before the GitOps operator
26+
# creates the initial instance.
27+
object-templates-raw: |
28+
{{- range (lookup "argoproj.io/v1beta1" "ArgoCD" "" "").items }}
29+
- complianceType: musthave
30+
objectDefinition:
31+
apiVersion: argoproj.io/v1beta1
32+
kind: ArgoCD
33+
metadata:
34+
name: {{ .metadata.name }}
35+
namespace: {{ .metadata.namespace }}
36+
spec:
37+
resourceHealthChecks:
38+
- group: policy.open-cluster-management.io
39+
kind: CertificatePolicy
40+
check: |
41+
hs = {}
42+
if obj.status == nil or obj.status.compliant == nil then
43+
hs.status = "Progressing"
44+
hs.message = "Waiting for the status to be reported"
45+
return hs
46+
end
47+
if obj.status.compliant == "Compliant" then
48+
hs.status = "Healthy"
49+
hs.message = "All certificates found comply with the policy"
50+
return hs
51+
else
52+
hs.status = "Degraded"
53+
hs.message = "At least once certificate does not comply with the policy"
54+
return hs
55+
end
56+
- group: policy.open-cluster-management.io
57+
kind: ConfigurationPolicy
58+
check: |
59+
hs = {}
60+
if obj.status == nil or obj.status.compliant == nil then
61+
hs.status = "Progressing"
62+
hs.message = "Waiting for the status to be reported"
63+
return hs
64+
end
65+
if obj.status.lastEvaluatedGeneration ~= obj.metadata.generation then
66+
hs.status = "Progressing"
67+
hs.message = "Waiting for the status to be updated"
68+
return hs
69+
end
70+
if obj.status.compliant == "Compliant" then
71+
hs.status = "Healthy"
72+
else
73+
hs.status = "Degraded"
74+
end
75+
if obj.status.compliancyDetails ~= nil then
76+
messages = {}
77+
for i, compliancy in ipairs(obj.status.compliancyDetails) do
78+
if compliancy.conditions ~= nil then
79+
for i, condition in ipairs(compliancy.conditions) do
80+
if condition.message ~= nil and condition.type ~= nil then
81+
table.insert(messages, condition.type .. " - " .. condition.message)
82+
end
83+
end
84+
end
85+
end
86+
hs.message = table.concat(messages, "; ")
87+
return hs
88+
end
89+
hs.status = "Progressing"
90+
hs.message = "Waiting for compliance"
91+
return hs
92+
- group: policy.open-cluster-management.io
93+
kind: OperatorPolicy
94+
check: |
95+
hs = {}
96+
if obj.status == nil or obj.status.conditions == nil then
97+
hs.status = "Progressing"
98+
hs.message = "Waiting for the status to be reported"
99+
return hs
100+
end
101+
if obj.status.observedGeneration ~= nil and obj.status.observedGeneration ~= obj.metadata.generation then
102+
hs.status = "Progressing"
103+
hs.message = "Waiting for the status to be updated"
104+
return hs
105+
end
106+
for i, condition in ipairs(obj.status.conditions) do
107+
if condition.type == "Compliant" then
108+
hs.message = condition.message
109+
if condition.status == "True" then
110+
hs.status = "Healthy"
111+
return hs
112+
else
113+
hs.status = "Degraded"
114+
return hs
115+
end
116+
end
117+
end
118+
hs.status = "Progressing"
119+
hs.message = "Waiting for the compliance condition"
120+
return hs
121+
- group: policy.open-cluster-management.io
122+
kind: Policy
123+
check: |
124+
hs = {}
125+
if obj.status == nil or obj.status.compliant == nil then
126+
hs.status = "Progressing"
127+
hs.message = "Waiting for the status to be reported"
128+
return hs
129+
end
130+
if obj.status.compliant == "Compliant" then
131+
hs.status = "Healthy"
132+
else
133+
hs.status = "Degraded"
134+
end
135+
noncompliants = {}
136+
if obj.status.status ~= nil then
137+
-- "root" policy
138+
for i, entry in ipairs(obj.status.status) do
139+
if entry.compliant ~= "Compliant" then
140+
noncompliants[i] = entry.clustername
141+
end
142+
end
143+
if table.getn(noncompliants) == 0 then
144+
hs.message = "All clusters are compliant"
145+
else
146+
hs.message = "NonCompliant clusters: " .. table.concat(noncompliants, ", ")
147+
end
148+
elseif obj.status.details ~= nil then
149+
-- "replicated" policy
150+
for i, entry in ipairs(obj.status.details) do
151+
if entry.compliant ~= "Compliant" then
152+
noncompliants[i] = entry.templateMeta.name
153+
end
154+
end
155+
if table.getn(noncompliants) == 0 then
156+
hs.message = "All templates are compliant"
157+
else
158+
hs.message = "NonCompliant templates: " .. table.concat(noncompliants, ", ")
159+
end
160+
end
161+
return hs
162+
{{- end }}

stable/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Policy | Description | Prerequisites
5454
[policy-pod](./CM-Configuration-Management/policy-pod.yaml) | Ensures that a pod exists as specified. |
5555
[policy-zts-cmc](./CM-Configuration-Management/policy-zts-cmc.yaml) | This example deploys a replica of \`zts-cmc-deployment\`. | See the [Zettaset README.stable](https://github.com/zettaset/zettaset-public/) to learn more about Zettaset CMC Deployment.
5656
[Scan your cluster with the OpenShift CIS security profile](./CM-Configuration-Management/policy-compliance-operator-cis-scan.yaml) | This example creates a ScanSettingBinding that the ComplianceOperator uses to scan the cluster for compliance with the OpenShift CIS benchmark. | See the [Compliance Operator repository](https://github.com/openshift/compliance-operator) to learn more about the operator. **Note**: The Compliance Operator must be installed to use this policy. See the [Compliance operator policy](./CA-Security-Assessment-and-Authorization/policy-compliance-operator-install.yaml) to install the Compliance Operator with a policy.
57+
[Configure ArgoCD instances with Policy healthchecks](./CM-Configuration-Management/argocd-policy-healthchecks.yaml) | This policy configures healthchecks for open-cluster-management-io Policy kinds on any ArgoCD instances found on the cluster. | See the [Red Hat OpenShift GitOps documentation](https://docs.openshift.com/gitops/) for more information about this operator. |
5758

5859
### Contingency Planning
5960

0 commit comments

Comments
 (0)