Hari 21: Checkov vs Trivy IaC, Mana Lebih Jago?
7 min read

Hari 21: Checkov vs Trivy IaC, Mana Lebih Jago?

Scan Terraform config dengan 2 tools: Checkov dan Trivy IaC. Hasilnya 15 vs 14 findings. Checkov lebih komprehensif, Trivy lebih praktis dengan severity level.

devsecops
terraform
checkov
trivy
iac-security
infrastructure-as-code
60-days-challenge
Share

Dua Scanner, Satu Target

Kemarin kita scan Terraform pakai Checkov dan menemukan 15 celah. Hari ini kita scan file yang persis sama pakai Trivy IaC — tool dari vendor berbeda — lalu bandingkan temuan-nya.

Kenapa pakai 2 tools? Karena tidak ada satu tool yang perfect. Setiap tool punya rule set yang berbeda, dan dengan membandingkan kita bisa lihat mana yang lebih jago.

Sidenote: rencana awalnya pakai tfsec juga, tapi tfsec sudah deprecated. Aqua Security (pembuat tfsec) sudah mengintegrasikan rule set-nya ke Trivy. Jadi cukup pakai Trivy IaC saja.

Trivy IaC: 14 Findings

Trivy punya mode khusus untuk IaC: trivy config. Command-nya simpel:

$ trivy config securebank-api/terraform/

Failures: 14 (UNKNOWN: 0, LOW: 5, MEDIUM: 2, HIGH: 6, CRITICAL: 1)

Trivy menemukan 14 findings dengan severity breakdown:

  • 1 CRITICAL — Unrestricted egress ke 0.0.0.0/0 (AWS-0104)
  • 6 HIGH — Unrestricted ingress (AWS-0107), S3 no public access block (AWS-0086/0087/0091/0093), S3 no KMS (AWS-0132)
  • 2 MEDIUM — S3 no versioning (AWS-0090), VPC no flow logging (AWS-0178)
  • 5 LOW — S3 no logging (AWS-0089), S3 no public access block general (AWS-0094), SG no description (AWS-0099, AWS-0124 x2)

Yang langsung mencolok: Trivy punya severity level. Checkov cuma Pass/Fail, tidak ada CRITICAL atau LOW.

Checkov (IaC): 15 Findings

Dari Day 20, Checkov menemukan 15 failed checks dan 6 passed checks. Semua dalam format Pass/Fail, tidak ada severity.

Perbandingan Head-to-Head

Mari kita taruh findings berdampingan. Saya kelompokkan per resource:

S3 Bucket — 11 findings

Finding Checkov (IaC) Trivy IaC Match?
No public access block ✅ 1 rule (CKV2_AWS_6) ✅ 4 rules (AWS-0086/0087/0091/0093/0094) Match — Trivy lebih granular
No access logging ✅ CKV_AWS_18 ✅ AWS-0089 (LOW) Match
No versioning ✅ CKV_AWS_21 ✅ AWS-0090 (MEDIUM) Match
No KMS encryption ✅ CKV_AWS_145 ✅ AWS-0132 (HIGH) Match
No cross-region replication ✅ CKV_AWS_144 Checkov only
No event notifications ✅ CKV2_AWS_62 Checkov only
No lifecycle configuration ✅ CKV2_AWS_61 Checkov only

Trivy memecah "no public access block" menjadi 4 rules terpisah — satu untuk setiap aspek (block ACLs, block policies, ignore ACLs, restrict buckets). Checkov pakai 1 rule saja. Tapi Checkov menemukan 3 things yang Trivy tidak: cross-region replication, event notifications, dan lifecycle configuration.

Security Group — 8 findings

Finding Checkov (IaC) Trivy IaC Match?
Ingress 0.0.0.0/0 port 22 (SSH) ✅ CKV_AWS_24 ✅ AWS-0107 (HIGH) Match — Trivy broader
Ingress 0.0.0.0/0 port 80 (HTTP) ✅ CKV_AWS_260 ✅ AWS-0107 (HIGH) Match — Trivy broader
Ingress 0.0.0.0/0 port 3389 (RDP) ✅ CKV_AWS_25 ✅ AWS-0107 (HIGH) Match — Trivy broader
Egress 0.0.0.0/0 all ports ✅ CKV_AWS_382 ✅ AWS-0104 (CRITICAL) Match
No description on SG ✅ CKV_AWS_23 ✅ AWS-0099 (LOW) Match
No description on ingress rule ✅ CKV_AWS_23 ✅ AWS-0124 (LOW) Match
No description on egress rule ✅ CKV_AWS_23 ✅ AWS-0124 (LOW) Match
SG not attached to resource ✅ CKV2_AWS_5 Checkov only

Kebalikan dari S3: Checkov lebih granular di sini. Checkov bikin rule terpisah untuk setiap port (22, 80, 3389). Trivy pakai 1 rule generic (AWS-0107) untuk semua unrestricted ingress. Tapi Checkov juga nemuin 1 thing yang Trivy tidak: SG tidak attached ke resource apapun.

VPC — 2 findings

Finding Checkov (IaC) Trivy IaC Match?
No VPC flow logging ✅ CKV2_AWS_11 ✅ AWS-0178 (MEDIUM) Match
Default SG doesn't restrict traffic ✅ CKV2_AWS_12 Checkov only

Kedua tools setuju bahwa VPC tidak punya flow logging. Checkov nemuin 1 tambahan: default SG tidak restrict traffic.

Skor Akhir

Metric Checkov (IaC) Trivy IaC
Total Failed 15 14
Total Passed 6 0
Unique Findings 5 0
Severity Level ❌ (Pass/Fail only) ✅ (CRITICAL→LOW)
Passed Checks Transparency ✅ (shows both) ❌ (only failures)

Lima Temuan yang Hanya Checkov Tangkap

  1. S3 no cross-region replication (CKV_AWS_144) — data gak direplikasi ke region lain untuk disaster recovery
  2. S3 no event notifications (CKV2_AWS_62) — gak ada notifikasi saat ada perubahan object
  3. S3 no lifecycle configuration (CKV2_AWS_61) — gak ada auto-transition ke storage class lebih murah
  4. SG not attached to resource (CKV2_AWS_5) — Security Group dibikin tapi gak dipakai
  5. Default SG doesn't restrict traffic (CKV2_AWS_12) — default SG VPC masih terbuka

Ini semua best-practice rules, bukan critical security vulnerabilities. Tapi di production, aturan-aturan ini penting untuk compliance dan cost optimization.

Trivy Tidak Punya Temuan Unik

Semua 14 findings Trivy juga ditemukan oleh Checkov. Tapi Trivy memberi nilai tambah: severity level. Dengan Trivy, kita tahu bahwa egress 0.0.0.0/0 adalah CRITICAL (paling urgent di-fix), sementara SG description yang kosong cuma LOW.

Checkov tidak membedakan — semuanya "FAILED" dengan urgency yang sama. Kalau ada 15 findings tanpa severity, mana yang harus di-fix dulu? Susah tentukan prioritas.

Cara Kedua Tools Memecah Rules Berbeda

Ini menarik. Sama-sama scan file yang sama, tapi cara pecah rules-nya berbeda:

S3 public access block:

  • Checkov: 1 rule → 1 finding
  • Trivy: 4 rules → 4 findings (block_acls, block_policies, ignore_acls, restrict_buckets)

Security Group ingress:

  • Checkov: 3 rules → 3 findings (port 22, 80, 3389 terpisah)
  • Trivy: 1 rule → 1 finding (generic unrestricted ingress)

Tidak ada yang "salah." Cuma cara melapor yang berbeda. Checkov lebih cocok untuk audit detail (port mana yang kebuka), Trivy lebih ringkas (cuma bilang "ingress kebuka").

1 Tool, 3 Mode Scan

Salah satu kelebihan Trivy: satu binary untuk tiga jenis scan.

Mode Command Fase Tujuan
FS (SCA) trivy fs . Fase 1 Scan dependency CVE
Image trivy image securebank:v1 Fase 2 Day 17 Scan container CVE
Config (IaC) trivy config terraform/ Fase 2 Day 21 Scan IaC misconfig

Tidak perlu install tool terpisah untuk tiap jenis scan. Tapi Checkov tetap punya value-add: coverage rules yang lebih luas (21 checks vs 14).

Lesson Learned

1. Tidak ada single tool yang perfect. Checkov nemuin 5 things yang Trivy tidak. Trivy kasih severity yang Checkov tidak. Pakai keduanya = coverage maksimal. Overlap findings = konfirmasi, unique findings = complementary.

2. Severity level penting untuk prioritisasi. Dengan 15 findings tanpa severity (Checkov), susah tahu mana yang urgent. Dengan Trivy, kita tahu egress 0.0.0.0/0 itu CRITICAL — di-fix dulu sebelum SG description yang kosong (LOW).

3. Cara pecah rules berbeda antar tools. Checkov bikin rule per-port (22, 80, 3389). Trivy bikin rule per-aspek (block_acls, block_policies). Tidak ada yang salah, cuma cara melapor. Pahami filosofi masing-masing tool.

4. Trivy mengintegrasikan tfsec. tfsec sudah deprecated, tapi rule set-nya hidup di Trivy IaC. Tidak perlu install tfsec terpisah. Cuma trivy config saja.

5. Passed checks berguna untuk audit. Checkov menampilkan 6 checks yang passed. Trivy hanya tampilkan failures. Passed checks = bukti compliance untuk auditor. "S3 tidak ada public READ ACL" itu juga penting untuk ditampilkan, bukan cuma yang gagal.

6. tfsec deprecated bukan berarti useless. Trivy mengadopsi semua tfsec rules. Jadi scan dengan Trivy IaC = scan dengan tfsec rule set + Aqua Security additional rules. Win-win.

Kesimpulan

Hari ini kita scan Terraform config yang sama dengan 2 tools berbeda: Checkov (IaC) dari Prisma Cloud dan Trivy IaC dari Aqua Security.

Checkov menemukan 15 findings, Trivy menemukan 14. Checkov lebih comprehensive (5 unique findings: cross-region replication, event notifications, lifecycle, SG attachment, default SG restrict). Trivy lebih praktis dengan severity level (1 CRITICAL, 6 HIGH, 2 MEDIUM, 5 LOW).

Rekomendasi: pakai keduanya di pipeline. Checkov untuk coverage, Trivy IaC untuk severity-based triage. Defense in depth — dua vendor berbeda lebih baik dari satu.

Besok: Hari 22 — IaC Scan di Pipeline — masukkan Checkov dan Trivy IaC ke GitHub Actions workflow, supaya scan berjalan otomatis setiap ada perubahan Terraform.

Repo: github.com/stayrelevantid/chalange-devsecops

Enjoyed this article? Share it!

Share

Diskusi & Komentar

Artikel Terkait