Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Trivy] Protect your application by Trivy

Posted on May 3, 2023August 28, 2023 By nim No Comments on [Trivy] Protect your application by Trivy

Contents

Toggle
  • 1) Bacsic Trivy
    • Sample Trivy Scan Table Report
  • 2) Handons with Trivy
    • 2.1) Trivy Image Scan – Docker
    • 2.2) Scan application packages
  • 3) Using Trivy ignore.

1) Bacsic Trivy

Trivy is a simple and comprehensive vulnerability scanner for containers and other artifacts.

docker run --rm -v $WORKSPACE:/root/.cache/ aquasec/trivy:0.17.2 --exit-code 0 --severity HIGH nginx

When you use --exit-code 0, you are telling Trivy to always return an exit code of 0, regardless of whether vulnerabilities are found or not. This means that even if Trivy detects vulnerabilities that match the specified severity, the command will still be considered successful.

If you want Trivy to return a non-zero exit code when vulnerabilities are found, you can either remove the --exit-code flag or set it to a non-zero value (e.g., --exit-code 1). This way, when vulnerabilities are found during the scan, Trivy will return a non-zero exit code, indicating that there is an issue that needs to be addressed.

docker run --rm -v $WORKSPACE:/root/.cache/ aquasec/trivy:0.17.2 --exit-code 1 --severity HIGH nginx

–format value : format (table, json, template) (default: “table”)
–exit-code value : Exit code when vulnerabilities were found (default: 0)
–list-all-pkgs : enabling the option will output all packages regardless of vulnerability

Sample Trivy Scan Table Report

2) Handons with Trivy

2.1) Trivy Image Scan – Docker

Ta sẽ run trivy via container và trivy sẽ đi scan public image python:3.4-alpine

docker run -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy:0.41.0 image python:3.4-alpine

Tiện mình cũng kiểm tra luôn là exit-code cho lần run này là bao nhiêu thì nó echo $? là 0
Và nếu run như này thì trên pipeline nó sẽ không bị dừng lại hay report là pipeline failed.

Nếu bạn chỉ cần report các severity is CRITICAL

docker run -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy:0.41.0 image python:3.4-alpine --exit-code 1 --severity CRITICAL

Và đây là report:

python:3.4-alpine (alpine 3.9.2)
================================
Total: 4 (CRITICAL: 4)

┌─────────────┬────────────────┬──────────┬───────────────────┬───────────────┬──────────────────────────────────────────────────────────┐
│   Library   │ Vulnerability  │ Severity │ Installed Version │ Fixed Version │                          Title
                 │
├─────────────┼────────────────┼──────────┼───────────────────┼───────────────┼──────────────────────────────────────────────────────────┤
│ libbz2      │ CVE-2019-12900 │ CRITICAL │ 1.0.6-r6          │ 1.0.6-r7      │ bzip2: out-of-bounds write in function BZ2_decompress    │
│             │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2019-12900               │
├─────────────┼────────────────┤          ├───────────────────┼───────────────┼──────────────────────────────────────────────────────────┤
│ musl        │ CVE-2019-14697 │          │ 1.1.20-r4         │ 1.1.20-r5     │ musl libc through 1.1.23 has an x87 floating-point stack │
│             │                │          │                   │               │ adjustment im ......
                 │
│             │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2019-14697               │
├─────────────┤                │          │                   │               │
                 │
│ musl-utils  │                │          │                   │               │
                 │
│             │                │          │                   │               │
                 │
│             │                │          │                   │               │
├─────────────┼────────────────┤          ├───────────────────┼───────────────┼──────────────────────────────────────────────────────────┤
│ sqlite-libs │ CVE-2019-8457  │          │ 3.26.0-r3         │ 3.28.0-r0     │ sqlite: heap out-of-bound read in function rtreenode()   │
│             │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2019-8457                │
└─────────────┴────────────────┴──────────┴───────────────────┴───────────────┴──────────────────────────────────────────────────────────┘

root@LP11-D7891:~# echo $?
1

Bạn sẽ thấy chúng ta run exit-code được report là 1.
nếu bạn chạy pipeline thì khả năng cao là pipeline sẽ dùng lại.

--light: This flag enables the “light mode” for the vulnerability database. In light mode, Trivy downloads a smaller database with less detailed vulnerability information, which is faster and uses less disk space.

Bạn có thể bắt trước file .sh này để design scan cho project của bạn.

2.2) Scan application packages

Bạn cũng có thể scan application packages.

3) Using Trivy ignore.

Nếu có 1 số lỗi và bạn muốn Trivy ignore thì có thể sài cách sau:

Mình gặp lỗi sau:

/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5/api_op_GetAccessKeyInfo.go (secrets)
=================================================================================================
Total: 1 (CRITICAL: 1)

CRITICAL: AWS (aws-access-key-id)
════════════════════════════════════════
AWS Access Key ID
────────────────────────────────────────
 /go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/sts@v1.21.5/api_op_GetAccessKeyInfo.go:19 (added by 'RUN /bin/sh -c go mod download # buildki')
────────────────────────────────────────
  17   
  18   // Returns the account identifier for the specified access key ID. Access keys
  19 [ // consist of two parts: an access key ID (for example, ******************** ) and
  20   // a secret access key (for example, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY ).

Lỗi trên là lib của aws người ta có bỏ aws key example.
Và trivy bắt lỗi trên.

Sau khi nghiên cứu trivy action của github thì mình nhận ra rằng
đầu tiên bạn tạo 1 file bất kì trong.

Mình tạo 1 file request-trivy-ignore.txt

Bạn sử dụng trivyIgnores: ‘request-trivy-ignore.txt’

- name: Run Trivy vulnerability scanner (CRITICAL)
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: ${{ secrets.DOCKER_HUB_USERNAME }}/zeus-rotations:${{ env.RELEASE_VERSION }}
          format: 'table'
          exit-code: '1'
          severity: 'CRITICAL'
          trivyIgnores: 'request-trivy-ignore.txt'
          #https://github.com/aquasecurity/trivy/issues/4826
          #skip-files: '/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/sts@v1.21.4/api_op_GetAccessKeyInfo.go'
          #skip-dirs: '/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service'
DevSecOps

Post navigation

Previous Post: [Terraform] Manage Secrets in Terraform (2023)
Next Post: [Monitoring] Understand percentiles in monitoring.

More Related Articles

[Vulnerability] CVE-2024-6387 – Critical vulnerability in OpenSSH DevSecOps
[DevSevOps] How to Install OpenVAS DevSecOps
[DevSecOps] Remove the secrets on Git. DevSecOps
[DAST] OWASP ZAP – Understand about Dynamic Application Security Testing DevSecOps
[Snyk] Scan your code quickly to prevent attack form Hackers. DevSecOps
How do companies ship code to production? Coding

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.