Bylaw

Gallery › Storage › Azure built-in policies

Secure transfer to storage accounts should be enabled

Converted Policy Audit Deny Disabled Mode Indexed Version 2.0.0

Audit requirement of Secure transfer in your storage account. Secure transfer is an option that forces your storage account to accept requests only from secure connections (HTTPS). Use of HTTPS ensures authentication between the server and the service and protects data in transit from network layer attacks such as man-in-the-middle, eavesdropping, and session-hijacking

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONStorage_AuditForHTTPSEnabled_Audit.json · 66 lines
{
  "properties": {
    "displayName": "Secure transfer to storage accounts should be enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Audit requirement of Secure transfer in your storage account. Secure transfer is an option that forces your storage account to accept requests only from secure connections (HTTPS). Use of HTTPS ensures authentication between the server and the service and protects data in transit from network layer attacks such as man-in-the-middle, eavesdropping, and session-hijacking",
    "metadata": {
      "version": "2.0.0",
      "category": "Storage"
    },
    "version": "2.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "less": "2019-04-01"
                  },
                  {
                    "field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
                    "exists": "false"
                  }
                ]
              },
              {
                "field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/404c3081-a854-4457-ae30-26a93ef643f9",
  "name": "404c3081-a854-4457-ae30-26a93ef643f9"
}
Bylaw404c3081-a854-4457-ae30-26a93ef643f9.bylaw.ps1 · 36 lines
# Converted from Storage_AuditForHTTPSEnabled_Audit.json by ConvertTo-Bylaw.
Policy '404c3081-a854-4457-ae30-26a93ef643f9' {

    Properties @{
        DisplayName   = 'Secure transfer to storage accounts should be enabled'
        Description   = 'Audit requirement of Secure transfer in your storage account. Secure transfer is an option that forces your storage account to accept requests only from secure connections (HTTPS). Use of HTTPS ensures authentication between the server and the service and protects data in transit from network layer attacks such as man-in-the-middle, eavesdropping, and session-hijacking'
        Version       = '2.0.0'
        Category      = 'Storage'
        PolicyVersion = '2.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        Require 'supportsHttpsTrafficOnly is as required' {
            AnyOf {
                Arm '[requestContext().apiVersion]' | Must -BeGreaterOrEqual '2019-04-01'
                Field supportsHttpsTrafficOnly | Must -Exist
            }
        }

        Require 'supportsHttpsTrafficOnly is not false' {
            Field supportsHttpsTrafficOnly | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Storage/Storage_AuditForHTTPSEnabled_Audit.json in Azure/azure-policy, under the MIT licence.