How to disable feature of redirecting all HTTP traffic to HTTPS in azure Web App service using azure policy.

Godugu, Loka 20 Reputation points
2024-10-17T08:16:53.1866667+00:00

How to disable feature of redirecting all HTTP traffic to HTTPS in azure Web App service using azure policy. Our client is asking for a policy so that if anyone creates Function app or logic App services, by default HTTPS only will configured as off. Please help me on this policy creation.

User's image

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,124 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,217 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
919 questions
{count} votes

Accepted answer
  1. Pavan Minukuri 205 Reputation points Microsoft Vendor
    2024-10-30T19:01:07.1766667+00:00

    Hi Godugu, Loka
    Please try with below producer:
    To disable the feature of redirecting all HTTP traffic to HTTPS in Azure Web App service using Azure Policy, you can create a custom policy definition with the following JSON policy rule:

    {

    "mode": "Indexed",
    
    "policyRule": {
    
        "if": {
    
            "allOf": [
    
                {
    
                    "field": "type",
    
                    "equals": "Microsoft.Web/sites/config"
    
                },
    
                {
    
                    "field": "Microsoft.Web/sites/config/web.redirectHttpToHttps",
    
                    "equals": true
    
                }
    
            ]
    
        },
    
        "then": {
    
            "effect": "deny"
    
        }
    
    },
    
    "parameters": {}
    

    }

    This policy rule checks if the redirectHttpToHttps property is set to true in the Microsoft.Web/sites/config resource type. If the property is set to true, the policy denies the deployment of the resource.

    To apply this policy to Function App or Logic App services, you can use the Microsoft.Web/sites/config resource type in the policy definition. Here's an example policy definition that applies this policy to Function App or Logic App services:

    {

    "mode": "All",
    
    "displayName": "Disable redirecting all HTTP traffic to HTTPS in Function App or Logic App services",
    
    "description": "This policy disables the feature of redirecting all HTTP traffic to HTTPS in Function App or Logic App services.",
    
    "metadata": {
    
        "category": "Web"
    
    },
    
    "parameters": {},
    
    "policyRule": {
    
        "if": {
    
            "allOf": [
    
                {
    
                    "field": "type",
    
                    "in": [
    
                        "Microsoft.Web/sites",
    
                        "Microsoft.Logic/workflows"
    
                    ]
    
                },
    
                {
    
                    "field": "Microsoft.Web/sites/siteConfig.redirectHttpToHttps",
    
                    "equals": true
    
                }
    
            ]
    
        },
    
        "then": {
    
            "effect": "deny",
    
            "details": {
    
                "message": "The feature of redirecting all HTTP traffic to HTTPS is disabled in this subscription."
    
            }
    
        }
    
    }
    

    }

    This policy definition applies the policy rule to the Microsoft.Web/sites and Microsoft.Logic/workflows resource types. The Microsoft.Web/sites/siteConfig/redirectHttpToHttps property is used to check if the feature of redirecting all HTTP traffic to HTTPS is enabled. If the property is set to true.

    Please let me know if anything required.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.