Configure pipeline to use STO images from private registry
Harness maintains its own set of scan images for STO-supported scanners. By default, a Harness pipeline pulls scan images from the Harness DockerHub.
This topic describes how to override the default image pull behavior and use your own private registry instead of pulling directly from the public Harness DockerHub. You can download the scan images you need, perform your own security checks on the images, upload them to a private registry, and then set up your STO steps to download images from your private registry.
To do this, you need to:
- (Optional) Create scanner images with your own SSL certificates.
- Create a connector for your private registry.
- Configure the pipeline to download images from your registry.
Create STO scanner images with your own SSL certificates (optional)
Harness STO supports three workflows for running scans with custom certificates.
In this workflow, you set up your STO scan images and pipelines to run scans as non-root and establish trust for your own proxies using custom certificates. This workflow supports any STO-compatible scanner that can run natively without root access. This workflow also supports build environments that use a self-signed proxy server between the Harness Delegate and Harness Manager.
Running container image scans as a non-root user is not currently supported.
-
Save a copy of the following Dockerfile into a folder along with the certificates you want to copy to the image.
-
Update the
FROM
,COPY
, andUSER
commands as described in the Dockerfile comments. -
Build the new image and then publish it to your private registry.
-
Update the scan step in your pipeline as follows:
- Update the Image setting to point to the new image in your registry.
- If you specified a
USER
in your Dockerfile, set the Run as User (runAsUser
) setting to the user you specified in your Dockerfile.
Dockerfile template for adding certificates to an STO scanner image
# STEP 1
# Specify the STO scanner image where you want to add your certificates
# For a list of all images in the Harness Container Registry, run the following:
# curl -X GET https://app.harness.io/registry/_catalog
FROM harness/twistlock-job-runner:latest as scanner
# FYI Root access is required to load and trust certificates
USER root
# STEP 2
# Copy your certificates to the engine
# You can copy multiple ca from completely different paths into SHARE_CA_PATH
COPY ./CERTIFICATE_1.pem ../another-folder/CERTIFICATE_2.pem /shared/customer_artifacts/certificates/
# FYI establishes trust for certificates in Python and the OS
RUN sto_plugin --trust-certs
# Optional: To trust certificates for Java for tools such as
# - Black Duck Hub
# - Checkmarx
# - Sonarqube
# - Veracode
# - NexusIQ
# RUN sh /bin/setup.sh
# STEP 3 (optional)
# Create a user and assume limited permission user
# If you set this, you need to add runAsUser setting in the scan step
# i.e., runAsUser: "1000"
USER 1000
Create a connector to your private registry
You need a Docker connector that points to your private container registry. For more information, go to Docker Connector Settings Reference.
Configure your pipeline to use images from your registry
-
Download the scan images you need from the Harness DockerHub, test and validate the images, and store them in your private registry.
warningDo not change the image names in your private registry. The image names must match the names specified by Harness; this includes the
harness/
prefix. -
By default, STO will automatically use the latest image from the public Harness registry, you might want to specify the images to use in your pipelines. This ensures that your pipelines use specific image versions. You must update this specification when you want to adopt a new version of an image.
-
Set up your pipeline to use the images from your private registry. This can be done at both the stage level and the step level for scanner steps(Blackduck, Semgrep etc.,) and Custom Scan steps. Below are the detailed steps and configurations required for each scenario.
- Override security test images for scanner steps:
- Override security test images for Custom Scan steps
Override security test images for scanner steps
Stage level override
If you want to use your private images for all steps within a stage, follow these steps:
- Navigate to the Infrastructure section in your stage.
- Go to the Advanced section.
- Configure your private registry under the Override Image Connector section.
Do not modify the names of the images in your private registry. STO will automatically look for the exact name(harness/<SCANNER_NAME>-job-runner
) based on the step added to the pipeline.
Step level override
If you want to override the image for a specific step within a stage, follow these steps:
- Navigate to the specific STO step in the pipeline.
- Go to the Additional Configuration section in the step configuration.
- Set your private registry and tag under Override Security Test Image section. By default, the step will look for the
latest
tag if no tag is provided.
Do not modify the names of the images in your private registry. STO will automatically look for the exact name(harness/<SCANNER_NAME>-job-runner
) based on the step added to the pipeline.
Override security test images for Custom Scan steps
The Custom Scan step uses the sto-plugin
image to launch the appropriate scanner image(internally called as runner) based on the step configuration. You have the option to either override both the sto-plugin
image and the scanner image, or simply override the scanner image while keeping the sto-plugin
image unchanged.
To override the scanner image in a Custom Scan step, add the following settings in the Additional Configuration section of the Custom Scan step:
runner_registry_domain
: The URL of the registry where the images are stored. The supported format is<_domain_>/<_directory_>
(such as, gcr.io/gcr-prod). Do not include the scheme (such as http:// or https://).runner_registry_image_prefix
: set this toharness
(Do not change this setting)runner_registry_username
: The username of your registryrunner_registry_token
: The token to access your registryrunner_tag
: The image tag
If you want to override the sto-plugin
image for the Custom Scan steps, you can configure your private registry either at the stage level or step level, based on your requirements. Refer to the stage level or step level sections above for instructions, as they are the same.
If you specified a USER
in the Dockerfile for your scan image, configure the scan step to run as the user:
- Open the scanner step and expand Additional Configuration.
- Set the Run as User (
runAsUser
) setting to the user you specified in your Dockerfile.