Policy Definitions - Create Or Update

Abonelikte ilke tanımı oluşturur veya güncelleştirir.
Bu işlem, verilen abonelikte belirtilen adla bir ilke tanımı oluşturur veya güncelleştirir.

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

URI Parametreleri

Name İçinde Gerekli Tür Description
policyDefinitionName
path True

string

Oluşturulacak ilke tanımının adı.

Regex pattern: ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$

subscriptionId
path True

string

uuid

Hedef aboneliğin kimliği. Değer bir UUID olmalıdır.

api-version
query True

string

Bu işlem için kullanılacak API sürümü.

İstek Gövdesi

Name Tür Description
properties.description

string

İlke tanımı açıklaması.

properties.displayName

string

İlke tanımının görünen adı.

properties.metadata

object

İlke tanımı meta verileri. Meta veriler açık uçlu bir nesnedir ve genellikle anahtar değer çiftlerinden oluşan bir koleksiyondur.

properties.mode

string

İlke tanımı modu. Bazı örnekler All, Indexed, Microsoft.KeyVault.Data'dır.

properties.parameters

<string,  ParameterDefinitionsValue>

İlke kuralında kullanılan parametreler için parametre tanımları. Anahtarlar parametre adlarıdır.

properties.policyRule

object

İlke kuralı.

properties.policyType

policyType

İlke tanımının türü. Olası değerler NotSpecified, BuiltIn, Custom ve Static değerleridir.

properties.version

string

#.#.# biçimindeki ilke tanımı sürümü.

properties.versions

string[]

Bu ilke tanımı için kullanılabilir sürümlerin listesi.

Yanıtlar

Name Tür Description
201 Created

PolicyDefinition

Oluşturuldu - İlke tanımı hakkındaki bilgileri döndürür.

Other Status Codes

CloudError

İşlemin neden başarısız olduğunu açıklayan hata yanıtı.

Güvenlik

azure_auth

Azure Active Directory OAuth2 Flow.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation kullanıcı hesabınızın kimliğine bürünme

Örnekler

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

Create or update a policy definition

Sample Request

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"
        }
      }
    }
  }
}

Sample Response

{
  "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

Sample Request

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"
        }
      }
    }
  }
}

Sample Response

{
  "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"
        }
      }
    }
  }
}

Tanımlar

Name Description
CloudError

İlke işleminden bir hata yanıtı.

createdByType

Kaynağı oluşturan kimliğin türü.

ErrorAdditionalInfo

Kaynak yönetimi hatası ek bilgileri.

ErrorResponse

Hata Yanıtı

Metadata

parametresi için genel meta veriler.

ParameterDefinitionsValue

İlkeye sağlanabilir bir parametrenin tanımı.

parameterType

Parametrenin veri türü.

PolicyDefinition

İlke tanımı.

policyType

İlke tanımının türü. Olası değerler NotSpecified, BuiltIn, Custom ve Static değerleridir.

systemData

Kaynağın oluşturulması ve son değiştirilmesiyle ilgili meta veriler.

CloudError

İlke işleminden bir hata yanıtı.

Name Tür Description
error

ErrorResponse

Hata Yanıtı
Başarısız işlemlerin hata ayrıntılarını döndürmek için tüm Azure Resource Manager API'leri için genel hata yanıtı. (Bu, OData hata yanıtı biçimini de izler.)

createdByType

Kaynağı oluşturan kimliğin türü.

Name Tür Description
Application

string

Key

string

ManagedIdentity

string

User

string

ErrorAdditionalInfo

Kaynak yönetimi hatası ek bilgileri.

Name Tür Description
info

object

Ek bilgiler.

type

string

Ek bilgi türü.

ErrorResponse

Hata Yanıtı

Name Tür Description
additionalInfo

ErrorAdditionalInfo[]

Hata ek bilgileri.

code

string

Hata kodu.

details

ErrorResponse[]

Hata ayrıntıları.

message

string

Hata iletisi.

target

string

Hata hedefi.

Metadata

parametresi için genel meta veriler.

Name Tür Description
assignPermissions

boolean

İlke ataması sırasında Azure portal bu parametrenin kaynak kimliğinde veya kaynak kapsamı değerinde rol atamaları oluşturmasını sağlamak için true olarak ayarlayın. Bu özellik, atama kapsamı dışında izinler atamak istemeniz durumunda kullanışlıdır.

description

string

Parametresinin açıklaması.

displayName

string

Parametrenin görünen adı.

strongType

string

portal aracılığıyla ilke tanımı atanırken kullanılır. Kullanıcının aralarından seçim yapabileceğiniz değerlerin bağlam bilgisi olan bir listesi sağlar.

ParameterDefinitionsValue

İlkeye sağlanabilir bir parametrenin tanımı.

Name Tür Description
allowedValues

object[]

parametresi için izin verilen değerler.

defaultValue

object

Değer sağlanmazsa parametresinin varsayılan değeri.

metadata

Metadata

parametresi için genel meta veriler.

schema

object

Kendi kendine tanımlanmış bir JSON şeması kullanarak atama sırasında parametre girişlerinin doğrulanması sağlar. Bu özellik yalnızca nesne türü parametreler için desteklenir ve Json.NET Schema 2019-09 uygulamasını izler. şemaları kullanma hakkında daha fazla bilgiyi adresinden https://json-schema.org/ ve taslak şemaları https://www.jsonschemavalidator.net/test edebilirsiniz.

type

parameterType

Parametrenin veri türü.

parameterType

Parametrenin veri türü.

Name Tür Description
Array

string

Boolean

string

DateTime

string

Float

string

Integer

string

Object

string

String

string

PolicyDefinition

İlke tanımı.

Name Tür Varsayılan değer Description
id

string

İlke tanımının kimliği.

name

string

İlke tanımının adı.

properties.description

string

İlke tanımı açıklaması.

properties.displayName

string

İlke tanımının görünen adı.

properties.metadata

object

İlke tanımı meta verileri. Meta veriler açık uçlu bir nesnedir ve genellikle anahtar değer çiftlerinden oluşan bir koleksiyondur.

properties.mode

string

Indexed

İlke tanımı modu. Bazı örnekler All, Indexed, Microsoft.KeyVault.Data'dır.

properties.parameters

<string,  ParameterDefinitionsValue>

İlke kuralında kullanılan parametreler için parametre tanımları. Anahtarlar parametre adlarıdır.

properties.policyRule

object

İlke kuralı.

properties.policyType

policyType

İlke tanımının türü. Olası değerler NotSpecified, BuiltIn, Custom ve Static değerleridir.

properties.version

string

#.#.# biçimindeki ilke tanımı sürümü.

properties.versions

string[]

Bu ilke tanımı için kullanılabilir sürümlerin listesi.

systemData

systemData

Bu kaynakla ilgili sistem meta verileri.

type

string

Kaynağın türü (Microsoft.Authorization/policyDefinitions).

policyType

İlke tanımının türü. Olası değerler NotSpecified, BuiltIn, Custom ve Static değerleridir.

Name Tür Description
BuiltIn

string

Custom

string

NotSpecified

string

Static

string

systemData

Kaynağın oluşturulması ve son değiştirilmesiyle ilgili meta veriler.

Name Tür Description
createdAt

string

Kaynak oluşturma (UTC) zaman damgası.

createdBy

string

Kaynağı oluşturan kimlik.

createdByType

createdByType

Kaynağı oluşturan kimliğin türü.

lastModifiedAt

string

Kaynağın son değişikliğinin zaman damgası (UTC)

lastModifiedBy

string

Kaynağı son değiştiren kimlik.

lastModifiedByType

createdByType

Kaynağı en son değiştiren kimliğin türü.