Snyk Code Security — วิธีใช้ Snyk

Snyk Developer Security Platform

Snyk เป็น Developer Security Platform ที่ตรวจสอบ Vulnerabilities ตั้งแต่ Code, Dependencies, Containers ไปจนถึง Infrastructure as Code ทำงานร่วมกับ Developer Workflow ตรวจจับปัญหาตั้งแต่เขียน Code ใน IDE
เนื้อหาเกี่ยวข้อง — ดูเพิ่มเติมเรื่อง Prometheus Federation Testing Strategy QA
Snyk มี 4 Products หลัก ได้แก่ Snyk Code (SAST), Snyk Open Source (SCA), Snyk Container และ Snyk IaC ใช้ร่วมกันได้ครอบคลุม Security ทั้ง Software Development Lifecycle
เนื้อหาเกี่ยวข้อง — ดูเพิ่มเติมเรื่อง Demand Zone — คู่มือฉบับสมบูรณ์ 2026
Snyk CLI และ Configuration
# === Snyk Installation และ Configuration ===
# 1. ติดตั้ง Snyk CLI
npm install -g snyk
# หรือ
brew install snyk
# หรือ
pip install snyk
# 2. Authentication
snyk auth
# หรือใช้ Token
export SNYK_TOKEN="your-api-token"
# 3. Snyk Open Source (SCA) — ตรวจ Dependencies
# ตรวจ Vulnerabilities
snyk test
# ตรวจพร้อม Fix Suggestions
snyk test --severity-threshold=high
# Monitor (ส่งผลไป Snyk Dashboard)
snyk monitor
# ตรวจ Specific Package Manager
snyk test --file=requirements.txt # Python
snyk test --file=package.json # Node.js
snyk test --file=pom.xml # Java
snyk test --file=go.mod # Go
snyk test --file=Gemfile.lock # Ruby
# 4. Snyk Code (SAST) — ตรวจ Source Code
snyk code test
# ตรวจเฉพาะ Directory
snyk code test --path=./src
# Output เป็น JSON
snyk code test --json > snyk-code-report.json
# 5. Snyk Container — ตรวจ Docker Image
snyk container test node:18-alpine
snyk container test myapp:latest --file=Dockerfile
# Monitor Container
snyk container monitor myapp:latest
# 6. Snyk IaC — ตรวจ Infrastructure as Code
snyk iac test
snyk iac test terraform/
snyk iac test kubernetes/deployment.yaml
snyk iac test --severity-threshold=high
# 7. ดู Report
snyk test --json | snyk-to-html -o report.html
echo "Snyk configured"
echo " Open Source: snyk test"
echo " Code (SAST): snyk code test"
echo " Container: snyk container test"
echo " IaC: snyk iac test"
CI/CD Integration

# === GitHub Actions — Snyk Security Pipeline ===
# .github/workflows/snyk-security.yml
name: Snyk Security
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * 1' # ทุกวันจันทร์ 06:00
env:
SNYK_TOKEN: }
jobs:
snyk-open-source:
name: Dependency Scan (SCA)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Snyk Open Source Test
uses: snyk/actions/node@master
continue-on-error: true
with:
command: test
args: --severity-threshold=high
- name: Snyk Open Source Monitor
uses: snyk/actions/node@master
if: github.ref == 'refs/heads/main'
with:
command: monitor
snyk-code:
name: Code Analysis (SAST)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Snyk Code Test
uses: snyk/actions/node@master
continue-on-error: true
with:
command: code test
args: --severity-threshold=high
snyk-container:
name: Container Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Docker Image
run: docker build -t myapp:test .
- name: Snyk Container Test
uses: snyk/actions/docker@master
continue-on-error: true
with:
image: myapp:test
args: --severity-threshold=high
snyk-iac:
name: IaC Security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Snyk IaC Test
uses: snyk/actions/iac@master
continue-on-error: true
with:
args: --severity-threshold=medium
security-gate:
name: Security Gate
needs: [snyk-open-source, snyk-code, snyk-container, snyk-iac]
runs-on: ubuntu-latest
steps:
- name: Check Results
run: |
echo "All security scans completed"
echo "Check Snyk Dashboard for details"
Best Practices
- Shift Left: ใช้ Snyk IDE Plugin ตรวจจับ Vulnerabilities ตั้งแต่เขียน Code
- CI/CD Gate: ตั้ง Snyk เป็น Quality Gate ใน CI/CD Block Deploy ถ้ามี Critical
- Auto Fix PRs: เปิด Auto Fix PRs ให้ Snyk สร้าง PR อัพเดท Dependencies อัตโนมัติ
- Policy as Code: กำหนด Security Policy เช่น ไม่ยอมรับ Critical, High ไม่เกิน 5
- Weekly Scan: ตั้ง Schedule Scan ทุกสัปดาห์ ตรวจจับ Vulnerabilities ใหม่
- License Compliance: ใช้ Snyk ตรวจ License ของ Dependencies ป้องกัน License Issues
Snyk คืออะไร
Developer Security Platform ตรวจ Vulnerabilities ใน Code (SAST) Dependencies (SCA) Containers IaC รองรับหลายภาษา CLI IDE Plugin CI/CD Integration ฟรีสำหรับ Open Source
แนะนำเพิ่มเติม — สัญญาณเทรดรายวัน XM Signal
เนื้อหาเกี่ยวข้อง — ดูเพิ่มเติมเรื่อง QuestDB Time Series DevSecOps Integration





