📴

Defender for Cloud の設定 OFF を検出・通知

2025/03/03に公開

はじめに

Defender for Cloud は、Defender CSPM や Defender for Servers などの有償プランを提供しています。これらのプランや機能を誤って OFF にしてしまうと、セキュリティ リスクが生じる可能性があります。そのため、プランや機能の OFF にした場合に検出し、通知する仕組みを考えます。

Azure Resource Graph クエリ で Defender for Cloud の設定をチェック

Defender for Cloud の設定は Azure Resource Graph クエリでチェック可能です。いくつかサンプルを説明します。

各サブスクリプションにおけるプランの有効・無効を確認

securityresources における microsoft.security/pricings のタイプが Defender for Cloud の設定を管理しています。この設定における properties 内の "pricingTier": "Free" の場合はその Defender プランが無効であることを示しています。

securityresources
| where type == 'microsoft.security/pricings'
| project type, name, tenantId, subscriptionId, properties

Defender CSPM が OFF のサブスクリプションを抽出

上記のクエリを参考に、properties.pricingTier をチェックし、Free になっていることを検出します。他のプランの場合は name の箇所を変更します。

securityresources
| where type == 'microsoft.security/pricings'
| project type, name, tenantId, subscriptionId, properties
| where name == "CloudPosture"
| where properties.pricingTier == "Free"

Defender CSPM の各設定が OFF の場合を抽出

どのプランでも基本的に properties.extensions に各機能の ON/OFF が記載されているのでここをチェックします。以下は Defender for Servers (name == "VirtualMachine") の例です。

以下のクエリは Defender CSPM の設定が False になっていることををチェックしています。

securityresources
| where type == 'microsoft.security/pricings'
| project type, name, tenantId, subscriptionId, properties
| where name == "CloudPosture"
| where properties.pricingTier == "Standard"
| mv-expand properties.extensions
| extend featureName = properties_extensions.name
| extend isEnabled = properties_extensions.isEnabled
| project type, name, tenantId, subscriptionId,featureName,isEnabled
| where isEnabled == "False"

Defender CSPM の各設定が OFF の場合を抽出 (mv-expand なし)

この場合は、明確に各機能のパラメータが設定されている順序で指定する必要があるため、仕様が変わる際に見直す必要が出てきます。

securityresources
| where type == 'microsoft.security/pricings'
| project type, name, tenantId, subscriptionId, properties
| where name == "CloudPosture"
| where properties.pricingTier == "Standard"
| extend extensions = properties.extensions
| extend SensitiveDataDiscovery = extensions[0].isEnabled
| extend ContainerRegistriesVulnerabilityAssessments = extensions[1].isEnabled
| extend AgentlessDiscoveryForKubernetes = extensions[2].isEnabled
| extend AgentlessVmScanning = extensions[3].isEnabled
| extend EntraPermissionsManagement = extensions[4].isEnabled
| extend ApiPosture = extensions[5].isEnabled
| project-away properties, extensions
| where SensitiveDataDiscovery == "False" 
  or ContainerRegistriesVulnerabilityAssessments == "False"
  or AgentlessDiscoveryForKubernetes  == "False"
  or EntraPermissionsManagement == "False"
  or ApiPosture == "False"

Azure Monitor アラートルールを設定

Azure Resource Graph クエリは Azure Monitor のログ検索で使用でき、アラート ルールもサポートされていますので、今回は検出・通知にこちらを利用します。
https://learn.microsoft.com/ja-jp/azure/governance/resource-graph/alerts-query-quickstart?tabs=azure-resource-graph

モニターや Log Analytics ワークスペースのログ検索画面で以下のようにクエリのテーブルの頭に arg(""). をつければ使用可能です。 (赤波線が引かれてエラーのように見えるが無視)

arg("").securityresources
| where type == 'microsoft.security/pricings'
| project type, name, tenantId, subscriptionId, properties
| where name == "CloudPosture"
| where properties.pricingTier == "Free"


ログ検索画面で対象のクエリを実行し、右上 […] から 新しいアラートルールを選択します。


集計の粒度、評価の頻度、しきい値をカスタマイズし、[次へ: アクション>] をクリックします。


既存のアクション グループを使用を選択するか、 [+アクション グループの作成] をクリックします。


サブスクリプション、リソース グループ、リージョン、名称などを選択し、[次へ: 通知 >] をクリックします。


通知方法、連絡先などを設定し、[次へ:アクション>] をクリックします。


追加で何かアクションを起こす場合 (Logic Apps など) は設定、要件がなければ [確認と作成] をクリックします。


問題なければ [作成] をクリックします。


アラート ルールの作成画面に戻り、アクション グループが設定されるため、[次へ:詳細>] をクリックします。


名前などを設定して、ID で [システム割り当てマネージド ID] を選択、[確認および作成] をクリックします。

問題なければ [作成] をクリックします。


作成後、[監視] ページを開き、[アラート] から [アラート ルール] を選択します。


作成したアラートルールを選択し、[ID] を選択、[Azure ロールの割り当て] をクリックします。


[+ロールの割り当ての追加] をクリックし、以下のロールを割り当てます。

ロール スコープ 理由
Log Analytics 閲覧者 アラート ルールで指定した Log Analytics ワークスペースを含むサブスクリプションもしくはリソース グループ クエリを実行する権限の付与
閲覧者もしくはセキュリティ閲覧者 今回のクエリでチェックしたいサブスクリプション Azure Resource Graph でリソース データを閲覧する権限


動作確認

設定した周期次第ではありますが、5 分で設定した場合には設定後 10 分程度でアラートが出力されます。(その後も 5 分おきに出力されるため、動作確認後に周期の変更など調整ください)


メールの受信も確認できました。

まとめ

Defender for Cloud の設定を定期的にチェックし、通史する仕組みを検討しました。このようなアラートルールを設定することで、重要なセキュリティ機能が無効化された場合に迅速に対応できるようになります。

Microsoft (有志)

Discussion