GitLab CI Integration with Services¶
This document explains how to use GitLab CI/CD services with the Kubernetes CINC Secure Scanner for enhanced container scanning workflows.
Overview¶
GitLab CI/CD services allow you to run Docker containers alongside your CI/CD jobs. These service containers can provide additional functionality and dependencies without cluttering your main job container. For our scanning workflows, services can provide a consistent, pre-configured environment for running CINC Auditor scans.
Benefits of Using Services¶
- Pre-installed Dependencies: Service containers can have CINC Auditor, the train-k8s-container plugin, and the SAF CLI pre-installed.
- Isolation: Scanning tools are isolated from your application code and build tools.
- Consistency: Every scan job uses the exact same scanning environment.
- Specialized Containers: Different service containers can be used for different types of scans (standard vs. distroless).
- Reduced Setup Time: Eliminates the need to install dependencies in each job.
Implementation¶
Creating Scanner Service Images¶
Create Docker images for your scanning services:
Standard Scanner Image¶
Distroless Scanner Image¶
Using Scanner Services in GitLab CI¶
See the gitlab-pipeline-examples/gitlab-ci-with-services.yml
file in the repository for a complete implementation. Here's how to define services in your .gitlab-ci.yml
file:
Communication Between Jobs and Services¶
To interact with service containers:
- Docker Commands: Use
docker cp
anddocker exec
to copy files and run commands in service containers. - File Exchange: Use temporary files to exchange data between the job and service containers.
- Container Networking: Service containers are accessible via their alias hostnames.
Considerations¶
Advantages¶
- Clean separation of concerns
- Pre-built, consistent scanning environment
- Reduced pipeline setup time
- Support for both standard and distroless scanning approaches
Potential Challenges¶
- Complexity: Adds another layer to the CI/CD configuration
- Docker-in-Docker: Requires Docker socket access or Docker-in-Docker service
- Performance: Additional overhead from running multiple containers
- Maintenance: Scanner service images need to be maintained and updated
Complete Example¶
See the gitlab-pipeline-examples/gitlab-ci-with-services.yml
file in the repository for a complete example of integrating scanner services into your GitLab CI/CD pipeline.
Workflow Diagram¶
For a visual representation of how GitLab CI services integrate with the scanning workflow, see the Workflow Diagrams document.