6.2. Custom security policies
In addition to using the default policies, you can also create custom policies in Red Hat Advanced Cluster Security for Kubernetes.
You can create custom policies by using the following methods:
-
In the RHACS portal, go to Platform configuration
Policy management and click Create policy. - In the RHACS portal, go to Risk and use the filter to select the criteria that you want the policy to use. Click Create policy.
- Create and manage policies as code by saving policies as Kubernetes custom resources (CRs) and by applying them to clusters using a continuous delivery tool such as Argo CD.
See the following sections for more information.
You can create new security policies from the system policies view.
Procedure
-
In the RHACS portal, go to Platform Configuration
Policy Management. - Click Create policy.
- Configure the policy definition information in the following sections.
You can use the drag-and-drop policy fields panel to specify logical conditions for the policy criteria.
Prerequisites
- You must be using Red Hat Advanced Cluster Security for Kubernetes version 3.0.45 or newer.
Procedure
In the Policy Criteria section, select Add a new condition to add a new policy section.
- You can click on the Edit icon to rename the policy section.
- The Drag out a policy field section lists available policy criteria in multiple categories. You can expand and collapse these categories to view the policy criteria attributes.
- Drag an attribute to the Drop a policy field inside area of the policy section.
Depending on the type of the attribute you select, you get different options to configure the conditions for the selected attribute. For example:
-
If you select an attribute with Boolean values
Read-Only Root Filesystem, you will seeREAD-ONLYandWRITABLEoptions. If you select an attribute with compound values
Environment variable, you will see options to enter values forKey,Value, andValue Fromfields, and an icon to add more values for the available options.- To combine multiple values for an attribute, click the Add icon.
-
You can also click on the logical operator
ANDorORlisted in a policy section, to toggle betweenANDandORoperators. Toggling between operators only works inside a policy section and not between two different policy sections.
-
If you select an attribute with Boolean values
-
You can specify more than one
ANDandORcondition by repeating these steps. After you configure the conditions for the added attributes, click Next to continue with the policy creation.
6.2.2. Creating a security policy from the risk view 复制链接链接已复制到粘贴板!
While evaluating risks in your deployments in the Risk view, when you apply local page filtering, you can create new security policies based on the filtering criteria you are using.
Procedure
- Go to the RHACS portal and select Risk from the navigation menu.
- Apply local page filtering criteria that you want to create a policy for.
- Select New Policy and complete the required fields to create a new policy. For the steps to create a policy, see "Creating a security policy from the system policies view".
6.2.3. Modifying existing security policies 复制链接链接已复制到粘贴板!
You can edit the policies you have created and the existing default policies provided by Red Hat Advanced Cluster Security for Kubernetes that you have cloned.
Procedure
-
In the RHACS portal, go to Platform Configuration
Policy Management. - From the Policies page, select the policy you want to edit.
Select Actions
Edit policy. 注意You cannot edit default policies. You must clone a default policy and edit the cloned policy.
- Edit the fields that you want to change and click Save.
6.2.3.1. Disabling associated policies 复制链接链接已复制到粘贴板!
You can turn off the enforcement on relevant policies, which in turn instructs the admission controller to skip enforcements.
Procedure
-
In the RHACS portal, go to Platform Configuration
Policy Management. Disable enforcement on the default policies:
-
In the policies view, locate the Kubernetes Actions: Exec into Pod policy. Click the overflow menu,
, and then select Disable policy.
-
In the policies view, locate the Kubernetes Actions: Port Forward to Pod policy. Click the overflow menu,
, and then select Disable policy.
-
In the policies view, locate the Kubernetes Actions: Exec into Pod policy. Click the overflow menu,
- Disable enforcement on any other custom policies that you have created by using criteria from the default Kubernetes Actions: Port Forward to Pod and Kubernetes Actions: Exec into Pod policies.