Sonatype Container Security
Sonatype Container Security is a comprehensive security solution for the entire container build time pipeline; safeguarding your containerized applications by protecting them with unmatched vulnerability detection and automatic policy enforcement during build time.
Integrates within CI/CD pipelines to scan and report CVE vulnerabilities within container images
Scan early in the development process to prevent vulnerable images from deploying
Prerequisites for Sonatype Container Security
MacOS or Linux
A running instance of the docker client
Podman provides wrapper commands ("docker") that mimic the behavior of docker commands and is also supported.
Set the environment variables (as needed)
Usage of Sonatype Container Security is included in the base Lifecycle subscription
A license for Sonatype Container Security is required for support from the Sonatype Technical Support team.
Note
Container scanning using Windows OS is not supported. The Azure Devops plugin supports container security build time container: scanning, provided the agent uses macOS or Linux and the other prerequisites are met.
Windows users should refer to Docker Container Analysis)
Scanning with Sonatype Container Security
Sonatype Container Security uses the docker client to analyze the container as a scan target when using a Lifecycle scanner. Environment variables may need to be configured depending on where the image is located and which scanner you use.
Scanning a local image
This will look for an image in your local docker instance and scan it when found. This is useful for scanning images built locally and before pushing them to a registry.
Scanning a local image using the default configuration does not require setting environment variables. Use the container:<image>:<version>
format as the scan target.
container:alpine:3.4
Example with the Sonatype CLI
java -jar nexus-iq-cli*.jar \ -a admin:admin123 \ -i test-app \ -t build \ -s http://localhost:8070 \ container:alpine:3.4
Refer to the Sonatype CLI documentation for parameter details.
Scanning an application along with the container
Analyze an application and container simultaneously by specifying both as targets in the CLI command. Use a space between the path to the application and the container.
/app_path container:alpine:3.4
Example with application binary and base container
java -jar nexus-iq-cli*.jar \ -a admin:admin123 \ -i test-app \ -t build \ -s http://localhost:8070 \ ./my_application.war container:alpine:3.4
Scanning a remote image
Include the container's url to scan an image stored on a remote server. We recommend you set the registry's username and password environment variables to authenticate on the remote registry. Credentials are required for private images.
export NEXUS_CONTAINER_IMAGE_REGISTRY_USER=anyuser export NEXUS_CONTAINER_IMAGE_REGISTRY_PASSWORD=xxxxxxxxxxxxxx
java -jar nexus-iq-cli*.jar \ -a admin:admin123 \ -i test-app \ -t build \ -s http://localhost:8070 \ container:http://registry.hub.docker.com/library/alpine:3.4
Running a scan from Jenkins
Requirements are a running instance of Jenkins with the Sonatype Platform plugin installed and configured to run policy evaluations in Jenkins.
Consult the Jenkins documentation for examples of setting environment variables.
For this example, the scanPattern
of container:
is used to target the container.
Create a new pipeline project in Jenkins
Enter and update the example script from below into the Pipeline section
Save the pipeline script and run the build in Jenkins
Once complete, follow the link to the results report
pipeline { agent any environment { NEXUS_CONTAINER_IMAGE_REGISTRY_USER = {anyuser} NEXUS_CONTAINER_IMAGE_REGISTRY_PASSWORD = {password} } stages { stage('Policy') { steps { nexusPolicyEvaluation ( advancedProperties: '', enableDebugLogging: false, failBuildOnNetworkError: false, iqApplication: selectedApplication('test-app'), iqScanPatterns: [ [scanPattern: 'container:http://registry.hub.docker.com/library/alpine:3.4'], [scanPattern: '**/my_application.war'] ], iqStage: 'build', jobCredentialsId: '' ) } } } }
Running a scan on Podman without Docker
If you don't have Docker, you may use Podman as an alternative container runtime. Podman is a daemonless container engine for developing, managing, and running OCI (Open Containers Initiative) Containers and Container Images.
Follow the steps below to scan with Sonatype Container Security using Podman instead of Docker:
Verify that the
docker
command isn’t found on your system:% docker zsh: command not found: docker
Confirm that Podman is installed by running the
podman
command without any arguments. This should display usage information and available options.% podman
Alias Docker to Podman or create a symlink that points docker’s path (
/usr/local/bin/docker
) to Podman (/opt/podman/bin/podman
). Keep in mind that paths might change depending on your specific environment:% sudo ln -s $(which podman) /usr/local/bin/docker
Verify the symlink was created correctly:
% ls -al /usr/local/bin/docker
This should return
lrwxrwxrwx 1 root root 17 Jul 10:45 /usr/local/bin/docker -> /opt/podman/bin/podman
. Ensure the path and target are as expected.The symbolic link allows you to use the
docker
command, which will execute thepodman
binary.Log in to the container registry:
% podman login
Enter your username and password. If successful, you'll see the message "Login Succeeded!"
Run your container scan:
% java -jar /Users/[your username]/Applications/nexus-iq-server-1.176.0-01-bundle/nexus-iq-cli.1.76.0-01.jar -i ContainerScan -t stage-release -s http://localhost:8070 -a [username]:[password] container:nodered/node-red:2.0.3
The report will be generated without requiring a running Docker daemon, using Podman instead.
Sonatype Container Security environment variables
These environment variables are to set the authentication to remote servers.
Environment Variable | Example Value |
---|---|
| <registry_username> |
| <registry_password> |
These environment variables may be set to override the default configuration.
When using the mount path for Sonatype Container, the user requires write permissions to the location specified at the mount path. Write permission to /tmp
is required when the default value is used.
Environment Variable | Default Value |
---|---|
| docker |
| /var/run/docker.sock:/var/run/docker.sock |
| "" |
| scanner |
| https://registry.hub.docker.com/neuvector |
| <dockerhub username> |
| <dockerhub password> |
| /tmp |
| false |
FAQs
How does Sonatype Lifecycle evaluate containers?
Sonatype Lifecycle leverages Sonatype Container Security to directly provide information about your images and registries back in the same familiar Lifecycle report, alongside other application vulnerabilities and evaluation results.
Where can I integrate Sonatype Container Security scanning into my SDLC?
Sonatype Container Security scanning in Lifecycle is currently available in the CLI and the Jenkins, Bamboo CI, and Gitlab CI plugins.
How can I scan with an SELinux image?
Support for the environmental variable NEXUS_CONTAINER_SCANNING_BIND_MOUNT_SHARED
. Setting the property to true will include the ':z'
option in the request allowing the bind mount content to be shared among multiple containers. This is something that is needed when using SELinux
.
Details are found in the Docker documentation.
Why are components discovered by Sonatype Container Security showing the component's license name as "Not Provided"?
The Sonatype Container Security scan does not show the license information for all the detected components. These are OS-level components where the identity information is provided by a third-party source that only provides vulnerability information. There is no way to get the license information at this time. This feature has been raised as an enhancement request. Submit your interest on ideas.sonatype.com
Why does the component overview page only show one version?
The component overview page only shows one version because NeuVector's provided component identity information does not include other versions of the component data.