Listen to this Post
Security should be at the top of mind these days. One easy step you can take to improve your security posture is to set up automated scanning of your container images. One popular tool in this area is Trivy. Trivy is an open-source scanning tool that you can integrate into your automation tools to check your images. The article from Brandon Lee shows how to use Trivy with examples.
You Should Know:
Trivy is a comprehensive and easy-to-use vulnerability scanner for container images, file systems, and Git repositories. It is designed to be integrated into CI/CD pipelines to ensure that vulnerabilities are caught early in the development process. Below are some practical steps, commands, and code snippets to help you get started with Trivy.
Installing Trivy
To install Trivy on a Linux system, you can use the following commands:
<h1>Download the Trivy binary</h1> wget https://github.com/aquasecurity/trivy/releases/download/v0.24.0/trivy_0.24.0_Linux-64bit.tar.gz <h1>Extract the binary</h1> tar -xzf trivy_0.24.0_Linux-64bit.tar.gz <h1>Move the binary to a directory in your PATH</h1> sudo mv trivy /usr/local/bin/ <h1>Verify the installation</h1> trivy --version
Scanning a Docker Image
Once Trivy is installed, you can start scanning Docker images for vulnerabilities. Here’s how you can do it:
<h1>Pull a Docker image to scan</h1> docker pull nginx:latest <h1>Scan the Docker image using Trivy</h1> trivy image nginx:latest
This command will output a detailed report of any vulnerabilities found in the image, including the severity level (e.g., CRITICAL, HIGH, MEDIUM, LOW).
Integrating Trivy with CI/CD Pipelines
Trivy can be easily integrated into CI/CD pipelines to automate the scanning process. Below is an example of how you can integrate Trivy into a GitHub Actions workflow:
name: Trivy Vulnerability Scan on: push: branches: - main jobs: scan: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 <ul> <li>name: Install Trivy run: | wget https://github.com/aquasecurity/trivy/releases/download/v0.24.0/trivy_0.24.0_Linux-64bit.tar.gz tar -xzf trivy_0.24.0_Linux-64bit.tar.gz sudo mv trivy /usr/local/bin/</p></li> <li><p>name: Scan Docker image run: trivy image nginx:latest
Scanning a File System
Trivy can also scan your local file system for vulnerabilities. This is particularly useful for checking your application dependencies.
<h1>Scan a directory for vulnerabilities</h1> trivy fs /path/to/your/project
Scanning a Git Repository
Trivy can scan a Git repository for vulnerabilities in its dependencies. This is useful for ensuring that your codebase is secure.
<h1>Scan a Git repository</h1> trivy repo https://github.com/yourusername/yourrepository.git
What Undercode Say:
Trivy is an essential tool for modern DevOps and security practices. By integrating Trivy into your workflow, you can ensure that your container images, file systems, and Git repositories are free from known vulnerabilities. This not only improves your security posture but also helps in maintaining compliance with industry standards.
Here are some additional Linux and Windows commands that can help you in your cybersecurity practices:
Linux Commands:
netstat -tuln: List all open ports on your system.iptables -L: View the current iptables firewall rules.chkconfig --list: List all services and their run levels.ls -la /var/log: View log files for security auditing.
Windows Commands:
netstat -an: Display all active connections and listening ports.netsh advfirewall show allprofiles: Display the current firewall settings.schtasks /query: List all scheduled tasks.wevtutil qe Security /f:text: Query the Security event log.
Expected Output:
By following the steps and commands outlined above, you should be able to integrate Trivy into your security practices effectively. The expected output is a detailed vulnerability report that helps you identify and mitigate security risks in your container images, file systems, and Git repositories. This will significantly enhance your overall security posture and ensure that your applications are secure from potential threats.
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅



