Este conteúdo não está disponível no idioma selecionado.
Chapter 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 Copiar o linkLink copiado para a área de transferência!
You can check RHACS policies during builds.
Procedure
- Configure policies that apply to the build stage of the container lifecycle.
- Integrate with the registry that images are pushed to during the build.
2.1.1. Checking existing build-time policies Copiar o linkLink copiado para a área de transferência!
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.1.1. Deploy stage enforcement Copiar o linkLink copiado para a área de transferência!
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.
2.2. Configuring registry integration Copiar o linkLink copiado para a área de transferência!
To scan images, you must provide Red Hat Advanced Cluster Security for Kubernetes with access to the image registry you are using in your build pipeline.
2.2.1. Checking for existing registry integration Copiar o linkLink copiado para a área de transferência!
You can use the RHACS portal to check if you have already integrated with a registry.
Procedure
-
In the RHACS portal, go to Platform Configuration
Integrations. - Under the Image Integration section, look for highlighted Registry tiles. The tiles also list the number of items already configured for that tile.
If none of the Registry tiles are highlighted, you must first integrate with an image registry.
2.3. Configuring access Copiar o linkLink copiado para a área de transferência!
RHACS provides the roxctl command-line interface (CLI) to make it easy to integrate RHACS policies into your build pipeline. The roxctl CLI prints detailed information about problems and how to fix them so that developers can maintain high standards in the early phases of the container lifecycle.
To securely authenticate to the Red Hat Advanced Cluster Security for Kubernetes API server, you must create an API token.
2.3.1. Exporting and saving the API token Copiar o linkLink copiado para a área de transferência!
Procedure
After you have generated the authentication token, export it as the
ROX_API_TOKENvariable by entering the following command:export ROX_API_TOKEN=<api_token>
$ export ROX_API_TOKEN=<api_token>Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional): You can also save the token in a file and use it with the
--token-fileoption by entering the following command:roxctl central debug dump --token-file <token_file>
$ roxctl central debug dump --token-file <token_file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note the following guidelines:
-
You cannot use both the
-password(-p) and the--token-fileoptions simultaneously. -
If you have already set the
ROX_API_TOKENvariable, and specify the--token-fileoption, theroxctlCLI uses the specified token file for authentication. -
If you have already set the
ROX_API_TOKENvariable, and specify the--passwordoption, theroxctlCLI uses the specified password for authentication.
2.3.2. Installing the roxctl CLI by downloading the binary Copiar o linkLink copiado para a área de transferência!
You can install the roxctl CLI to interact with Red Hat Advanced Cluster Security for Kubernetes from a command-line interface. You can install roxctl on Linux, Windows, or macOS.
2.3.2.1. Installing the roxctl CLI on Linux Copiar o linkLink copiado para a área de transferência!
You can install the roxctl CLI binary on Linux by using the following procedure.
roxctl CLI for Linux is available for amd64, arm64, ppc64le, and s390x architectures.
Procedure
Determine the
roxctlarchitecture for the target operating system:arch="$(uname -m | sed "s/x86_64//")"; arch="${arch:+-$arch}"$ arch="$(uname -m | sed "s/x86_64//")"; arch="${arch:+-$arch}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the
roxctlCLI:curl -L -f -o roxctl "https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Linux/roxctl${arch}"$ curl -L -f -o roxctl "https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Linux/roxctl${arch}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make the
roxctlbinary executable:chmod +x roxctl
$ chmod +x roxctlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Place the
roxctlbinary in a directory that is on yourPATH:To check your
PATH, execute the following command:echo $PATH
$ echo $PATHCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify the
roxctlversion you have installed:roxctl version
$ roxctl versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2.2. Installing the roxctl CLI on macOS Copiar o linkLink copiado para a área de transferência!
You can install the roxctl CLI binary on macOS by using the following procedure.
roxctl CLI for macOS is available for amd64 and arm64 architectures.
Procedure
Determine the
roxctlarchitecture for the target operating system:arch="$(uname -m | sed "s/x86_64//")"; arch="${arch:+-$arch}"$ arch="$(uname -m | sed "s/x86_64//")"; arch="${arch:+-$arch}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the
roxctlCLI:curl -L -f -o roxctl "https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Darwin/roxctl${arch}"$ curl -L -f -o roxctl "https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Darwin/roxctl${arch}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Remove all extended attributes from the binary:
xattr -c roxctl
$ xattr -c roxctlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Make the
roxctlbinary executable:chmod +x roxctl
$ chmod +x roxctlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Place the
roxctlbinary in a directory that is on yourPATH:To check your
PATH, execute the following command:echo $PATH
$ echo $PATHCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify the
roxctlversion you have installed:roxctl version
$ roxctl versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2.3. Installing the roxctl CLI on Windows Copiar o linkLink copiado para a área de transferência!
You can install the roxctl CLI binary on Windows by using the following procedure.
roxctl CLI for Windows is available for the amd64 architecture.
Procedure
Download the
roxctlCLI:curl -f -O https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Windows/roxctl.exe
$ curl -f -O https://mirror.openshift.com/pub/rhacs/assets/4.9.0/bin/Windows/roxctl.exeCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify the
roxctlversion you have installed:roxctl version
$ roxctl versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.3. Running the roxctl CLI from a container Copiar o linkLink copiado para a área de transferência!
The roxctl client is the default entry point in the RHACS roxctl image. To run the roxctl client in a container image:
Prerequisites
- You must first generate an authentication token from the RHACS portal.
Procedure
Log in to the
registry.redhat.ioregistry.docker login registry.redhat.io
$ docker login registry.redhat.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow Pull the latest container image for the
roxctlCLI.docker pull registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0
$ docker pull registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow
After you install the CLI, you can run it by using the following command:
docker run -e ROX_API_TOKEN=$ROX_API_TOKEN \ -it registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0 \ -e $ROX_CENTRAL_ADDRESS <command>
$ docker run -e ROX_API_TOKEN=$ROX_API_TOKEN \
-it registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0 \
-e $ROX_CENTRAL_ADDRESS <command>
In Red Hat Advanced Cluster Security Cloud Service (RHACS Cloud Service), when using roxctl commands that require the Central address, use the Central instance address as displayed in the Instance Details section of the Red Hat Hybrid Cloud Console. For example, use acs-ABCD12345.acs.rhcloud.com instead of acs-data-ABCD12345.acs.rhcloud.com.
Verification
Verify the
roxctlversion you have installed.docker run -it registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0 version
$ docker run -it registry.redhat.io/advanced-cluster-security/rhacs-roxctl-rhel8:4.9.0 versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Integrating with your CI pipeline Copiar o linkLink copiado para a área de transferência!
After you have finished these procedures, the next step is to integrate with your CI pipeline.
Each CI system might require a slightly different configuration.
2.4.1. Using Jenkins Copiar o linkLink copiado para a área de transferência!
Use the StackRox Container Image Scanner Jenkins plugin for integrating with Jenkins. You can use this plugin in both Jenkins freestyle projects and pipelines.
2.4.2. Using CircleCI Copiar o linkLink copiado para a área de transferência!
You can integrate Red Hat Advanced Cluster Security for Kubernetes with CircleCI.
Prerequisites
-
You have a token with
readandwritepermissions for theImageresource. - You have a username and password for your Docker Hub account.
Procedure
- Log in to CircleCI and open an existing project or create a new project.
- Click Project Settings.
- Click Environment variables.
Click Add variable and create the following three environment variables:
- Name: STACKROX_CENTRAL_HOST - The DNS name or IP address of Central.
- Name: ROX_API_TOKEN - The API token to access Red Hat Advanced Cluster Security for Kubernetes.
- Name: DOCKERHUB_PASSWORD - The password for your Docker Hub account.
- Name: DOCKERHUB_USER - The username for your Docker Hub account.
-
Create a directory called
.circleciin the root directory of your local code repository for your selected project, if you do not already have a CircleCI configuration file. Create a
config.ymlconfiguration file with the following lines in the.circlecidirectory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you already have a
config.ymlfile for CircleCI in your repository, add a new jobs section with the specified details in your existing configuration file.- After you commit the configuration file to your repository, go to the Jobs queue in your CircleCI dashboard to verify the build policy enforcement.