Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
object-templates-raw: |
{{/* ## Gather all Placements from the hub cluster ## */}}
{{- $stdTolerations := dict "unreachable" "cluster.open-cluster-management.io/unreachable"
"unavailable" "cluster.open-cluster-management.io/unavailable" }}

{{- range $pt := (lookup "cluster.open-cluster-management.io/v1beta1" "Placement" "" "").items }}
- complianceType: musthave
objectDefinition:
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: {{ $pt.metadata.name }}
namespace: {{ $pt.metadata.namespace }}
spec:
tolerations:
{{- range $t := $pt.spec.tolerations }}
- {{ $t | toRawJson | toLiteral }}

{{/* ## check if the toleration is unavailable or unreachable ## */}}
{{- if eq $t.key $stdTolerations.unreachable }}
{{- $_ := unset $stdTolerations "unreachable" }}
{{- else if eq $t.key $stdTolerations.unavailable }}
{{- $_ := unset $stdTolerations "unavailable" }}
{{- end }}
{{- end }}

{{- range $t := $stdTolerations }}
- key: {{ $t }}
operator: Exists
{{- end }}

{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: placement-openshift-plus-hub
namespace: policies
spec:
predicates:
- requiredClusterSelector:
labelSelector:
matchExpressions:
- {key: "local-cluster", operator: In, values: ["true"]}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ policyDefaults:
namespace: policies
policySets:
- openshift-best-practices
- openshift-best-practices-hub
remediationAction: enforce
severity: medium
standards:
Expand All @@ -26,6 +27,8 @@ policies:
manifests:
- path: input-admin/policy-remove-kubeadmin.yaml
remediationAction: "inform"
policySets:
- openshift-best-practices
- name: policy-config-audit
categories:
- AU Audit and Accountability
Expand All @@ -34,6 +37,8 @@ policies:
manifests:
- path: input-audit/policy-config-audit.yaml
remediationAction: "enforce"
policySets:
- openshift-best-practices
#- name: policy-cert-ocp4
# categories:
# - SC System and Communications Protection
Expand All @@ -45,15 +50,21 @@ policies:
manifests:
- path: input-compliance/policy-compliance-operator-install.yaml
remediationAction: "enforce"
policySets:
- openshift-best-practices
- name: policy-compliance-operator-moderate-scan
manifests:
- path: input-compliance/policy-compliance-operator-moderate-scan.yaml
remediationAction: "enforce"
policySets:
- openshift-best-practices
- name: policy-compliance-operator-moderate-scan-results
complianceType: "mustnothave"
manifests:
- path: input-compliance/policy-compliance-operator-scan-results.yaml
remediationAction: "inform"
policySets:
- openshift-best-practices
#- name: policy-etcd-backup
# manifests:
# - path: input-etcd/policy-etcd-backup.yaml
Expand All @@ -66,6 +77,8 @@ policies:
manifests:
- path: input-etcd/policy-etcdencryption.yaml
remediationAction: "enforce"
policySets:
- openshift-best-practices
- name: policy-file-integrity-operator
categories:
- SC System and Communications Protection
Expand All @@ -74,6 +87,8 @@ policies:
manifests:
- path: input-files/policy-file-integrity-operator.yaml
remediationAction: "enforce"
policySets:
- openshift-best-practices
- name: policy-file-integrity-node-status
complianceType: "mustnothave"
categories:
Expand All @@ -83,6 +98,8 @@ policies:
manifests:
- path: input-files/policy-file-integrity-node-status.yaml
remediationAction: "inform"
policySets:
- openshift-best-practices
- name: policy-checkfipscompliance
categories:
- CA Security Assessment and Authorization
Expand All @@ -91,11 +108,15 @@ policies:
manifests:
- path: input-fips/policy-check-fips.yaml
remediationAction: "inform"
policySets:
- openshift-best-practices
- name: policy-checkclusteroperator
complianceType: "mustnothave"
manifests:
- path: input-operators/
remediationAction: "inform"
policySets:
- openshift-best-practices
- name: policy-scc-restricted
categories:
- SC System and Communications Protection
Expand All @@ -104,8 +125,21 @@ policies:
manifests:
- path: input-scc/
remediationAction: "inform"
policySets:
- openshift-best-practices
- name: policy-placement-tolerations
severity: critical
remediationAction: inform
manifests:
- path: input-tolerations/placement-tolerations.yaml
policySets:
- openshift-best-practices-hub
Comment on lines +130 to +136

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check PolicyGenerator documentation or source for policySets override vs merge behavior.

# Search for PolicyGenerator documentation in the repo
fd -i 'readme' --type f | head -5

# Search for policySets handling in any PolicyGenerator docs
rg -n -C3 'policySets' --type yaml policygenerator/ | head -40

Repository: open-cluster-management-io/policy-collection

Length of output: 4129


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant PolicyGenerator config around the defaults and the new policy.
sed -n '220,280p' policygenerator/policy-sets/community/ocp-best-practices/policyGenerator.yaml

# Find any docs or examples that explain whether per-policy policySets override or merge with defaults.
rg -n -C3 'policyDefaults|policySets|override|merge' policygenerator README.md blogs 3rd-party community stable .github -g '*.md' -g '*.yaml' -g '*.yml' | head -200

# Look for the generator implementation or schema references in-repo.
fd -i 'policygenerator' .
fd -i 'policygenerator.*' .

Repository: open-cluster-management-io/policy-collection

Length of output: 20965


🌐 Web query:

Policy Generator policySets merge override policyDefaults policySets Open Cluster Management

💡 Result:

In the Open Cluster Management (OCM) Policy Generator, the configuration follows a hierarchical structure where defaults can be overridden at more specific levels. PolicyDefaults vs. Overrides The policyDefaults section defines common settings that apply to all policies generated by the PolicyGenerator [1][2]. Most fields defined in policyDefaults can be overridden for individual policies by specifying them within the specific entry in the policies array [1][3]. The only field in policyDefaults that cannot be overridden in this manner is namespace [1][3]. PolicySets and Merging PolicySets are used to group related policies, allowing for unified placement management [1][4]. When a policy is included in a PolicySet, a placement binding is automatically generated for the set rather than for the individual policy [1]. Regarding the interaction between policySets defined in different locations: 1. Merging Behavior: If policySets are specified in multiple places (such as in policyDefaults.policySets and within individual policies[].policySets), the lists of policy sets are merged [1][3]. 2. Overriding: You can define default values for all policy sets using the policySetDefaults section [1]. Any values defined there can be overridden by specific entries within the policySets array [1]. 3. Placement Generation: By default, when a policy is part of a policy set, the generator does not create a separate placement for that policy. You can change this behavior by setting generatePlacementWhenInSet to true in either policyDefaults or at the specific policy level [1]. In summary, the OCM Policy Generator uses a cascading approach where policySetDefaults provide base configurations for all sets, and policyDefaults provides base configurations for all policies, both of which can be selectively overridden by more granular definitions in the policySets or policies arrays, respectively [1][3].

Citations:


policy-placement-tolerations still inherits openshift-best-practices PolicyGenerator merges policySets from policyDefaults with the per-policy entry, so this policy will land in both openshift-best-practices and openshift-best-practices-hub. Move policySets out of the defaults or split the defaults so this one stays hub-only.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@policygenerator/policy-sets/community/ocp-best-practices/policyGenerator.yaml`
around lines 130 - 136, The policy entry for policy-placement-tolerations is
still inheriting policySets from policyDefaults, so it ends up in both
openshift-best-practices and openshift-best-practices-hub. Adjust the
PolicyGenerator configuration so the shared defaults no longer include
policySets for this case, or split the defaults and apply a hub-only set
specifically to policy-placement-tolerations. Use policyDefaults and the
per-policy policySets override to keep this policy scoped only to
openshift-best-practices-hub.

Source: Coding guidelines

policySets:
- description: Applies the OpenShift best practices for how to harden your OpenShift clusters.
name: openshift-best-practices
placement:
placementPath: input/placement.yaml
- description: Applies the OpenShift best practices for how to harden your OpenShift clusters on the hub.
name: openshift-best-practices-hub
placement:
placementPath: input/hub-placement.yaml