Chapter 4. Integrating Policy Generator
By integrating the Policy Generator, you can use it to automatically build Red Hat Advanced Cluster Management for Kubernetes policies. To integrate the Policy Generator, see Policy Generator.
For an example of what you can do with the Policy Generator, see Generating a policy that installs the Compliance Operator.
4.1. Policy Generator Copy linkLink copied to clipboard!
The Policy Generator is a part of the Red Hat Advanced Cluster Management for Kubernetes application lifecycle subscription Red Hat OpenShift GitOps workflow that generates Red Hat Advanced Cluster Management policies using Kustomize. The Policy Generator builds Red Hat Advanced Cluster Management policies from Kubernetes manifest YAML files, which are provided through a PolicyGenerator manifest YAML file that is used to configure it. The Policy Generator is implemented as a Kustomize generator plug-in. For more information on Kustomize, read the Kustomize documentation.
View the following sections for more information:
4.1.1. Policy Generator capabilities Copy linkLink copied to clipboard!
The integration of the Policy Generator with the Red Hat Advanced Cluster Management application lifecycle subscription OpenShift GitOps workflow simplifies the distribution of Kubernetes resource objects to managed OpenShift Container Platform clusters, and Kubernetes clusters through Red Hat Advanced Cluster Management policies.
Use the Policy Generator to complete the following actions:
- Convert any Kubernetes manifest files to Red Hat Advanced Cluster Management configuration policies, including manifests that are created from a Kustomize directory.
- Patch the input Kubernetes manifests before they are inserted into a generated Red Hat Advanced Cluster Management policy.
- Generate additional configuration policies so you can report on Gatekeeper policy violations through Red Hat Advanced Cluster Management for Kubernetes.
- Generate policy sets on the hub cluster.
4.1.2. Policy Generator configuration structure Copy linkLink copied to clipboard!
The Policy Generator is a Kustomize generator plug-in that is configured with a manifest of the PolicyGenerator kind and policy.open-cluster-management.io/v1 API version. Continue reading to learn about the configuration structure:
To use the plug-in, add a
generatorssection in akustomization.yamlfile. View the following example:generators: - policy-generator-config.yaml
generators: - policy-generator-config.yaml1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The
policy-generator-config.yamlfile that is referenced in the previous example is a YAML file with the instructions of the policies to generate.
A simple
PolicyGeneratorconfiguration file might resemble the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The
configmap.yamlrepresents a Kubernetes manifest YAML file to be included in the policy. Alternatively, you can set the path to a Kustomize directory, or a directory with multiple Kubernetes manifest YAML files. View the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
object-templates-rawmanifest to automatically generate aConfigurationPolicyresource with the content you add. See the following examples:For example, create a manifest file with the following syntax:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Then create a
PolicyGeneratorconfiguration file similar to the following YAML:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Path to your
manifest.yamlfile.
The generated
Policyresource, along with the generatedPlacementandPlacementBindingmight resemble the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.1.3. Policy Generator configuration reference table Copy linkLink copied to clipboard!
All the fields in the policyDefaults section except for namespace can be overridden for each policy, and all the fields in the policySetDefaults section can be overridden for each policy set.
| Field | Optional or required | Description |
|---|---|---|
|
| Required |
Set the value to |
|
| Required |
Set the value to |
|
| Required | The name for identifying the policy resource. |
|
| Optional |
If multiple policies use the same placement, this name is used to generate a unique name for the resulting |
|
| Required |
Any default value listed here is overridden by an entry in the policies array except for |
|
| Required | The namespace of all the policies. |
|
| Optional |
Determines the policy controller behavior when comparing the manifest to objects on the cluster. The values that you can use are |
|
| Optional |
Overrides |
|
| Optional |
Array of categories to be used in the |
|
| Optional |
Array of controls to be used in the |
|
| Optional |
An array of standards to be used in the |
|
| Optional |
Annotations that the policy includes in the |
|
| Optional |
Key-value pairs of annotations to set on generated configuration policies. For example, you can disable policy templates by defining the following parameter: |
|
| Optional |
Copies the labels and annotations for all policies and adds them to a replica policy. Set to |
|
| Optional |
The severity of the policy violation. The default value is |
|
| Optional |
Whether the policy is disabled, meaning it is not propagated and no status as a result. The default value is |
|
| Optional |
The remediation mechanism of your policy. The parameter values are |
|
| Required for namespaced objects that do not have a namespace specified |
Determines namespaces in the managed cluster that the object is applied to. The |
|
| Optional |
Use the parameters |
|
| Optional |
Determines whether objects created or monitored by the policy should be deleted when the policy is deleted. Pruning only takes place if the remediation action of the policy has been set to |
|
| Optional |
Describes whether to delete and recreate an object when an update is required. The
When the |
|
| Optional |
Specifies if and where to log the difference between the object on the cluster and the |
|
| Optional |
A list of objects that must be in specific compliance states before this policy is applied. Cannot be specified when |
|
| Required | The name of the object being depended on. |
|
| Optional | The namespace of the object being depended on. The default is the namespace of policies set for the Policy Generator. |
|
| Optional |
The compliance state the object needs to be in. The default value is |
|
| Optional |
The kind of the object. By default, the kind is set to |
|
| Optional |
The API version of the object. The default value is |
|
| Optional | The description of the policy you want to create. |
|
| Optional |
A list of objects that must be in specific compliance states before this policy is applied. The dependencies that you define are added to each policy template (for example, |
|
| Required | The name of the object being depended on. |
|
| Optional | The namespace of the object being depended on. By default, the value is set to the namespace of policies set for the Policy Generator. |
|
| Optional |
The compliance state the object needs to be in. The default value is |
|
| Optional |
The kind of the object. The default value is to |
|
| Optional |
The API version of the object. The default value is |
|
| Optional |
Bypass compliance status checks when the Policy Generator is waiting for its dependencies to reach their desired states. The default value is |
|
| Optional |
Automatically generate |
|
| Optional |
Automatically generate |
|
| Optional |
This determines if a single configuration policy is generated for all the manifests being wrapped in the policy. If set to |
|
| Optional |
Set |
|
| Optional |
When the policy references a Kyverno policy manifest, this determines if an additional configuration policy is generated to receive policy violations in Red Hat Advanced Cluster Management, when the Kyverno policy is violated. The default value is |
|
| Optional |
Labels that the policy includes in its |
|
| Optional |
Array of policy sets that the policy joins. Policy set details can be defined in the |
|
| Optional |
Generate placement manifests for policies. Set to |
|
| Optional |
When a policy is part of a policy set, by default, the generator does not generate the placement for this policy since a placement is generated for the policy set. Set |
|
| Optional | The placement configuration for the policies. This defaults to a placement configuration that matches all clusters. |
|
| Optional | Specifying a name to consolidate placements that contain the same cluster label selectors. |
|
| Optional |
Specify a placement by defining a cluster label selector using either |
|
| Optional |
Define this parameter to use a placement that already exists on the cluster. A |
|
| Optional |
To reuse an existing placement, specify the path relative to the location of the |
|
| Optional |
|
|
| Optional |
|
|
| Optional |
|
|
| Optional |
Default values for policy sets. Any default value listed for this parameter is overridden by an entry in the |
|
| Optional |
The placement configuration for the policies. This defaults to a placement configuration that matches all clusters. See |
|
| Optional |
Generate placement manifests for policy sets. Set to |
|
| Required |
The list of policies to create along with overrides to either the default values, or the values that are set in |
|
| Optional | The description of the policy you want to create. |
|
| Required | The name of the policy to create. |
|
| Required |
The list of Kubernetes object manifests to include in the policy, along with overrides to either the default values, the values set in this |
|
| Required |
Path to a single file, a flat directory of files, or a Kustomize directory relative to the The following manifests are supported:
|
|
| Optional |
A list of Kustomize patches to apply to the manifest at the path. If there are multiple manifests, the patch requires the |
|
| Optional |
Labels that the policy includes in its |
|
| Optional |
The list of policy sets to create, along with overrides to either the default values or the values that are set in |
|
| Required | The name of the policy set to create. |
|
| Optional | The description of the policy set to create. |
|
| Optional |
The list of policies to be included in the policy set. If |
4.1.4. Additional resources Copy linkLink copied to clipboard!
- Read Generating a policy to install GitOps Operator.
- Read to Policy set controller for more details.
- Read Applying Kustomize for more information.
- Read the Governance documentation for more topics.
-
See an example of a
kustomization.yamlfile. - Refer to the Kubernetes labels and selectors documentation.
- Refer Gatekeeper for more details.
- Refer to the Kustomize documentation.
4.2. Generating a policy that installs the Compliance Operator Copy linkLink copied to clipboard!
Generate a policy that installs the Compliance Operator onto your clusters. For an operator that uses the namespaced installation mode, such as the Compliance Operator, an OperatorGroup manifest is also required.
Complete the following steps:
Create a YAML file with a
Namespace, aSubscription, and anOperatorGroupmanifest calledcompliance-operator.yaml. The following example installs these manifests in thecompliance-operatornamespace:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
PolicyGeneratorconfiguration file. View the followingPolicyGeneratorpolicy example that installs the Compliance Operator on all OpenShift Container Platform managed clusters:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the policy generator to your
kustomization.yamlfile. Thegeneratorssection might resemble the following configuration:generators: - policy-generator-config.yaml
generators: - policy-generator-config.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a result, the generated policy resembles the following file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
As a result, the generated policy is displayed.