Azure DevOps の GitHub Advanced Security で依存関係スキャンの問題をトラブルシューティングする方法について説明します。
[前提条件]
カテゴリ | 要求事項 |
---|---|
アクセス許可 | - リポジトリのすべてのアラートの概要を表示するには、リポジトリに対する「コントリビューター」権限が必要です。 - Advanced Security でアラートを解除するには、プロジェクト管理者の権限が必要です。 - Advanced Security でアクセス許可を管理するには、プロジェクト コレクション管理者グループのメンバーであること、またはAdvanced Security: 設定の管理のアクセス許可が許可に設定されている必要があります。 |
高度なセキュリティの権限の詳細については、「高度なセキュリティ権限の管理」を参照してください。
依存関係スキャンでコンポーネントが識別されない
コンポーネントにフラグを設定せずに依存関係スキャン タスクが完了し、既知の脆弱性を持つコンポーネントのアラートを生成できない場合は、 AdvancedSecurity-Dependency-Scanning@1
タスクの前にパッケージの復元手順があることを確認してください。
たとえば、C# (.NET Core) プロジェクトの場合、サンプルの YAML スニペットを次に示します。
- task: DotNetCoreCLI@2
displayName: 'Restore NuGet packages'
inputs:
command: 'restore'
projects: '**/*.csproj'
# If you are using a private package feed such as Azure Artifacts, you will need additional variables.
# For more information, see https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/dotnet-core-cli-v2?view=azure-pipelines
feedsToUse: 'select'
...
- task: AdvancedSecurity-Dependency-Scanning@1
JavaScript プロジェクトの場合、サンプルの YAML スニペットを次に示します。
- task: Npm@1
displayName: 'npm install'
inputs:
command: 'install'
workingDir: '$(System.DefaultWorkingDirectory)'
- task: AdvancedSecurity-Dependency-Scanning@1
依存関係スキャン タスクのタイムアウト
タイムアウト前に依存関係スキャン タスクが実行されるデフォルトの時間は、300 秒間 (5 分間) です。 タスクが完了前にタイムアウトする場合は、パイプライン変数 DependencyScanning.Timeout
を設定できます。この変数には、 DependencyScanning.Timeout: 600
などの秒を表す整数が必要です。 300 秒の既定のタイムアウトでは何も影響しません。
この変数を使用するには、パイプライン変数として DependencyScanning.Timeout
を追加します。
- task: AdvancedSecurity-Dependency-Scanning@1
env:
DependencyScanning.Timeout: 600
スキャン ディレクトリの調整
既定では、依存関係スキャン タスクは Agent.BuildDirectory
ディレクトリを処理します。 スキャンのスコープを特定のフォルダーに設定する場合は、分析するビルド エージェント内の任意のディレクトリ ファイル パスに DependencyScanning.SourcePath
パイプライン変数を設定できます。 同じパイプライン ジョブでの複数の依存関係スキャン タスクの実行はサポートされていません。 スキャン パスのスコープがサブディレクトリの場合、別のディレクトリをスキャンするタスクを再追加することはできません。
- task: AdvancedSecurity-Dependency-Scanning@1
env:
DependencyScanning.SourcePath: scan/code/path
依存関係のスキャン結果を意図しないリポジトリに公開すること
あるリポジトリに格納されているパイプライン定義があり、GitHub Advanced Security によってスキャンされるソース コードが別のリポジトリにある場合、結果が処理され、正しくないリポジトリに送信され、ソース コード リポジトリではなくパイプライン定義を含むリポジトリに発行される可能性があります。
意図した結果ルーティングを有効にするには、パイプライン環境変数 advancedsecurity.publish.repository.infer: true
を設定して、作業ディレクトリ内のリポジトリから発行するリポジトリを推測します。
trigger:
- main
resources:
repositories:
# PipelineRepo: The repository containing the pipeline definition.
# This is optional and only needed if you plan to reference files or scripts from this repo.
- repository: PipelineRepo
type: git
name: DevOpsPipelineRepo
ref: refs/heads/main
trigger:
- main
# SourceRepo: The repository where scanning and publishing will occur.
- repository: SourceRepo
type: git
name: code-to-analyze-repo
ref: refs/heads/main
trigger:
- main
jobs:
- job: "DependencyScan"
displayName: "Dependency Scanning with Inferred Publishing"
variables:
# Enable repository inference
advancedsecurity.publish.repository.infer: true
steps:
# Checkout the SourceRepo
- checkout: SourceRepo
# Perform Dependency Scanning
- task: AdvancedSecurity-Dependency-Scanning@1
displayName: "Analyze Dependencies for Vulnerabilities"
結果の公開場所を調整すると、依存関係スキャンのプルリクエスト注釈が見つかりません。
advancedsecurity.publish.repository.infer
を使用している場合、または代替advancedsecurity.publish.repository
を定義する場合は、プル要求注釈が期待どおりに表示されるようにファイル パスを正確に決定できるように、DependencyScanning.SourcePath: $(System.DefaultWorkingDirectory)
を設定する必要があります。
- task: AdvancedSecurity-Dependency-Scanning@1
env:
DependencyScanning.SourcePath: $(System.DefaultWorkingDirectory)
ビルド タスクの緊急シナリオ
依存関係スキャン ビルド タスクがパイプラインの正常な実行をブロックしていて、ビルド タスクを緊急にスキップする必要がある場合は、パイプライン変数 DependencyScanning.Skip: true
を設定できます。
依存関係スキャン タスクのアクセス許可
依存関係スキャン ビルド タスクは、パイプライン ID を使用して Advanced Security REST API を呼び出します。 デフォルトでは、同じプロジェクト内のパイプラインはアラートを取得するアクセスを持っています。 ビルド サービス アカウントからこれらのアクセス許可を削除する場合、またはカスタム セットアップがある場合 (たとえば、リポジトリとは異なるプロジェクトでホストされているパイプライン) は、これらのアクセス許可を手動で付与します。
パイプラインで使用されるビルド サービス アカウントへの Advanced Security: View Alerts
アクセス許可を付与します。これは、プロジェクト スコープパイプラインの場合は [Project Name] Build Service ([Organization Name])
、コレクション スコープのパイプラインの場合は Project Collection Build Service ([Organization Name])
です。