次の方法で共有


Policy Definitions - Create Or Update

サブスクリプション内のポリシー定義を作成または更新します。
この操作により、指定されたサブスクリプション内のポリシー定義が、指定された名前で作成または更新されます。

PUT https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}?api-version=2023-04-01

URI パラメーター

名前 / 必須 説明
policyDefinitionName
path True

string

作成するポリシー定義の名前。

正規表現パターン: ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$

subscriptionId
path True

string

uuid

ターゲット サブスクリプションの ID。 値は UUID である必要があります。

api-version
query True

string

この操作に使用する API バージョン。

要求本文

名前 説明
properties.description

string

ポリシー定義の説明。

properties.displayName

string

ポリシー定義の表示名。

properties.metadata

object

ポリシー定義メタデータ。 メタデータはオープン エンド オブジェクトであり、通常はキー値ペアのコレクションです。

properties.mode

string

ポリシー定義モード。 たとえば、All、Indexed、Microsoft.KeyVault.Data などです。

properties.parameters

<string,  ParameterDefinitionsValue>

ポリシー ルールで使用されるパラメーターのパラメーター定義。 キーはパラメーター名です。

properties.policyRule

object

ポリシー ルール。

properties.policyType

policyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

properties.version

string

#.#.# 形式のポリシー定義のバージョン。

properties.versions

string[]

このポリシー定義で使用できるバージョンの一覧。

応答

名前 説明
201 Created

PolicyDefinition

Created - ポリシー定義に関する情報を返します。

Other Status Codes

CloudError

操作に失敗した理由を説明するエラー応答。

セキュリティ

azure_auth

Azure Active Directory OAuth2 フロー。

型: oauth2
フロー: implicit
Authorization URL (承認 URL): https://login.microsoftonline.com/common/oauth2/authorize

スコープ

名前 説明
user_impersonation ユーザー アカウントの借用

Create or update a policy definition
Create or update a policy definition with advanced parameters

Create or update a policy definition

要求のサンプル

PUT https://management.azure.com/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming?api-version=2023-04-01

{
  "properties": {
    "mode": "All",
    "displayName": "Enforce resource naming convention",
    "description": "Force resource names to begin with given 'prefix' and/or end with given 'suffix'",
    "metadata": {
      "category": "Naming"
    },
    "policyRule": {
      "if": {
        "not": {
          "field": "name",
          "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]"
        }
      },
      "then": {
        "effect": "deny"
      }
    },
    "parameters": {
      "prefix": {
        "type": "String",
        "metadata": {
          "displayName": "Prefix",
          "description": "Resource name prefix"
        }
      },
      "suffix": {
        "type": "String",
        "metadata": {
          "displayName": "Suffix",
          "description": "Resource name suffix"
        }
      }
    }
  }
}

応答のサンプル

{
  "id": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "ResourceNaming",
  "properties": {
    "mode": "All",
    "displayName": "Naming Convention",
    "description": "Force resource names to begin with 'prefix' and end with 'suffix'",
    "metadata": {
      "category": "Naming"
    },
    "version": "1.2.1",
    "versions": [
      "1.2.1",
      "1.0.0"
    ],
    "policyRule": {
      "if": {
        "not": {
          "field": "name",
          "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]"
        }
      },
      "then": {
        "effect": "deny"
      }
    },
    "parameters": {
      "prefix": {
        "type": "String",
        "metadata": {
          "displayName": "Prefix",
          "description": "Resource name prefix"
        }
      },
      "suffix": {
        "type": "String",
        "metadata": {
          "displayName": "Suffix",
          "description": "Resource name suffix"
        }
      }
    },
    "policyType": "Custom"
  }
}

Create or update a policy definition with advanced parameters

要求のサンプル

PUT https://management.azure.com/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/EventHubDiagnosticLogs?api-version=2023-04-01

{
  "properties": {
    "mode": "Indexed",
    "displayName": "Event Hubs should have diagnostic logging enabled",
    "description": "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised",
    "metadata": {
      "category": "Event Hub"
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.EventHub/namespaces"
      },
      "then": {
        "effect": "AuditIfNotExists",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled",
                "equals": "true"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days",
                "equals": "[parameters('requiredRetentionDays')]"
              }
            ]
          }
        }
      }
    },
    "parameters": {
      "requiredRetentionDays": {
        "type": "Integer",
        "defaultValue": 365,
        "allowedValues": [
          0,
          30,
          90,
          180,
          365
        ],
        "metadata": {
          "displayName": "Required retention (days)",
          "description": "The required diagnostic logs retention in days"
        }
      }
    }
  }
}

応答のサンプル

{
  "id": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "ResourceNaming",
  "properties": {
    "mode": "Indexed",
    "displayName": "Event Hubs should have diagnostic logging enabled",
    "description": "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised",
    "metadata": {
      "category": "Event Hub"
    },
    "version": "1.2.1",
    "versions": [
      "1.2.1",
      "1.0.0"
    ],
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.EventHub/namespaces"
      },
      "then": {
        "effect": "AuditIfNotExists",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled",
                "equals": "true"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days",
                "equals": "[parameters('requiredRetentionDays')]"
              }
            ]
          }
        }
      }
    },
    "parameters": {
      "requiredRetentionDays": {
        "type": "Integer",
        "defaultValue": 365,
        "allowedValues": [
          0,
          30,
          90,
          180,
          365
        ],
        "metadata": {
          "displayName": "Required retention (days)",
          "description": "The required diagnostic logs retention in days"
        }
      }
    }
  }
}

定義

名前 説明
CloudError

ポリシー操作からのエラー応答。

createdByType

リソースを作成した ID の種類。

ErrorAdditionalInfo

リソース管理エラーの追加情報。

ErrorResponse

エラー応答

Metadata

パラメーターの一般的なメタデータ。

ParameterDefinitionsValue

ポリシーに指定できるパラメーターの定義。

parameterType

パラメーターのデータ型です。

PolicyDefinition

ポリシー定義。

policyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

systemData

リソースの作成と最後の変更に関連するメタデータ。

CloudError

ポリシー操作からのエラー応答。

名前 説明
error

ErrorResponse

エラー応答
失敗した操作のエラーの詳細を返す、すべての Azure Resource Manager API に対する一般的なエラー応答 (これは、OData エラー応答形式にも従います)。

createdByType

リソースを作成した ID の種類。

名前 説明
Application

string

Key

string

ManagedIdentity

string

User

string

ErrorAdditionalInfo

リソース管理エラーの追加情報。

名前 説明
info

object

追加情報。

type

string

追加情報の種類。

ErrorResponse

エラー応答

名前 説明
additionalInfo

ErrorAdditionalInfo[]

エラーの追加情報。

code

string

エラー コード。

details

ErrorResponse[]

エラーの詳細です。

message

string

エラー メッセージ。

target

string

エラーのターゲット。

Metadata

パラメーターの一般的なメタデータ。

名前 説明
assignPermissions

boolean

ポリシーの割り当て中に、このパラメーターのリソース ID またはリソース スコープ値に対してロールの割り当てを作成Azure portal場合は、true に設定します。 このプロパティは、割り当てスコープ外でアクセス許可を割り当てたい場合に便利です。

description

string

パラメーターの説明。

displayName

string

パラメーターの表示名。

strongType

string

ポータルを使用してポリシー定義を割り当てるときに使用されます。 ユーザーが選択できる値のコンテキスト対応リストを提供します。

ParameterDefinitionsValue

ポリシーに指定できるパラメーターの定義。

名前 説明
allowedValues

object[]

パラメーターに使用できる値。

defaultValue

object

値が指定されていない場合のパラメーターの既定値。

metadata

Metadata

パラメーターの一般的なメタデータ。

schema

object

自己定義 JSON スキーマを使用した割り当て中のパラメーター入力の検証を提供します。 このプロパティは、オブジェクト型パラメーターでのみサポートされ、Json.NET Schema 2019-09 の実装に従います。 スキーマの使用については https://json-schema.org/ で、下書きスキーマのテストについては https://www.jsonschemavalidator.net/ で詳細を参照してください。

type

parameterType

パラメーターのデータ型です。

parameterType

パラメーターのデータ型です。

名前 説明
Array

string

Boolean

string

DateTime

string

Float

string

Integer

string

Object

string

String

string

PolicyDefinition

ポリシー定義。

名前 規定値 説明
id

string

ポリシー定義の ID。

name

string

ポリシー定義の名前。

properties.description

string

ポリシー定義の説明。

properties.displayName

string

ポリシー定義の表示名。

properties.metadata

object

ポリシー定義メタデータ。 メタデータはオープン エンド オブジェクトであり、通常はキー値ペアのコレクションです。

properties.mode

string

Indexed

ポリシー定義モード。 たとえば、All、Indexed、Microsoft.KeyVault.Data などです。

properties.parameters

<string,  ParameterDefinitionsValue>

ポリシー ルールで使用されるパラメーターのパラメーター定義。 キーはパラメーター名です。

properties.policyRule

object

ポリシー ルール。

properties.policyType

policyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

properties.version

string

#.#.# 形式のポリシー定義のバージョン。

properties.versions

string[]

このポリシー定義で使用できるバージョンの一覧。

systemData

systemData

このリソースに関連するシステム メタデータ。

type

string

リソースの種類 (Microsoft.Authorization/policyDefinitions)。

policyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

名前 説明
BuiltIn

string

Custom

string

NotSpecified

string

Static

string

systemData

リソースの作成と最後の変更に関連するメタデータ。

名前 説明
createdAt

string

リソース作成のタイムスタンプ (UTC)。

createdBy

string

リソースを作成した ID。

createdByType

createdByType

リソースを作成した ID の種類。

lastModifiedAt

string

リソースの最終変更のタイムスタンプ (UTC)

lastModifiedBy

string

リソースを最後に変更した ID。

lastModifiedByType

createdByType

リソースを最後に変更した ID の種類。