Поделиться через


Azure Policy definitions audit effect

The audit effect is used to create a warning event in the activity log when evaluating a non-compliant resource, but it doesn't stop the request.

Audit evaluation

Audit is the last effect checked by Azure Policy during the creation or update of a resource. For a Resource Manager mode, Azure Policy then sends the resource to the Resource Provider. When evaluating a create or update request for a resource, Azure Policy adds a Microsoft.Authorization/policies/audit/action operation to the activity log and marks the resource as non-compliant. During a standard compliance evaluation cycle, only the compliance status on the resource is updated.

Audit properties

For a Resource Manager mode, the audit effect doesn't have any other properties for use in the then condition of the policy definition.

For a Resource Provider mode of Microsoft.Kubernetes.Data, the audit effect has the following subproperties of details. Использование templateInfo требуется для новых или обновленных определений политик, так как constraintTemplate устарел.

  • templateInfo (обязательно)

    • Can't be used with constraintTemplate.
    • sourceType (обязательно)
      • Определяет тип источника для шаблона ограничения. Допустимые значения: PublicURL или Base64Encoded.

      • If PublicURL, paired with property url to provide location of the constraint template. Расположение должно быть общедоступным.

        Предупреждение

        Don't use SAS URIs, URL tokens, or anything else that could expose secrets in plain text.

      • If Base64Encoded, paired with property content to provide the base 64 encoded constraint template. See Create policy definition from constraint template to create a custom definition from an existing Open Policy Agent (OPA) Gatekeeper v3 constraint template.

  • constraint (не рекомендуется)

    • Can't be used with templateInfo.
    • The CRD implementation of the Constraint template. Использует параметры, передаваемые через values как {{ .Values.<valuename> }}. В приведенном ниже примере 2 эти значения: {{ .Values.excludedNamespaces }} и {{ .Values.allowedContainerImagesRegex }}.
  • constraintTemplate (не рекомендуется)

    • Can't be used with templateInfo.
    • Must be replaced with templateInfo when creating or updating a policy definition.
    • Шаблон ограничения CustomResourceDefinition (CRD), определяющий новые ограничения. Шаблон определяет логику Rego, схему ограничения и параметры ограничения, которые передаются через values из политики Azure. For more information, go to Gatekeeper constraints.
  • constraintInfo (необязательно)

    • Can't be used with constraint, constraintTemplate, apiGroups, kinds, scope, namespaces, excludedNamespaces, or labelSelector.
    • Если constraintInfo не указано, ограничение можно создать из templateInfo и политики.
    • sourceType (обязательно)
      • Определяет тип источника для ограничения. Допустимые значения: PublicURL или Base64Encoded.

      • If PublicURL, paired with property url to provide location of the constraint. Расположение должно быть общедоступным.

        Предупреждение

        Не используйте URI или маркеры SAS в url или в любых других конструкциях, которые могут раскрыть секрет.

  • namespaces (необязательно)

    • An array of Kubernetes namespaces to limit policy evaluation to.
    • An empty or missing value causes policy evaluation to include all namespaces not defined in excludedNamespaces.
  • excludedNamespaces (необязательно)

  • labelSelector (необязательно)

    • An object that includes matchLabels (object) and matchExpression (array) properties to allow specifying which Kubernetes resources to include for policy evaluation that matched the provided labels and selectors.
    • An empty or missing value causes policy evaluation to include all labels and selectors, except namespaces defined in excludedNamespaces.
  • scope (необязательно)

    • A string that includes the scope property to allow specifying if cluster-scoped or namespaced-scoped resources are matched.
  • apiGroups (required when using templateInfo)

    • Массив, включающий группы API для сопоставления. Пустой массив ([""]) — это основная группа API.
    • Определение ["*"] для apiGroups не разрешено.
  • kinds (required when using templateInfo)

    • An array that includes the kind of Kubernetes object to limit evaluation to.
    • Defining ["*"] for kinds is disallowed.
  • values (необязательно)

    • Определяет все параметры и значения, передаваемые в ограничение. Each value must exist and match a property in the validation openAPIV3Schema section of the Constraint template CRD.

Audit example

Example 1: Using the audit effect for Resource Manager modes.

"then": {
  "effect": "audit"
}

Example 2: Using the audit effect for a Resource Provider mode of Microsoft.Kubernetes.Data. Дополнительные сведения в details.templateInfo объявляют об использовании PublicURL и задают url на местоположение шаблона ограничения для использования в Kubernetes для ограничения разрешенных образов контейнеров.

"then": {
  "effect": "audit",
  "details": {
    "templateInfo": {
      "sourceType": "PublicURL",
      "url": "https://store.policy.core.windows.net/kubernetes/container-allowed-images/v1/template.yaml",
    },
    "values": {
      "imageRegex": "[parameters('allowedContainerImagesRegex')]"
    },
    "apiGroups": [
      ""
    ],
    "kinds": [
      "Pod"
    ]
  }
}

Дальнейшие действия