Security Study/Docker

์˜คํ”ˆ์†Œ์Šค๋ฅผ ์ด์šฉํ•œ docker(container)์ทจ์•ฝ์  ์Šค์บ”(trivy)

๐“›๐“พ๐“ฌ๐“ฎ๐“ฝ๐“ฎ_๐“ข๐“ฝ๐“ฎ๐“ต๐“ต๐“ช 2022. 11. 22.
728x90
๋ฐ˜์‘ํ˜•

ํ•ด๋‹น ๋ธ”๋กœ๊ทธ๋Š” ํ•ดํ‚น ๋ฐ ๋ณด์•ˆ ๋ธ”๋กœ๊ทธ๋กœ ๊ณต๋ถ€ ๋ฐ ์—ฐ๊ตฌ์šฉ์œผ๋กœ ์ž‘์„ฑ๋˜์–ด์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ดํ‚น ์‹œ๋„ ๋ฐ ์‹ค์ œ ๊ณต๊ฒฉ์„ ์‹œ๋„ํ•˜์—ฌ ์ผ์–ด๋‚˜๋Š” ๋ชจ๋“  ์ฑ…์ž„์€ ๋ณธ์ธ(๋”ฐ๋ผํ•œ์ž)์—๊ฒŒ ์žˆ์Œ์„ ์•Œ๋ ค๋“œ๋ฆฌ๋ฉฐ, ๊ธ€์“ด์ด๋Š” ์•„๋ฌด๋Ÿฐ ์ฑ…์ž„์„ ์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ผญ ๊ณต๋ถ€ ๋ฐ ์—ฐ๊ตฌ์šฉ์œผ๋กœ๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ์ฃผ์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

docker๋ฅผ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด ๋งŽ์€ ํŽธ๋ฆฌํ•จ์ด ์กด์žฌํ•œ๋‹ค. ๊ฐ€๋”์€ https://hub.docker.com/ ์—์„œ ์ œ๊ณต๋˜๋Š” ์ด๋ฏธ์ง€๋“ค์ด ์•ˆ์ „ํ•œ๊ฐ€? ๋ผ๋Š” ์˜๋ฌธ์„ ๊ฐ€์งˆ์ˆ˜ ์žˆ๋‹ค. ๋‹ค์–‘ํ•œ ์ทจ์•ฝ์  ์Šค์บ๋„ˆ๋“ค์ด ์žˆ์ง€๋งŒ ์˜ค๋Š˜์€ trivy๋ผ๋Š” ์ทจ์•ฝ์  ์Šค์บ๋„ˆ๋ฅผ ์†Œ๊ฐœ ๋ฐ ์‚ฌ์šฉ๋ฒ•์„ ์ž‘์„ฑํ•  ์˜ˆ์ •์ด๋‹ค.

 

trivy๋Š” aquasecurity์—์„œ ์ œ๊ณตํ•˜๋Š” ๋„๊ตฌ๋กœ ์„ค์น˜๋„ ์‰ฝ๊ณ  ์‚ฌ์šฉํ•˜๊ธฐ๋„ ์‹ถ๋‹ค.
๊ณต์‹ github๋Š” https://github.com/aquasecurity/trivy์—ฌ๊ธฐ์ด๋‹ค.

 

GitHub - aquasecurity/trivy: Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories

Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more - GitHub - aquasecurity/trivy: Find vulnerabilities, misconfigurations, secrets,...

github.com

์ด์ œ ์„ค์น˜ํ•˜๋Š” ๋ฒ•์„ ๋ณด์ž ์‚ฌ์‹ค ๋ช…๋ น์–ด ํ•œ์ค„์ด๋ฉด ์„ค์น˜๊ฐ€ ๋‹ค๋˜๊ธฐ ๋•Œ๋ฌธ์— ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋ž„ ๊ฒƒ๋„ ์—†๋‹ค.

apt-get install trivy

yum install trivy

pacman -S trivy

brew install aquasecurity/trivy/trivy

sudo port install trivy

docker run aquasec/trivy

์ด๋ ‡๊ฒŒ OS๋ณ„๋กœ ์ด์ œ ์„ค์น˜ํ•˜๋Š” ๋ช…๋ น์–ด๋“ค์ด๋‹ค.

ํ•ด๋‹น trivy์˜ ๊ฒฝ์šฐ ์ง€์›๋˜๋Š” ๊ฒƒ๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

๊ณต์‹ github์— ๋”ฐ๋ฅด๋ฉด 

Targets:

  • Container Image
  • Filesystem
  • Git repository (remote)
  • Kubernetes cluster or resource

Scanners:

  • OS packages and software dependencies in use (SBOM)
  • Known vulnerabilities (CVEs)
  • IaC misconfigurations
  • Sensitive information and secrets

์ด๋ฉฐ, ์‚ฌ์šฉ๋ฒ•์€ trivy -h ๋ฅผ ํ†ตํ•˜์—ฌ ์•Œ์ˆ˜์žˆ์ง€๋งŒ ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ๋ฒ•๋“ค์„ ์•Œ์•„๋ณด๋ฉด

์ด๋ฏธ์ง€์— ๋Œ€ํ•œ CVE ์ทจ์•ฝ์  ์Šค์บ”์„ ํ•˜๊ณ  ์‹ถ์„ ๊ฒฝ์šฐ

trivy image {image}

ex) hub.docker.com์—์„œ ubuntu์ด๋ฏธ์ง€๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐ›์•„ ํ™•์ธํ•˜๊ณ  ์‹ถ์„ ๊ฒฝ์šฐ
trivy image ubuntu

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค.

total ์ทจ์•ฝ์ ๊ณผ low medium high critical ์ด๋ ‡๊ฒŒ ๋‚˜๋ˆ„์–ด์„œ ๋‚˜ํƒ€๋‚ด์–ด์ค€๋‹ค.

 

๋งŒ์•ฝ high, critical๋งŒ ๋ณด๊ณ  ์‹ถ์œผ๋ฉด ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•„ํ„ฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

trivy image --severity HIGH,CRITICAL ubuntu

repo์—์„œ ๊ฐ€์ ธ์˜จ ์ด๋ฏธ์ง€๊ฐ€ ์•„๋‹Œ docker์— ์žˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ ๊ฒ€ํ•˜๊ณ  ์‹ถ์„ ๊ฒฝ์šฐ์—” ์ด๋ ‡๊ฒŒํ•˜๋ฉด ๋œ๋‹ค.

trivy images {์ด๋ฏธ์ง€ ID}

๊ฒฐ๊ณผ๋Š” ๋™์ผํ•˜๊ฒŒ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ์•Œ์ˆ˜ ์žˆ๋‹ค.

 

์ž ๊ทธ๋Ÿผ ํ•œํŽธ์œผ๋กœ ์ƒ๊ฐํ•ด๋ณด๋ฉด dockerํ™˜๊ฒฝ์— ์ ‘์†ํ•ด์žˆ์„ ๊ฒฝ์šฐ์—”?

์˜ˆ๋ฅผ ๋“ค์–ด cloud ํ™˜๊ฒฝ์— ์„ค์น˜ํ•ด์„œ ์ ‘์†์„ ํ•ด์„œ ์ปจํ…Œ์ด๋„ˆ์— ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ์ƒํ™ฉ์—์„  ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ?

 

๊ทธ๋•Œ๋Š” ํ•ด๋‹น ํ™˜๊ฒฝ์— trivy๊ฐ€ ์„ค์น˜๋˜์–ด์žˆ์„ ๊ฒฝ์šฐ

์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด๋œ๋‹ค.

cd /
//root ๊ฒฝ๋กœ๋กœ ์ด๋™
trivy fs .
//ํ˜„์žฌ๊ฒฝ๋กœ๋ถ€ํ„ฐ ์ทจ์•ฝ์  ๊ฒ€์ƒ‰
//fs(filesystem)๋ช…๋ น์–ด

๊ทธ๋Ÿผ ๊ฒฐ๊ณผ๋Š” ๋™์ผํ•˜๊ฒŒ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€