You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deploy Trivy security scanner for Cluster API based Kubernetes clusters #659
A new pipeline has been developed for the execution of Trivy in its two modes: through its official container image and using the trivy operator from the command line.
The pipeline is being executed in our test zuul deployment in order to debug possible problems and make adjustements to its code. We run it in two phases:
Update trivy vulnerability database.
Run the container for vulnerability analysis.
The vulnerabilities that this kind of scan analize are relative to the applications running in a specific namespace, hence the resulting report provides insights on which CaaS layer (k8s) components have vulnerabilities in that said namespace.
On the other hand, Trivy operator has more capabilities and provides different fine grained reports. As for now, we configured it to generate five reports with information of the current state of the cluster:
It is important to note that this is a remote scan, so in order to use the abovementioned tools, it is necessary to use the K8s kubeconfig generated during the CaaS layer deploiment. This file contains sensitive information for connecting to the cluster.
Blockers: As we are working with different kind of reports, we need to find the most optimal way to merge them in order to ensure vulnerability traceability and visibility.
Deployment of DefectDojo in Test Environments using Zuul on OpenStack
The deployment of DefectDojo is carried out in a test environment on OpenStack, using Zuul as the continuous integration (CI) system to automate the creation and configuration of this environment. DefectDojo is used as the main platform for vulnerability management, centralizing and visualizing security findings from various sources.
Steps Taken:
Environment Setup with OpenStack
Used Ansible playbooks to automate the creation of OpenStack instances. These playbooks handle tasks like installing Docker, and deploying DefectDojo using Docker Compose.
Deployment of DefectDojo with Docker Compose:
Once the OpenStack instance is provisioned, Docker and Docker Compose are configured for the deployment of DefectDojo.
The Docker Compose file defines the DefectDojo and PostgreSQL services, with data persistence through volumes in OpenStack to ensure database durability.
Challenges and Solutions
Issue: Latency in provisioning OpenStack instances and network issues.
Solution: Adjusted network policies and used Ansible scripts with retries to ensure instance provisioning. Additionally, a load balancer was configured in OpenStack to improve service availability.
Relevant Documentation
Configuration guide for OpenStack Ansible playbooks.
Python script examples for API validation of DefectDojo.
Docker Compose configuration for DefectDojo and PostgreSQL.
Development and Execution of the Trivy Container in the Zuul Pipeline
Trivy is executed as part of a security k8s scan pipeline, allowing automatic security scans of container images and Kubernetes configurations. This ensures that every code change or deployment of new images is evaluated before moving to production.
Steps Taken:
Configuration of the Zuul Pipeline for Trivy
Set up jobs in Zuul to execute security scans using Trivy whenever a new container image is execute(still TBD).
This job runs in an environment controlled by Zuul and uses Ansible playbooks to orchestrate the execution of Trivy, ensuring that all images are scanned before deployment.
Execution of Trivy and Analysis of Results
The playbook performs the following tasks:
Downloads the Trivy image from the Docker registry.
Executes Trivy to scan a specific image and generates a report in JSON format:
The generated JSON file is stored in a shared volume between Zuul and Kubernetes, where it is processed for integration.
Relevant Documentation
Ansible playbooks examples for running Trivy.
Deployment and Management of the Trivy Operator in Kubernetes
The Trivy Operator is a key component deployed in the Kubernetes cluster to automatically scan container images and cluster configurations, generating detailed reports on vulnerabilities.
Steps Taken
Deployment of the Trivy Operator
Used the Operator to configure the Trivy Operator, including:
Deployment of the Trivy Operator using helm.
Configured RoleBindings and ServiceAccounts to ensure that the Trivy Operator has the necessary permissions to access cluster resources and perform scans.
Automation and Management of Scans:
Configured the Trivy Operator to automatically scan whenever new container images or updated configurations are detected in the cluster. This is achieved through event listeners that detect changes in Deployments or Pods.
Scan results are stored in ConfigMaps in JSON format, allowing easy access and further processing.
Optimization of the Trivy Operator:
Adjusted concurrency parameters and limited the number of simultaneous scans to prevent cluster overload, especially during peak deployment times.
Relevant Documentation
Configuration guide for the Trivy Operator examples.
Documentation on integrating RoleBindings and ServiceAccounts for the operator.
Trivy-Dojo-Report-Operator: Integration and Configuration with DefectDojo
The Trivy-Dojo-Report-Operator is a specialized component that facilitates the integration between the results of the Trivy Operator scans and DefectDojo. This operator ensures that vulnerability reports generated by Trivy are automatically exported to DefectDojo, centralizing vulnerability management and improving the tracking of security findings.
Steps Taken
Deployment of the Trivy-Dojo-Report-Operator
Configured the Trivy-Dojo-Report-Operator that manages the export of security reports.
Validation and Optimization of the Integration
Validated the report export through automated tests and adjusted export scripts to ensure correct data import.
Adjusted parameters like engagementId to ensure reports are correctly associated with the right projects within DefectDojo.
Relevant Documentation
Examples of YAML for configuring the Trivy-Dojo-Report-Operator.
Documentation on the report format accepted by the DefectDojo API.
CronJob for Extracting Trivy Reports and Uploading to S3 in OpenStack
This Kubernetes CronJob automates the process of extracting vulnerability reports generated by the Trivy Operator, formats them, and uploads them to an S3 bucket hosted on an OpenStack environment. This setup ensures that the security reports are securely stored in a centralized location, facilitating further analysis and long-term storage.
This work was redone 3 times, since it was proposed to use secrets in principle, then as requested it had to be changed to use Hashicorp Vault for connection secrets, then it was asked to be searched to upload both in openstack swift and with s3 bucket and finally it was determined that only some local secrets were used with the information and only uploaded to an s3 bucket.
Steps Taken
Purpose and Requirements
The CronJob was developed to regularly extract reports stored in ConfigMaps generated by the Trivy Operator.
After extracting the JSON reports, the CronJob uses openstack client container with OpenStack's S3-compatible object storage to upload these reports to a designated S3 bucket for secure and centralized storage.
Configuration of the Kubernetes CronJob
The CronJob is configured to run at a specific interval (e.g., daily at midnight) to ensure the timely extraction and uploading of new reports. Below is the configuration of the CronJob.
Container. Uses openstack client container, which includes the necessary tools to interact with S3-compatible object storage.
Environment Variables Configures the S3 endpoint and bucket information, along with credentials stored in a Kubernetes Secret for secure access.
Command: The script executed by the container performs the following:
Uses kubectl to extract the scan.json data from ConfigMaps whose names start with "trivy-" (i.e., ConfigMaps generated by the Trivy Operator).
Saves the JSON data to a temporary file (/tmp/trivy_report.json).
Checks if the extracted report is not empty.
Generates a timestamped filename to ensure unique storage of each report.
Uses the container to upload the JSON file to the S3 bucket in OpenStack.
Logs the success or failure of the upload operation.
Setup of Secrets for S3 Access: To securely access the S3 bucket in OpenStack, a Kubernetes Secret is created to store the access keys. This Secret is referenced in the CronJob configuration to provide the necessary credentials to interact with the S3 API.
Validation and Testing: The CronJob was validated through manual runs to ensure correct extraction of reports and successful uploads to the S3 bucket. Logs from the CronJob were monitored using kubectl logs to confirm that the report extraction and upload process executed without errors.
Scheduling and Optimization: The CronJob is scheduled to run during off-peak hours (e.g., midnight) to minimize the impact on cluster performance. The temporary storage (emptyDir) is used to handle report data locally within the container, ensuring that data is not persisted unnecessarily within the cluster. The report file is deleted after uploading to minimize resource usage.
Challenges and Solutions:
Issue: Initial failures in uploading to the S3-compatible storage due to incorrect endpoint configuration.
Solution: Corrected the S3 endpoint URL to match the OpenStack S3-compatible object storage and validated access from within a Kubernetes pod.
Issue: Large report sizes caused timeouts during uploads.
Solution: Enabled multipart uploads in the AWS CLI settings and adjusted the aws s3 cp command to better handle large file uploads.
Issue: Ensuring data security during the transfer to S3.
Solution: Verified that the connection to the S3 endpoint is over HTTPS and used encrypted access keys stored securely in Kubernetes Secrets.
Relevant Documentation
Kubernetes documentation for configuring CronJobs and Secrets.
Scripts for validating the CronJob execution and extracting reports from ConfigMaps.
Working on future improvement
Automated Testing with Zuul
Configured a Zuul job that runs automated tests after deployment to verify service availability and API accessibility of DefectDojo. Curl and Python scripts are used to interact with the API and check the correct service response
Backup Automation and Cleanup
Created CronJobs in Kubernetes to automate backups of the DefectDojo database, storing them in OpenStack volumes.
Implemented a post-run job in Zuul to dismantle test instances in OpenStack and free up resources after tests are completed.
Worth noting that this specifically affects GitHub Actions (trivy-action / setup-trivy) via tag poisoning, where attackers force-pushed tags to malicious commits that executed a credential stealer in CI/CD runners.
In this case, those Actions are not used; Trivy is executed directly via Docker in Ansible, so it’s not the same attack vector.
That said, it’s still relevant from a supply chain perspective: the incident also involved malicious Trivy releases (e.g. v0.69.4) and compromised container images. So anything pulling unpinned aquasec/trivy images during that window could still have been affected.
TL;DR: not directly applicable, but part of the same incident. If still in use, images/tags should be pinned.
Activity
bitkeks commentedon Jun 14, 2024
Code of Trivy deployment to be committed to new repo: https://github.com/SovereignCloudStack/security-k8s-scan-pipeline
Spectertj commentedon Jun 14, 2024
A new pipeline has been developed for the execution of Trivy in its two modes: through its official container image and using the trivy operator from the command line.
The pipeline is being executed in our test zuul deployment in order to debug possible problems and make adjustements to its code. We run it in two phases:
The vulnerabilities that this kind of scan analize are relative to the applications running in a specific namespace, hence the resulting report provides insights on which CaaS layer (k8s) components have vulnerabilities in that said namespace.
On the other hand, Trivy operator has more capabilities and provides different fine grained reports. As for now, we configured it to generate five reports with information of the current state of the cluster:
• Vulnerability Report
• Sbom Report
• ConfigAudit Report
• Exposed Secrets Report
• Cluster Vulnerability Report
It is important to note that this is a remote scan, so in order to use the abovementioned tools, it is necessary to use the K8s kubeconfig generated during the CaaS layer deploiment. This file contains sensitive information for connecting to the cluster.
Blockers: As we are working with different kind of reports, we need to find the most optimal way to merge them in order to ensure vulnerability traceability and visibility.
bitkeks commentedon Jun 19, 2024
Work on Trivy and defectDojo in branches:
bitkeks commentedon Jun 21, 2024
@Spectertj thanks for the update today!
I have created a separate issue to track the implementation of Trivy Operator and the report operator: #669
Let's keep the Trivy Zuul pipeline stuff here, and track the operator stuff on #669.
Spectertj commentedon Jul 31, 2024
The new pipeline has been adapted to store all scanner and operator reports in an S3 bucket.
bitkeks commentedon Aug 7, 2024
This is also related to #669 no?
What's the status on SovereignCloudStack/security-k8s-scan-pipeline#1 ? Could you push and update the latest changes?
90n20 commentedon Oct 29, 2024
Sum up of the work done on the K8s side
Deployment of DefectDojo in Test Environments using Zuul on OpenStack
The deployment of DefectDojo is carried out in a test environment on OpenStack, using Zuul as the continuous integration (CI) system to automate the creation and configuration of this environment. DefectDojo is used as the main platform for vulnerability management, centralizing and visualizing security findings from various sources.
Steps Taken:
Environment Setup with OpenStack
Used Ansible playbooks to automate the creation of OpenStack instances. These playbooks handle tasks like installing Docker, and deploying DefectDojo using Docker Compose.
Deployment of DefectDojo with Docker Compose:
Once the OpenStack instance is provisioned, Docker and Docker Compose are configured for the deployment of DefectDojo.
The Docker Compose file defines the DefectDojo and PostgreSQL services, with data persistence through volumes in OpenStack to ensure database durability.
Challenges and Solutions
Solution: Adjusted network policies and used Ansible scripts with retries to ensure instance provisioning. Additionally, a load balancer was configured in OpenStack to improve service availability.
Relevant Documentation
Configuration guide for OpenStack Ansible playbooks.
Python script examples for API validation of DefectDojo.
Docker Compose configuration for DefectDojo and PostgreSQL.
Development and Execution of the Trivy Container in the Zuul Pipeline
Trivy is executed as part of a security k8s scan pipeline, allowing automatic security scans of container images and Kubernetes configurations. This ensures that every code change or deployment of new images is evaluated before moving to production.
Steps Taken:
Configuration of the Zuul Pipeline for Trivy
Set up jobs in Zuul to execute security scans using Trivy whenever a new container image is execute(still TBD).
This job runs in an environment controlled by Zuul and uses Ansible playbooks to orchestrate the execution of Trivy, ensuring that all images are scanned before deployment.
Execution of Trivy and Analysis of Results
The playbook performs the following tasks:
Relevant Documentation
Ansible playbooks examples for running Trivy.
Deployment and Management of the Trivy Operator in Kubernetes
The Trivy Operator is a key component deployed in the Kubernetes cluster to automatically scan container images and cluster configurations, generating detailed reports on vulnerabilities.
Steps Taken
Deployment of the Trivy Operator
Automation and Management of Scans:
Optimization of the Trivy Operator:
Relevant Documentation
Configuration guide for the Trivy Operator examples.
Documentation on integrating RoleBindings and ServiceAccounts for the operator.
Trivy-Dojo-Report-Operator: Integration and Configuration with DefectDojo
The Trivy-Dojo-Report-Operator is a specialized component that facilitates the integration between the results of the Trivy Operator scans and DefectDojo. This operator ensures that vulnerability reports generated by Trivy are automatically exported to DefectDojo, centralizing vulnerability management and improving the tracking of security findings.
Steps Taken
Deployment of the Trivy-Dojo-Report-Operator
Validation and Optimization of the Integration
Relevant Documentation
Examples of YAML for configuring the Trivy-Dojo-Report-Operator.
Documentation on the report format accepted by the DefectDojo API.
CronJob for Extracting Trivy Reports and Uploading to S3 in OpenStack
This Kubernetes CronJob automates the process of extracting vulnerability reports generated by the Trivy Operator, formats them, and uploads them to an S3 bucket hosted on an OpenStack environment. This setup ensures that the security reports are securely stored in a centralized location, facilitating further analysis and long-term storage.
This work was redone 3 times, since it was proposed to use secrets in principle, then as requested it had to be changed to use Hashicorp Vault for connection secrets, then it was asked to be searched to upload both in openstack swift and with s3 bucket and finally it was determined that only some local secrets were used with the information and only uploaded to an s3 bucket.
Steps Taken
Purpose and Requirements
Configuration of the Kubernetes CronJob
The CronJob is configured to run at a specific interval (e.g., daily at midnight) to ensure the timely extraction and uploading of new reports. Below is the configuration of the CronJob.
Container. Uses openstack client container, which includes the necessary tools to interact with S3-compatible object storage.
Environment Variables Configures the S3 endpoint and bucket information, along with credentials stored in a Kubernetes Secret for secure access.
Command: The script executed by the container performs the following:
Setup of Secrets for S3 Access: To securely access the S3 bucket in OpenStack, a Kubernetes Secret is created to store the access keys. This Secret is referenced in the CronJob configuration to provide the necessary credentials to interact with the S3 API.
Validation and Testing: The CronJob was validated through manual runs to ensure correct extraction of reports and successful uploads to the S3 bucket. Logs from the CronJob were monitored using kubectl logs to confirm that the report extraction and upload process executed without errors.
Scheduling and Optimization: The CronJob is scheduled to run during off-peak hours (e.g., midnight) to minimize the impact on cluster performance. The temporary storage (emptyDir) is used to handle report data locally within the container, ensuring that data is not persisted unnecessarily within the cluster. The report file is deleted after uploading to minimize resource usage.
Challenges and Solutions:
Solution: Corrected the S3 endpoint URL to match the OpenStack S3-compatible object storage and validated access from within a Kubernetes pod.
Solution: Enabled multipart uploads in the AWS CLI settings and adjusted the aws s3 cp command to better handle large file uploads.
Solution: Verified that the connection to the S3 endpoint is over HTTPS and used encrypted access keys stored securely in Kubernetes Secrets.
Relevant Documentation
Kubernetes documentation for configuring CronJobs and Secrets.
Scripts for validating the CronJob execution and extracting reports from ConfigMaps.
Working on future improvement
Automated Testing with Zuul
Configured a Zuul job that runs automated tests after deployment to verify service availability and API accessibility of DefectDojo. Curl and Python scripts are used to interact with the API and check the correct service response
Backup Automation and Cleanup
Created CronJobs in Kubernetes to automate backups of the DefectDojo database, storing them in OpenStack volumes.
Implemented a post-run job in Zuul to dismantle test instances in OpenStack and free up resources after tests are completed.
mbuechse commentedon Mar 26, 2026
For the sake of completeness: https://thehackernews.com/2026/03/trivy-security-scanner-github-actions.html
90n20 commentedon Mar 26, 2026
Good call adding this for context.
Worth noting that this specifically affects GitHub Actions (
trivy-action/setup-trivy) via tag poisoning, where attackers force-pushed tags to malicious commits that executed a credential stealer in CI/CD runners.In this case, those Actions are not used; Trivy is executed directly via Docker in Ansible, so it’s not the same attack vector.
That said, it’s still relevant from a supply chain perspective: the incident also involved malicious Trivy releases (e.g. v0.69.4) and compromised container images. So anything pulling unpinned
aquasec/trivyimages during that window could still have been affected.TL;DR: not directly applicable, but part of the same incident. If still in use, images/tags should be pinned.