Chapter 5. Setting Up Clair Security Scanning
Once you have created the necessary key and pem files from the Red Hat Quay config UI, you are ready to start up the Clair container and associated database. Once that is done, you an restart your Red Hat Quay cluster to have those changes take effect.
Procedures for running the Clair container and associated database are different on OpenShift than they are for running those containers directly on a host.
5.1. Run Clair on a Red Hat Quay OpenShift deployment Copy linkLink copied to clipboard!
To run the Clair image scanning container and its associated database on an OpenShift environment with your Red Hat Quay cluster, see Add Clair image scanning to Red Hat Quay.
5.2. Run Clair on a Red Hat Quay Basic or HA deployment Copy linkLink copied to clipboard!
To run Clair and its associated database on non-OpenShift environments (directly on a host), you need to:
- Start up a database
- Configure and start Clair
5.2.1. Get Postgres and Clair Copy linkLink copied to clipboard!
In order to run Clair, a database is required. For production deployments, MySQL is not supported. For production, we recommend you use PostgreSQL or other supported database:
- Running on machines other than those running Red Hat Quay
- Ideally with automatic replication and failover
For testing purposes, a single PostgreSQL instance can be started locally:
To start Postgres locally, do the following:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The configuration string for this test database is:
postgresql://postgres@{DOCKER HOST GOES HERE}:5432/clairtest?sslmode=disable
postgresql://postgres@{DOCKER HOST GOES HERE}:5432/clairtest?sslmode=disable
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Pull the security-enabled Clair image:
docker pull quay.io/redhat/clair-jwt:v3.2.2
docker pull quay.io/redhat/clair-jwt:v3.2.2
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make a configuration directory for Clair
mkdir clair-config cd clair-config
# mkdir clair-config # cd clair-config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.2.2. Configure Clair Copy linkLink copied to clipboard!
Clair can run either as a single instance or in high-availability mode. It is recommended to run more than a single instance of Clair, ideally in an auto-scaling group with automatic healing.
-
Create a
config.yaml
file to be used in the Clair config directory (/clair/config
) from one of the two Clair configuration files shown here. - If you are doing a high-availability installation, go through the procedure in Authentication for high-availability scanners to create a Key ID and Private Key (PEM).
- Save the Private Key (PEM) to a file (such as, $HOME/config/security_scanner.pem).
Replace the value of key_id (CLAIR_SERVICE_KEY_ID) with the Key ID you generated and the value of private_key_path with the location of the PEM file (for example, /config/security_scanner.pem).
For example, those two value might now appear as:
key_id: { 4fb9063a7cac00b567ee921065ed16fed7227afd806b4d67cc82de67d8c781b1 } private_key_path: /clair/config/security_scanner.pem
key_id: { 4fb9063a7cac00b567ee921065ed16fed7227afd806b4d67cc82de67d8c781b1 } private_key_path: /clair/config/security_scanner.pem
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Change other values in the configuration file as needed.
5.2.2.1. Clair configuration: High availability Copy linkLink copied to clipboard!
5.2.2.2. Clair configuration: Single instance Copy linkLink copied to clipboard!
5.2.3. Configuring Clair for TLS Copy linkLink copied to clipboard!
To configure Clair to run with TLS, a few additional steps are required.
5.2.3.1. Using certificates from a public CA Copy linkLink copied to clipboard!
For certificates that come from a public certificate authority, follow these steps:
- Generate a TLS certificate and key pair for the DNS name at which Clair will be accessed
-
Place these files as
clair.crt
andclair.key
in your Clair configuration directory -
Uncomment the
key_file
andcrt_file
lines underverifier_proxies
in your Clairconfig.yaml
If your certificates use a public CA, you are now ready to run Clair. If you are using your own certificate authority, configure Clair to trust it below.
5.2.3.2. Configuring trust of self-signed SSL Copy linkLink copied to clipboard!
Similar to the process for setting up Docker to trust your self-signed certificates, Clair must also be configured to trust your certificates. Using the same CA certificate bundle used to configure Docker, complete the following steps:
-
Rename the same CA certificate bundle used to set up Quay Registry to
ca.crt
Make sure the
ca.crt
file is mounted inside the Clair container under/etc/pki/ca-trust/source/anchors/
as in the example below:NoteAdd
--loglevel=debug
to thedocker run
command line for the clair container to enable debug level logging.docker run --restart=always -p 6060:6060 -p 6061:6061 \ -v /path/to/clair/config/directory:/clair/config \ -v /path/to/quay/cert/ca.crt:/etc/pki/ca-trust/source/anchors/ca.crt \ quay.io/redhat/clair-jwt:v3.2.2
# docker run --restart=always -p 6060:6060 -p 6061:6061 \ -v /path/to/clair/config/directory:/clair/config \ -v /path/to/quay/cert/ca.crt:/etc/pki/ca-trust/source/anchors/ca.crt \ quay.io/redhat/clair-jwt:v3.2.2
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Now Clair will be able to trust the source of your TLS certificates and use them to secure communication between Clair and Quay.
5.2.4. Using Clair data sources Copy linkLink copied to clipboard!
Before scanning container images, Clair tries to figure out the operating system on which the container was built. It does this by looking for specific filenames inside that image (see Table 1). Once Clair knows the operating system, it uses specific security databases to check for vulnerabilities (see Table 2).
Operating system | Files identifying OS type |
---|---|
Redhat/CentOS/Oracle | etc/oracle-release etc/centos-release etc/redhat-release etc/system-release |
Alpine | etc/alpine-release |
Debian/Ubuntu: | etc/os-release usr/lib/os-release etc/apt/sources.list |
Ubuntu | etc/lsb-release |
The data sources that Clair uses to scan containers are shown in Table 2.
You must be sure that Clair has access to all listed data sources by whitelisting access to each data source’s location. You might need to add a wild-card character (*) at the end of some URLS that may not be fully complete because they are dynamically built by code.
Data source | Data collected | Whitelist links | Format | License |
---|---|---|---|---|
Debian 6, 7, 8, unstable namespaces | ||||
Ubuntu 12.04, 12.10, 13.04, 14.04, 14.10, 15.04, 15.10, 16.04 namespaces | ||||
CentOS 5, 6, 7 namespace | ||||
Oracle Linux 5, 6, 7 namespaces | ||||
Alpine 3.3, 3.4, 3.5 namespaces | ||||
Generic vulnerability metadata | N/A |
5.2.5. Run Clair Copy linkLink copied to clipboard!
Execute the following command to run Clair:
docker run --restart=always -p 6060:6060 -p 6061:6061 \ -v /path/to/clair/config/directory:/clair/config \ quay.io/redhat/clair-jwt:v3.2.2
# docker run --restart=always -p 6060:6060 -p 6061:6061 \
-v /path/to/clair/config/directory:/clair/config \
quay.io/redhat/clair-jwt:v3.2.2
Output similar to the following will be seen on success:
To verify Clair is running, execute the following command:
curl -X GET -I http://path/to/clair/here:6061/health
curl -X GET -I http://path/to/clair/here:6061/health
If a 200 OK
code is returned, Clair is running:
HTTP/1.1 200 OK Server: clair Date: Wed, 04 May 2016 20:02:16 GMT Content-Length: 0 Content-Type: text/plain; charset=utf-8
HTTP/1.1 200 OK
Server: clair
Date: Wed, 04 May 2016 20:02:16 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8
Once Clair and its associated database are running, you man need to restart your quay application for the changes to take effect.