接続されている GitHub リポジトリまたは Azure DevOps プロジェクトをスキャンする

接続された GitHub リポジトリまたは Azure DevOps プロジェクトをスキャンするように Microsoft Security DevOps を設定できます。 GitHub アクションまたは Azure DevOps 拡張機能を使用して、コードとしてのインフラストラクチャ (IaC) ソース コードでのみ Microsoft Security DevOps を実行することで、パイプラインのランタイムを減らすことができます。

この記事では、テンプレート YAML の構成ファイルを適用して、接続されているリポジトリまたはプロジェクトをスキャンし、Microsoft Security DevOps ルールを使用して、特に IaC セキュリティの問題を検出する方法について説明します。

前提条件

  • Microsoft Security DevOps の場合は、ソース コード管理システムに基づいて GitHub アクションまたは Azure DevOps 拡張機能を設定します:
  • リポジトリに IaC テンプレートがあることを確認します。

接続されている IaC ソース コードをスキャンするための GitHub アクションを設定して実行する

GitHub でアクションを設定し、スキャン結果を表示するには:

  1. GitHub にサインインします。

  2. リポジトリのメイン ページに移動します。

  3. ファイル ディレクトリで、.github >workflows>msdevopssec.yml を選択します。

    GitHub でのアクションの操作の詳細については、「前提条件 」を参照してください。

  4. [このファイルの編集] (鉛筆) アイコンを選択します。

    Screenshot that highlights the Edit this file icon for the msdevopssec.yml file.

  5. YAML ファイルの [アナライザーの実行] セクションで、次のコードを追加します:

    with:
        categories: 'IaC'
    

    Note

    値は、大文字と小文字が区別されます。

    次に例を示します。

    Screenshot that shows the information to add to the YAML file.

  6. [変更点のコミット...] を選択します。

  7. [Commit changes] (変更をコミットする) を選びます。

    Screenshot that shows where to select Commit changes on the GitHub page.

  8. (省略可能) リポジトリに IaC テンプレートを追加します。 リポジトリに IaC テンプレートが既にある場合は、このステップをスキップします。

    たとえば、使用できる IaC テンプレートをコミットして、基本的な Linux Web アプリケーションをデプロイします

    1. azuredeploy.json ファイルを選択します。

      Screenshot that shows where the azuredeploy.json file is located.

    2. [Raw]\(未フォーマット\) を選択します。

    3. 次の例のように、ファイル内のすべての情報をコピーします:

      {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
          "webAppName": {
            "type": "string",
            "defaultValue": "AzureLinuxApp",
            "metadata": {
              "description": "The base name of the resource, such as the web app name or the App Service plan."
            },
            "minLength": 2
          },
          "sku": {
            "type": "string",
            "defaultValue": "S1",
            "metadata": {
              "description": "The SKU of the App Service plan."
            }
          },
          "linuxFxVersion": {
            "type": "string",
            "defaultValue": "php|7.4",
            "metadata": {
              "description": "The runtime stack of the current web app."
            }
          },
          "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
              "description": "The location for all resources."
            }
          }
        },
        "variables": {
          "webAppPortalName": "[concat(parameters('webAppName'), '-webapp')]",
          "appServicePlanName": "[concat('AppServicePlan-', parameters('webAppName'))]"
        },
        "resources": [
          {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2020-06-01",
            "name": "[variables('appServicePlanName')]",
            "location": "[parameters('location')]",
            "sku": {
              "name": "[parameters('sku')]"
            },
            "kind": "linux",
            "properties": {
              "reserved": true
            }
          },
          {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2020-06-01",
            "name": "[variables('webAppPortalName')]",
            "location": "[parameters('location')]",
            "kind": "app",
            "dependsOn": [
              "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
            ],
            "properties": {
              "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
              "siteConfig": {
                "linuxFxVersion": "[parameters('linuxFxVersion')]"
              }
            }
          }
        ]
      }
      
    4. GitHub リポジトリで、.github/workflows フォルダーに移動します。

    5. [ファイルの追加]>[新しいファイルの作成] を選択します。

      Screenshot that shows you how to create a new file.

    6. ファイルの名前を入力します。

    7. コピーした情報をファイルに貼り付けます。

    8. [Commit new file](新しいファイルのコミット) を選択します。

    テンプレート ファイルがリポジトリに追加されます。

    Screenshot that shows that the new file you created is added to your repository.

  9. Microsoft Security DevOps スキャンが完了したことを確認します:

    1. リポジトリの場合は、[アクション] を選択します。

    2. ワークフローを選択して、アクションの状態を表示します。

  10. スキャンの結果を表示するには、[セキュリティ]>[コード スキャン アラート] に移動します。

    ツールごとにフィルター処理して、IaC の結果のみを確認できます。

Azure DevOps 拡張機能を設定して実行し、接続されている IaC ソース コードをスキャンする

拡張機能を設定し、Azure DevOps でスキャン結果を表示するには:

  1. Azure DevOps にサインインします。

  2. プロジェクトを選択します。

  3. [パイプライン] を選択します。

  4. Microsoft Security DevOps の Azure DevOps 拡張機能が構成されているパイプラインを選択します。

  5. [パイプラインを編集する] を選択します。

  6. パイプライン YAML 構成ファイルで、MicrosoftSecurityDevOps@1 タスクの displayName 行の下に、次のコードを追加します:

    inputs:
        categories: 'IaC'
    

    次に例を示します。

    Screenshot that shows where to add the IaC categories line in the pipeline configuration YAML file.

  7. [保存] を選択します。

  8. (省略可能) Azure DevOps プロジェクトに IaC テンプレートを追加します。 プロジェクトに IaC テンプレートが既にある場合は、この手順をスキップします。

  9. メイン ブランチに直接コミットするか、コミット用に新しいブランチを作成するかを選択し、[保存] を選択します。

  10. IaC スキャンの結果を表示するには、[パイプライン] を選択し、変更したパイプラインを選択します。

  11. 詳細については、特定のパイプラインの実行を選択してください。

適用された IaC ルールの詳細と修復情報を表示する

Microsoft Security DevOps に含まれる IaC スキャン ツールは、テンプレート アナライザー (PSRule はテンプレート アナライザーに含まれます) と Terrascan です。

Template Analyzer は、Azure Resource Manager テンプレート (ARM テンプレート) と Bicep テンプレートに対してルールを実行します。 詳細については、「Template Analyzer のルールと修復の詳細」を参照してください。

Terrascan は、ARM テンプレートと、CloudFormation、Docker、Helm、Kubernetes、Kustomize、Terraform の各テンプレートでルールを実行します。 詳細については、「Terrascan ルール」を参照してください。

Microsoft Security DevOps に含まれている IaC スキャン ツールの詳細については、次を参照してください:

この記事では、Microsoft Security DevOps 用に GitHub アクションと Azure DevOps 拡張機能を設定して IaC セキュリティの構成ミスをスキャンする方法と、結果を表示する方法について説明しました。

詳しい情報を入手するには: