> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cystack.net/llms.txt
> Use this file to discover all available pages before exploring further.

# CI/CD連携

> セキュリティテスト、ステージングビルド、リリースフローでVulnScanを使用します

VulnScanはCI/CDパイプラインからCLIで実行でき、アプリケーションのリリース前に脆弱性を検出できます。一般的には、アプリケーションをビルドしてステージング環境またはプレビュー環境にデプロイした後、その環境をスキャンします。

## VulnScanを組み込む場面

次のような場合にCI/CD連携が適しています。

* 安定したステージング環境またはプレビュー環境がある。
* リリース前にWebやAPIのセキュリティ結果を開発チームへ共有したい。
* リリース管理でセキュリティテストの証跡が必要になる。
* JSONやCSVの結果を課題管理システムやデータ基盤へ取り込みたい。
* 指定したビルドの後に重要なエンドポイントをスキャンしたい。

トラフィック、スコープ、実行時間を十分に管理できない場合は、コミットのたびに本番環境をスキャンしないでください。

## 推奨するパイプライン

1. アプリケーションをビルドします。
2. ステージング環境またはプレビュー環境へデプロイします。
3. スモークテストを実行します。
4. VulnScan CLIでステージングURLをスキャンします。
5. JSONとCSVをビルド成果物のディレクトリへ出力します。
6. 結果を課題管理システムまたはレポート保管先へ取り込みます。
7. 必要に応じて、Criticalまたは新しいHighの検出結果がある場合にリリースを停止します。

## CLIの例

```bash theme={null}
vulnscan scan --target https://staging.example.com --output ./security-reports --format json,csv --lang en
```

トークンが必要なAPI:

```bash theme={null}
vulnscan scan --target https://api-staging.example.com -H "Authorization: Bearer $VULNSCAN_API_TOKEN" --output ./security-reports --format json,csv
```

複数のターゲット:

```bash theme={null}
vulnscan scan --target-file ./ci-targets.txt --output ./security-reports --format json,csv
```

## GitHub Actions

```yaml theme={null}
name: Security Scan

on:
  workflow_dispatch:
  push:
    branches: [main]

jobs:
  vulnscan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run VulnScan
        env:
          VULNSCAN_TOKEN: ${{ secrets.VULNSCAN_TOKEN }}
        run: |
          ./vulnscan scan \
            --target https://staging.example.com \
            -H "Authorization: Bearer $VULNSCAN_TOKEN" \
            --output ./security-reports \
            --format json,csv \
            --lang en

      - name: Upload reports
        uses: actions/upload-artifact@v4
        with:
          name: vulnscan-reports
          path: security-reports/
```

## GitLab CI

```yaml theme={null}
vulnscan:
  stage: test
  script:
    - ./vulnscan scan --target https://staging.example.com --output ./security-reports --format json,csv --lang en
  artifacts:
    when: always
    paths:
      - security-reports/
```

## Jenkins Pipeline

```groovy theme={null}
pipeline {
  agent any
  stages {
    stage('VulnScan') {
      steps {
        sh './vulnscan scan --target https://staging.example.com --output ./security-reports --format json,csv --lang en'
      }
    }
  }
  post {
    always {
      archiveArtifacts artifacts: 'security-reports/**', fingerprint: true
    }
  }
}
```

## リリースゲート

最初は次の方針から始めると運用しやすくなります。

* Criticalの検出結果がある場合はリリースを停止する。
* 新しいHighの検出結果にはセキュリティ担当者の承認を求める。
* MediumとLowは、修正状況を追跡できる場合に限って許可する。
* 追跡可能性を保つため、JSONとCSVを必ず保存する。

パイプラインや対象スコープを調整中の最初の数スプリントは、警告だけを出す運用から始めることもできます。

## シークレットの管理

* トークンはCI/CDのシークレットストアに保存します。
* ログへトークンを出力しません。
* ステージング専用のトークンを使用します。
* パイプラインで不要になったトークンは失効させます。
* テストに必要な権限だけを付与します。

## Web UIとの整合性

CLIとWeb UIで同じワークスペース設定を使用すると、パイプラインのスキャン結果を同じデータベースに保存できます。セキュリティチームは、パイプライン、手動実行、スケジュール実行の結果を一つの画面で確認できます。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.