Questo contenuto non è disponibile nella lingua selezionata.
Chapter 4. Setting Up Clair Security Scanning
The Clair project is an open source engine that powers Red Hat Quay Security Scanner to detect vulnerabilities in all images within Red Hat Quay, then notify developers as those issues are discovered.
Initial setup includes configuring a Postgres database, downloading the clair image and creating the Clair configuration.
4.1. Get Postgres and Clair Copia collegamentoCollegamento copiato negli appunti!
In order to run Clair, a Postgres database is required. For production deployments, we recommend a PostgreSQL database running on machines other than those running Red Hat Quay and 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/coreos/clair-jwt:v2.0.7
docker pull quay.io/coreos/clair-jwt:v2.0.7
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
4.2. Configure Clair Copia collegamentoCollegamento copiato negli appunti!
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 in the config directory 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 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: /config/security_scanner.pem
key_id: { 4fb9063a7cac00b567ee921065ed16fed7227afd806b4d67cc82de67d8c781b1 }
private_key_path: /config/security_scanner.pem
4.2.1. Clair configuration: High availability Copia collegamentoCollegamento copiato negli appunti!
4.2.2. Clair configuration: Single instance Copia collegamentoCollegamento copiato negli appunti!
4.3. Configuring Clair for TLS Copia collegamentoCollegamento copiato negli appunti!
To configure Clair to run with TLS, a few additional steps are required.
4.3.1. Using certificates from a public CA Copia collegamentoCollegamento copiato negli appunti!
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.
4.3.2. Configuring trust of self-signed SSL Copia collegamentoCollegamento copiato negli appunti!
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/usr/local/share/ca-certificates/
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:/config -v \ /path/to/quay/cert/ca.crt:/usr/local/share/ca-certificates/ca.crt \ quay.io/coreos/clair-jwt:v2.0.7
# docker run --restart=always -p 6060:6060 -p 6061:6061 \ -v /path/to/clair/config/directory:/config -v \ /path/to/quay/cert/ca.crt:/usr/local/share/ca-certificates/ca.crt \ quay.io/coreos/clair-jwt:v2.0.7
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.
4.4. Using Clair data sources Copia collegamentoCollegamento copiato negli appunti!
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 |
4.5. Run Clair Copia collegamentoCollegamento copiato negli appunti!
Execute the following command to run Clair:
docker run --restart=always -p 6060:6060 -p \ 6061:6061 -v \ /path/to/clair/config/directory:/config \ quay.io/coreos/clair-jwt:v2.0.7
# docker run --restart=always -p 6060:6060 -p \
6061:6061 -v \
/path/to/clair/config/directory:/config \
quay.io/coreos/clair-jwt:v2.0.7
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
4.6. Continue with Quay Setup Copia collegamentoCollegamento copiato negli appunti!
Once Clair setup is complete, continue with Red Hat Quay Security Scanning with Clair.