品質ゲートの設計
品質ゲートとは
品質ゲート(Quality Gate) とは、コードが本番環境に到達する前に通過しなければならないチェックポイントです。
vibe codingの問題を防ぐには、複数の品質ゲート を設置することが効果的です。
品質ゲートの層
品質ゲートは複数の層で構成されます。
[開発者]
↓
[Gate 1: ローカルチェック]
↓
[Gate 2: プルリクエスト]
↓
[Gate 3: CIパイプライン]
↓
[Gate 4: セキュリティスキャン]
↓
[Gate 5: 人間のレビュー]
↓
[Gate 6: ステージング環境]
↓
[本番環境]
Gate 1: ローカルチェック
コミット前にローカルで実行するチェックです。
pre-commitフック:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: detect-private-key
- id: detect-aws-credentials
- repo: https://github.com/eslint/eslint
rev: v8.56.0
hooks:
- id: eslint
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
設定:
# pre-commitのインストール
pip install pre-commit
pre-commit install
Gate 2: プルリクエストテンプレート
PRを作成する際のテンプレートです。
.github/pull_request_template.md:
## 変更内容
<!-- 変更の概要を記述 -->
## AI生成コードの確認
- [ ] AI生成コードを含む場合、すべて読んで理解した
- [ ] セキュリティチェックを実施した
- [ ] テストを追加した
## セキュリティチェックリスト
- [ ] APIキー・シークレットがハードコードされていない
- [ ] ユーザー入力がバリデートされている
- [ ] SQLインジェクション対策済み
- [ ] XSS対策済み
- [ ] 認証・認可が適切
## テスト
- [ ] ユニットテストを追加/更新した
- [ ] すべてのテストが通過する
## レビュー依頼
- [ ] 自己レビュー完了
- [ ] @security-team のレビューが必要(セキュリティ関連の変更の場合)
Gate 3: CIパイプライン
GitHub Actionsでの自動チェック例です。
# .github/workflows/quality-gate.yml
name: Quality Gate
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm test
- name: Check coverage
run: npm run test:coverage -- --coverageThreshold='{"global":{"lines":80}}'
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Snyk
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- name: Check for secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
build:
runs-on: ubuntu-latest
needs: [lint, test, security]
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run build
Gate 4: セキュリティスキャン
専用のセキュリティスキャンを追加します。
# .github/workflows/security-scan.yml
name: Security Scan
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * *' # 毎日実行
jobs:
dependency-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run npm audit
run: npm audit --audit-level=high
sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Semgrep
uses: returntocorp/semgrep-action@v1
with:
config: >-
p/security-audit
p/secrets
p/owasp-top-ten
container-scan:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t app:latest .
- name: Run Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: 'app:latest'
severity: 'CRITICAL,HIGH'
Gate 5: 人間のレビュー
自動化だけでは不十分です。人間のレビューが必須です。
CODEOWNERSファイル:
# .github/CODEOWNERS
# セキュリティ関連ファイル
/src/auth/ @security-team
/src/payment/ @security-team @payment-team
# インフラ関連
/infrastructure/ @devops-team
# すべてのPRにはリードのレビューが必要
* @tech-lead
ブランチ保護ルール:
# リポジトリ設定
Branch protection rules:
- Require a pull request before merging
- Require approvals: 2
- Require review from Code Owners
- Require status checks to pass:
- lint
- test
- security
Gate 6: ステージング環境
本番前の最終確認環境です。
ステージング環境の要件:
-
本番と同等の構成
- 同じインフラ
- 同じ設定
- 本番に近いデータ(匿名化)
-
セキュリティテスト
- ペネトレーションテスト
- 脆弱性スキャン
- 負荷テスト
-
承認プロセス
- ステージングでの動作確認
- 関係者の承認
- デプロイチェックリスト
品質ゲートダッシュボード
品質ゲートの状態を可視化しましょう。
メトリクス例:
| 指標 | 目標値 | 現在値 |
|---|---|---|
| テストカバレッジ | > 80% | 75% |
| セキュリティ問題(高) | 0 | 0 |
| セキュリティ問題(中) | < 5 | 3 |
| コード重複率 | < 5% | 4.2% |
| PRレビュー待ち時間 | < 24h | 18h |
この事例から学ぶべき教訓と実践ポイント
「品質ゲートの設計」から学ぶべきことは以下の通りです。
-
複数の層でチェック
- ローカル → CI → セキュリティ → 人間 → ステージング
-
自動化が基本
- pre-commit、CI/CD、セキュリティスキャン
-
人間のレビューは必須
- CODEOWNERS、承認プロセス
-
ステージング環境で最終確認
- 本番と同等の環境
-
可視化と継続的改善
- ダッシュボードでメトリクス管理
まとめ:重要ポイントの振り返り
- 複数の品質ゲート を設置
- Gate 1-3: 自動化(lint、test、security)
- Gate 4: セキュリティスキャン(Snyk、Semgrep)
- Gate 5: 人間のレビュー(CODEOWNERS)
- Gate 6: ステージング環境
- 可視化 でメトリクス管理
- 教訓:品質ゲートを通過しなければ本番に入れない