Skip to content

Commit 072918e

Browse files
committed
feat: add selective enforcement placement/binding generation support
Introduce enforcementPlacement alongside primary placement so policies and policy sets can generate a second Placement/PlacementBinding with subFilter and bindingOverrides for selective enforce. The new fields is at the same levels as placement (policyDefaults, policies, policySetDefaults, policySets). It reuses the existing placement model for defaults, overrides, membership (generatePlacementWhenInSet), and consolidation of matching selectors. Unlike primary placement, which is generated by default, enforcement placement and binding are only generated when enforcementPlacement is configured via labelSelector, placementPath, or placementName. Companion flags mirror the primary placement controls: - generatePolicyEnforcementPlacement (like generatePolicyPlacement) - generatePolicySetEnforcementPlacement (like generatePolicySetPlacement) - placementBindingDefaults.enforcementName (like placementBindingDefaults.name) ref: https://redhat.atlassian.net/browse/ACM-17945 Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Angie Wang <angwang@redhat.com>
1 parent 0560845 commit 072918e

6 files changed

Lines changed: 1370 additions & 270 deletions

File tree

docs/policygenerator-reference.yaml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ metadata:
99
placementBindingDefaults:
1010
# Set an explicit placement binding name to use rather than rely on the default.
1111
name: ""
12+
# Optional. Set an explicit placement binding name to use for generated selective enforcement bindings
13+
# rather than rely on the default.
14+
enforcementName: ""
1215

1316
# Required. Defaults for policy generation. Any default value listed here can be overridden under an entry in the
1417
# policies array except for "namespace".
@@ -154,6 +157,30 @@ policyDefaults:
154157
# responsibility of the administrator to ensure the placement exists. Use of this setting will prevent a Placement
155158
# from being generated, but the Placement Binding will still be created.
156159
placementName: ""
160+
# Optional. The placement configuration for the selective enforcement binding of the policies. When set, the
161+
# generator creates a second Placement and PlacementBinding with `subFilter: restricted` and
162+
# `bindingOverrides.remediationAction: enforce`. This defaults to unset.
163+
enforcementPlacement:
164+
# To specify a placement, specify key:value pair cluster label selectors or the full LabelSelector for the desired
165+
# cluster label selector. (See placementPath to specify an existing file instead.)
166+
# For example, to specify a placement using matchExpressions:
167+
# labelSelector:
168+
# matchExpressions:
169+
# - key: provider
170+
# operator: NotIn
171+
# values:
172+
# - "cloud"
173+
labelSelector: {}
174+
# Optional. Specifying a name will consolidate placements that contain the same cluster selectors.
175+
# A name alone does not enable selective enforcement generation; also set labelSelector.
176+
name: ""
177+
# To reuse an existing placement manifest, specify the path here relative to the kustomization.yaml file. If given,
178+
# this placement will be used by all policies by default. (See labelSelector to generate a new Placement instead.)
179+
placementPath: ""
180+
# Use a placement that already exists in the cluster in the same namespace as the policy to be generated. It is the
181+
# responsibility of the administrator to ensure the placement exists. Use of this setting will prevent a Placement
182+
# from being generated, but the Placement Binding will still be created.
183+
placementName: ""
157184
# Optional. recreateOption describes whether to delete and recreate an object when an update is required. `IfRequired`
158185
# will recreate the object when updating an immutable field. `Always` will always recreate the object if a mismatch
159186
# is detected. `RecreateOption` has no effect when the `remediationAction` is `inform`. `IfRequired` has no effect
@@ -183,9 +210,15 @@ policyDefaults:
183210
# part of a policy set. Use this setting to turn off placement generation for policies not in policy sets. This
184211
# defaults to "true".
185212
generatePolicyPlacement: true
213+
# Optional. Whether to generate the selective enforcement Placement and PlacementBinding when enforcementPlacement is
214+
# configured. Generation occurs except when policies are part of a policy set. Use this setting to turn off the
215+
# enforcement binding path for policies not in policy sets. This is independent from generatePolicyPlacement. This
216+
# defaults to "true".
217+
generatePolicyEnforcementPlacement: true
186218
# Optional. When a policy is part of a policy set, by default the generator will not generate the placement for this
187219
# policy since a placement is generated for the policy set. If a placement should still be generated, set it to "true"
188-
# so that the policy will be deployed with both policy placement and policy set placement. This defaults to "false".
220+
# so that the policy will be deployed with both policy placement and policy set placement. This applies to both the
221+
# primary placement and the optional selective enforcement placement. This defaults to "false".
189222
generatePlacementWhenInSet: false
190223
# Optional. Annotations that the policy will include under its metadata.annotations. It will be applied for all
191224
# policies unless specified in the policy.
@@ -204,8 +237,17 @@ policySetDefaults:
204237
# all clusters. If a placement.name is not provided here for placement consolidation, it will fall back to
205238
# policyDefaults.placement.name, if provided there. (See policyDefaults.placement for description.)
206239
placement: {}
240+
# Optional. The placement configuration for the selective enforcement binding of the policy sets. This defaults to
241+
# unset. If an enforcementPlacement.name is not provided here for placement consolidation, it will fall back to
242+
# policyDefaults.enforcementPlacement.name, if provided there. (See policyDefaults.enforcementPlacement for
243+
# description.)
244+
enforcementPlacement: {}
207245
# Optional. Whether to generate placement manifests for policy sets. This defaults to "true".
208246
generatePolicySetPlacement: true
247+
# Optional. Whether to generate the selective enforcement Placement and PlacementBinding for policy sets when
248+
# enforcementPlacement is configured. Use this setting to turn off the enforcement binding path for policy sets.
249+
# This is independent from generatePolicySetPlacement. This defaults to "true".
250+
generatePolicySetEnforcementPlacement: true
209251

210252
# Required. The list of policies to create along with overrides to either the default values or, if set, the values
211253
# given in policyDefaults.
@@ -349,6 +391,8 @@ policies:
349391
orderManifests: false
350392
# Optional. (See policyDefaults.placement for description.)
351393
placement: {}
394+
# Optional. (See policyDefaults.enforcementPlacement for description.)
395+
enforcementPlacement: {}
352396
# Optional. (See policyDefaults.remediationAction for description.)
353397
remediationAction: ""
354398
# Optional. (See policyDefaults.recreateOption for description.)
@@ -364,6 +408,8 @@ policies:
364408
policySets: []
365409
# Optional. (See policyDefaults.generatePolicyPlacement for description.)
366410
generatePolicyPlacement: true
411+
# Optional. (See policyDefaults.generatePolicyEnforcementPlacement for description.)
412+
generatePolicyEnforcementPlacement: true
367413
# Optional. (See policyDefaults.generatePlacementWhenInSet for description.)
368414
generatePlacementWhenInSet: false
369415
# Optional. Annotations that the policy will include under its metadata.annotations. It will overwrite the
@@ -387,5 +433,10 @@ policySets:
387433
# Optional. (See policySetDefaults.placement to set a default placement for policy sets. See
388434
# policyDefaults.placement for description of placement options.)
389435
placement: {}
436+
# Optional. (See policySetDefaults.enforcementPlacement to set a default selective enforcement placement for policy
437+
# sets. See policyDefaults.enforcementPlacement for description of placement options.)
438+
enforcementPlacement: {}
390439
# Optional. (See policySetDefaults.generatePolicySetPlacement for description.)
391440
generatePolicySetPlacement: true
441+
# Optional. (See policySetDefaults.generatePolicySetEnforcementPlacement for description.)
442+
generatePolicySetEnforcementPlacement: true

docs/policygenerator.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ PlacementBinding, specify `placement.placementPath` to an existing Placement man
2323
this way, `placementBindingDefaults.name` must be specified so that the generator can create unique
2424
names for the bindings.
2525

26+
To generate a second Placement and PlacementBinding for selective enforcement, configure
27+
`enforcementPlacement`. This follows the same placement configuration rules as `placement`, but the
28+
generated PlacementBinding includes `subFilter: restricted` and
29+
`bindingOverrides.remediationAction: enforce`. To consolidate policies that use the same selective
30+
enforcement Placement under a single PlacementBinding, specify `enforcementPlacement.placementPath`
31+
to an existing Placement manifest or set `enforcementPlacement.name` along with
32+
`enforcementPlacement.labelSelector`. When the PlacementBinding is consolidated in this way,
33+
`placementBindingDefaults.enforcementName` must be specified so that the generator can create unique
34+
names for the bindings. Use `generatePolicyEnforcementPlacement` or
35+
`generatePolicySetEnforcementPlacement` to opt a specific policy or policy set out of a
36+
defaults-configured `enforcementPlacement`.
37+
2638
## Policy expanders
2739

2840
Policy expanders provide logic to create additional policies based on a given kind to give a

0 commit comments

Comments
 (0)