2장. Integrating with CI systems
Red Hat Advanced Cluster Security for Kubernetes (RHACS) integrates with a variety of continuous integration (CI) products. Before you deploy images, you can use RHACS to apply build-time and deploy-time security rules to your images.
After images are built and pushed to a registry, RHACS integrates into CI pipelines. Pushing the image first allows developers to continue testing their artifacts while dealing with any policy violations alongside any other CI test failures, linter violations, or other problems.
If possible, configure the version control system to block pull or merge requests from being merged if the build stage, which includes RHACS checks, fails.
The integration with your CI product functions by contacting your RHACS installation to check whether the image complies with build-time policies you have configured. If there are policy violations, a detailed message is displayed on the console log, including the policy description, rationale, and remediation instructions.
Each policy includes an optional enforcement setting. If you mark a policy for build-time enforcement, failure of that policy causes the client to exit with a nonzero error code.
To integrate Red Hat Advanced Cluster Security for Kubernetes with your CI system, follow these steps:
- Configure build policies.
- Configure a registry integration.
- Configure access to your RHACS instance.
- Integrate with your CI pipeline.
2.1. Configuring build policies 링크 복사링크가 클립보드에 복사되었습니다!
You can check RHACS policies during builds.
Procedure
- Configure policies that apply to the build time of the container lifecycle.
- Integrate with the registry that images are pushed to during the build.
2.1.1. Checking existing build-time policies 링크 복사링크가 클립보드에 복사되었습니다!
Use the RHACS portal to check any existing build-time policies that you have configured in Red Hat Advanced Cluster Security for Kubernetes.
Procedure
-
In the RHACS portal, go to Platform Configuration
Policy Management. -
Use global search to search for
Lifecycle Stage:Build.
2.1.2. Creating a new system policy 링크 복사링크가 클립보드에 복사되었습니다!
In addition to using the default policies, you can also create custom policies in Red Hat Advanced Cluster Security for Kubernetes.
Procedure
-
In the RHACS portal, go to Platform Configuration
Policy Management. - Click + New Policy.
- Enter the Name for the policy.
- Select a Severity level for the policy: Critical, High, Medium, or Low.
Choose the Lifecycle Stages for which the policy is applicable, from Build, Deploy, or Runtime. You can select more than one stage.
참고If you create a new policy for integrating with a CI system, select Build as the lifecycle stage.
- Build-time policies apply to image fields such as CVEs and Dockerfile instructions.
- Deploy-time policies can include all build-time policy criteria. They can also have data from your cluster configurations, such as running in privileged mode or mounting the Docker daemon socket.
- Runtime policies can include all build-time and deploy-time policy criteria, and data about process executions during runtime.
- Enter information about the policy in the Description, Rationale, and Remediation fields. When CI validates the build, the data from these fields is displayed. Therefore, include all information explaining the policy.
- Select a category from the Categories drop-down menu.
Select a notifier from the Notifications drop-down menu that receives alert notifications when a violation occurs for this policy.
참고You must integrate RHACS with your notification providers, such as webhooks, Jira, or PagerDuty, to receive alert notifications. Notifiers only show up if you have integrated any notification providers with RHACS.
- Use Restrict to Scope to enable this policy only for a specific cluster, namespace, or label. You can add multiple scopes and also use regular expressions in RE2 Syntax for namespaces and labels.
- Use Exclude by Scope to exclude deployments, clusters, namespaces, and labels. This field indicates that the policy will not apply to the entities that you specify. You can add multiple scopes and also use regular expressions in RE2 Syntax for namespaces and labels. However, you cannot use regular expressions for selecting deployments.
For Excluded Images (Build Lifecycle only), select all the images from the list for which you do not want to trigger a violation for the policy.
참고The Excluded Images (Build Lifecycle only) setting only applies when you check images in a continuous integration system (the Build lifecycle stage). It does not have any effect if you use this policy to check running deployments (the Deploy lifecycle stage) or runtime activities (the Runtime lifecycle stage).
- In the Policy Criteria section, configure the attributes that will trigger the policy.
- Select Next on the panel header.
- The new policy panel shows a preview of the violations that are triggered if you enable the policy.
- Select Next on the panel header.
Choose the enforcement behavior for the policy. Enforcement settings are only available for the stages that you selected for the Lifecycle Stages option. Select ON to enforce policy and report a violation. Select OFF to only report a violation.
참고The enforcement behavior is different for each lifecycle stage.
- For the Build stage, RHACS fails your CI builds when images match the conditions of the policy.
For the Deploy stage, RHACS blocks the creation and update of deployments that match the conditions of the policy if the RHACS admission controller is configured and running.
- In clusters with admission controller enforcement, the Kubernetes or OpenShift Container Platform API server blocks all noncompliant deployments. In other clusters, RHACS edits noncompliant deployments to prevent pods from being scheduled.
- For existing deployments, policy changes only result in enforcement at the next detection of the criteria, when a Kubernetes event occurs. For more information about enforcement, see "Security policy enforcement for the deploy stage".
- For the Runtime stage, RHACS stops all pods that match the conditions of the policy.
주의Policy enforcement can impact running applications or development processes. Before you enable enforcement options, inform all stakeholders and plan how to respond to the automated enforcement actions.
2.1.2.1. Security policy enforcement for the deploy stage 링크 복사링크가 클립보드에 복사되었습니다!
Red Hat Advanced Cluster Security for Kubernetes supports two forms of security policy enforcement for deploy-time policies: hard enforcement through the admission controller and soft enforcement by RHACS Sensor. The admission controller blocks creation or updating of deployments that violate policy. If the admission controller is disabled or unavailable, Sensor can perform enforcement by scaling down replicas for deployments that violate policy to 0.
Policy enforcement can impact running applications or development processes. Before you enable enforcement options, inform all stakeholders and plan how to respond to the automated enforcement actions.