2.4. Integrating with your CI pipeline
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 复制链接链接已复制到粘贴板!
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 复制链接链接已复制到粘贴板!
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:version: 2 jobs: check-policy-compliance: docker: - image: 'circleci/node:latest' auth: username: $DOCKERHUB_USER password: $DOCKERHUB_PASSWORD steps: - checkout - run: name: Install roxctl command: | curl -H "Authorization: Bearer $ROX_API_TOKEN" https://$STACKROX_CENTRAL_HOST:443/api/cli/download/roxctl-linux -o roxctl && chmod +x ./roxctl - run: name: Scan images for policy deviations and vulnerabilities command: | ./roxctl image check --endpoint "$STACKROX_CENTRAL_HOST:443" --image "<your_registry/repo/image_name>" - run: name: Scan deployment files for policy deviations command: | ./roxctl image check --endpoint "$STACKROX_CENTRAL_HOST:443" --image "<your_deployment_file>" # Important note: This step assumes the YAML file you'd like to test is located in the project. workflows: version: 2 build_and_test: jobs: - check-policy-compliancewhere:
<your_registry/repo/image_name>- Specifies your registry and image path.
<your_deployment_file>- Specifies the path to your deployment file.
注意If 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.