Giter Club home page Giter Club logo

azure-policy's Issues

Alias request: Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod

Scenario

Deny Dynamic IP Address allocation on subnet.

Definition

{
	"properties": {
		"displayName": "Enforce Static IP",
		"description": "Enforce Static IP",
		"parameters": {
			
			"effect": {
                "type": "String",
                "allowedValues": [
                    "auditIfNotExists",
                    "deny"
                ],
                "metadata": {
                    "displayName": "Policy Effect"
                }
            },
			
			"setting": {
                "type": "String",
                "allowedValues": [
                    "Dynamic",
                    "Static"
                ],
                "metadata": {
                    "displayName": "Threat Detection Setting"
                }
            }
		
		},
		"policyRule": {
			"if": {
				"allOf": [
					{
						"field": "type",
						"equals": "Microsoft.Network/networkInterfaces"
					},
					{
						"field": "Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod",
						"notEquals": "[parameters('setting')]"
					}
				]
			},
			"then": {
				"effect": "[parameters('effect')]",
				"details": {

                    "type": "Microsoft.Network/networkInterfaces",

                    "name": "default",

                    "existenceCondition": {

                        "allOf": [

                            {

                                "field": "Microsoft.Network/networkInterfaces/ipConfigurations[*].privateIPAllocationMethod",

                                "notEquals": "[parameters('effect')]"

                            }

                        ]

                    }

                }
			}
			
		}
	}
}
'''

Alias request: "Microsoft.Web/sites/config/siteAuthEnabled"

  • Scenario
    Permit to check that webapp are correctly authentification settings enabled

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/siteAuthEnabled",
"equals": "true"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

The policy 'effect' property value cannot be 'DeployIfNotExists'.

Deploy if not exist doesnt work with the given example for network watcher

New-AzureRmPolicyDefinition : InvalidPolicyRuleEffect : The policy definition 'deploy-NW-in-vnet-regions' rule is invalid. The policy 'effect' property value cannot be 'DeployIfNotExists'.
At line:1 char:15

  • ... efinition = New-AzureRmPolicyDefinition -Name "deploy-NW-in-vnet-regi ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzureRmPolicyDefinition], ErrorResponseMessageException
    • FullyQualifiedErrorId : InvalidPolicyRuleEffect,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet

Any idea what to do ?

Location isn't indicated in my Allowed locations template

I created a built-in policy Allowed location and assigned to my target resource. The policy is effective. However, when I checked definition template I didn't see location indicated.

{
  "if": {
    "allOf": [
      {
        "field": "location",
        "notIn": "[parameters('listOfAllowedLocations')]"
      },
      {
        "field": "location",
        "notEquals": "global"
      },
      {
        "field": "type",
        "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}

There must be a value inside this element notIn": "[parameters('listOfAllowedLocations')]" but where exactly I can find to adjust?

Policy not being enforced

Hi guys,

I've created the policy definition and assigned to my VS Pro subscription.
However, I am still able to create a Resource Group without fail.
I have tried changed the resource type from "Microsoft.Resources/subscriptions/resourceGroups" to "Microsoft.Resources/resourceGroups" wondering if it was an issue with that. But that didn't work either.

Wondering if I'm missing something?

Cheers,
Tim

Alias request: "Microsoft.Web/site/config/clientCertEnabled"

To ensure my web app to use mutual client authentication which is considered a security practice, I'd like to audit clientCertEnabled. Below is the sample definition

{
  "policyRule":{
    "if":{
      "allOf":[
        {
          "field":"type",
          "equals":"Microsoft.Web/sites/config"
        },
        {
          "field":"Microsoft.Web/sites/config/clientCertEnabled",
          "equals":"true"
        }
        ]},
        "then":
        {
          "effect":"audit"
        }},
        "parameter":{},
        "metadata":{
          "category":"Web App Security"
        }
} 

Alias request for Microsoft.HDInsight/clusters/properties/securityProfile.domain and Microsoft.HDInsight/clusters/properties/securityProfile.ldapUrls

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.HDInsight/clusters"
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties/securityProfile.domain",
"equals": "dummy ad"
}
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties/securityProfile.ldapUrls",
"equals": "dummy ldap"
}
}

            ]
        },
        "then": {
            "effect": "audit"
        }
    }
}

Events tab shows no event

As far as my understanding, when Azure Policy scans, events are recorded and displayed in Events tab. But from what I've noticed, there is no event shown.

What does exactly Event mean? The tooltip seems to show a hint but still not to be clear (Events are recorded when policy effect is exercised after resource evaluation).

Alias request for Microsoft.Devices/IotHubs/sku.name

Scenario
Use Azure policy to validate SKUs on Azure IoT Hub services.

Rule

{
	"if": {
		"allOf": [
			{
				"field": "type",
				"equals": "Microsoft.Devices/IotHubs"
			},
			{
				"not": {
                    "field": "Microsoft.Devices/IotHubs/sku.name",
                    "in": "[parameters('listOfSKUId')]"
				}
			}
		]
	},
	"then": {
		"effect": "deny"
	}
}

Alias request: "Microsoft.Web/sites/config/http20Enabled"

  • Scenario
    Permit to check that webapp have http 2.0 Enabled

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/http20Enabled",
"equals": "true"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Alias request: "Microsoft.Web/sites/config/minTlsVersion"

  • Scenario
    Permit to check that webapp are secure by using only TLS 1.2

  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/minTlsVersion",
"equals": "1.2"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Alias request: Microsoft.Security/complianceResults/pricings

** Scenario **

Need to use Azure Policy to ensure all subscriptions in a Management Group are using standard tier of Security Center

** Definition **

{
"policyRule": {
"if": {
"not": {
"field": "Microsoft.Security/complianceResults/pricings",
"equals": "Standard"
}
},
"then": {
"effect": "deny"
}
}
}

Alias request: Microsoft.Web/hostingEnvironments.clusterSettings for DisableTls1.0 and FrontEndSSLCipherSuiteOrder

Scenario

Disable TLS 1.0 & FrontEndSSLCipherSuiteOrder on App Service Environment.

customers who are dealing with PCI compliance audits, is how to explicitly disable TLS 1.0 for their apps.

This policy will provide required governance assurance to deny ASE createion with TLS 1.0 enabled

Definition

I am not sure how properties settings will surface in policy definition as this is KV pair under properties.

"resources": [
{
   "apiVersion": "2015-08-01",
   "type": "Microsoft.Web/hostingEnvironments",
   "name": ...,
   "location": ...,
   "properties": {
      "clusterSettings": [
         {
                         "name": "DisableTls1.0",
                         "value": "1"

         }
      ],
      "workerPools": [ ...],
      etc...
   }
}


'''

Alias Request: webApplicationFirewallConfiguration.firewallMode

Scenario
Use Azure Policy to check/enforce the WAF firewall mode.
Definition
{
"properties": {
"displayName": "Allowed Application Gateway WAF Mode",
"description": "This policy enables you to detect if the WAF is in detection or prevention mode.",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/applicationGateways"
},
{
"not": {
"field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.firewallMode",
"equals": "Prevention"
}
}
]
},
"then": {
"effect": "Deny"
}
}
}
}

Policy Initiative Assignment created from PowerShell cannot be edited in the Portal

I am using the examples to create a policy initiative, and then assign this to a subscription. Upon doing so, I am able to view the configuration using Powershell, however, when viewing in the portal, you get a 'broken' Azure blade (Dark cloud with raindrop). If I create the same assignment via the portal, this works fine. I can see that by using powershell, there are some properties missing - i.e. metadata, and notScopes (the latter is actually an array with a count of zero in the configuration via the portal)

Any ideas why this might be?

Microsoft.HDInsight/clusters/properties.clusterVersion

Scenario : Allow Provisioning of HDInsight Cluster which supports Secure data transfer (https). HDInsight with version 3.6 or newer only supports secured https connection with storage accounts.

Definition:
{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.HDInsight/clusters"
},
{
"not": {
"field": "Microsoft.HDInsight/clusters/properties.clusterVersion",
"equals": "3.6.1000.0"
}
}
]
},
"then": {
"effect": "audit"
}
}
}

Alias request: Microsoft.compute/virtualMachines/networkInterfaces

Scenario

There is a scenario in which controlled virtual machines should not have any Public IP addresses associated with its relatively NICs.

Definition

{
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Network/networkInterfaces"
        },
        {
          "not": {
            "field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].publicIpAddress.id",
            "exists": false
          }
        },
        {
            "field":"type",
            "equals": "Microsoft.Compute/virtualMachine/networkProfile[*].networkInterfaces.id"
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  }

Remark

Currently Azure Policy supports listing out all NICs with PIP (Public IP) but I'd love to know which non-compliant VMs are in place.

[Update] I also tested with NIC field`` as follows:

        {
            "not":{
            "field":"Microsoft.Compute/virtualMachines/networkInterfaces[*].id",
            "exists": false
            }
        }

But it seems like the result is not going to be out as expected (displaying non-compliant VMs)

@pilor

Alias Request: webApplicationFirewallConfiguration.disabledRuleGroups

Scenario
Use Azure Policy to audit the existence of any disabled OWASP rule groups. This may require the addition of a count property to query if there are any items in the collection, as I think the property will always exist regardless of its contents.
Definition

{
  "properties": {
    "displayName": "Disabled Application Gateway WAF Rules",
    "description": "This policy allows you to detect if any of the OWASP rule sets used in the WAF are disabled.",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/applicationGateways"
          },
          {
            "field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.disabledRuleGroups",
            "exists": "true"
          }
        ]
      },
      "then": {
        "effect": "Audit"
      }
    }
  }
}

Alias Request: "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[*].ApplicationSecurityGroups.Id"

Scenario: force application of a default Application Security Group to a VM NIC.
Definition:
{
"type": "Microsoft.Authorization/policyDefinitions",
"name": "enforce-asg-on-nic-test",
"properties": {
"displayName": "ASG X on every nic",
"description": "This policy enforces a specific app security group on every virtual network interface",
"parameters": {
"asgId": {
"type": "string",
"metadata": {
"description": "Resource Id of the App Security Group",
"displayName": "App Security Group Id",
"strongType": "appsecuritygroup"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkInterfaces"
},
{
"not": {
"field": "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[0].ApplicationSecurityGroups.Id",
"equals": "[parameters('asgId')]"
}
}
]
},
"then": {
"effect": "append",
"details": [
{
"field": "Microsoft.Network/networkInterfaces/networkSecurityGroup.IpConfigurations[0].ApplicationSecurityGroups.Id",
"value": "[parameters('asgId')]"
}
]
}
}
}
}

Alias Request: webApplicationFirewallConfiguration.enabled

Scenario
Use Azure Policy to validate that the WAF is enabled should the SKU allow it.
Definition

{
  "properties": {
    "displayName": "Allowed Application Gateway WAF Configuration",
    "description": "This policy enables you to specify whether the WAF is enabled.",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/applicationGateways"
          },
          {
            "not": {
              "field": "Microsoft.Network/applicationGateways/sku.name",
              "equals": "Standard"
            }
          },
          {
            "not": {
              "field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration.enabled",
              "equals": "true"
            }
          }
        ]
      },
      "then": {
        "effect": "Deny"
      }
    }
  }
}

Need Alias for Microsoft.Storage/storageAccounts/networkAcls.bypass

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"not": {
"field": "Microsoft.Storage/storageAccounts/networkAcls.bypass",
"contains": "[parameters('Exceptions')]"
}
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"Exceptions": {
"type": "String",
"metadata": {
"displayName": "Exceptions",
"description": "Exceptions"
}
}
},
"metadata": {}
}

Access Control (IAM) in Azure Policy

Like other Azure services, Access Control (IAM) should be in place to see who have rights to read and create policy. It'd be good for policy access control so nobody can edit and modify policy without rights.

SQL DB/Server deny policy for auditing/TDE/threat detection?

Hi,

I am trying to create policies for SQL Server /db resources where auditing/TDE/threat detection is not enabled. I am using the definition provided ate below url and only changing the effect from auditIfNotExists to deny, but it's not working as per the compliance screen(it shows correctly configured db's also as non-compliante). We have the elastic pool setup configured in our db's.

Please suggest how to apply deny policy for db's/servers which are not configured for auditing/TDE/threat detection?

policy deifnition for tde;

{
  "if": {
    "field": "type",
    "equals": "Microsoft.SQL/servers/databases"
  },
  "then": {
    "effect": "deny",
    "details": {
      "type": "Microsoft.SQL/servers/databases/transparentDataEncryption",
      "name": "current",
      "existenceCondition": {
        "field": "Microsoft.Sql/transparentDataEncryption.status",
        "equals": "Disabled" //I tried enabled too
      }
    }
  }
}

Thanks

Alias request: "Microsoft.Web/site/config/httpsOnly"

To ensure confidentiality, I'd like to audit https enablement on my web app which can be found in httpsOnly. Below is the sample definition

{
  "policyRule":{
    "if":{
      "allOf":[
        {
          "field":"type",
          "equals":"Microsoft.Web/sites/config"
        },
        {
          "field":"Microsoft.Web/sites/config/httpsOnly",
          "equals":"true"
        }
        ]},
        "then":
        {
          "effect":"audit"
        }},
        "parameter":{},
        "metadata":{
          "category":"Web App Security"
        }
} 

Enforce AHUB Policy

Hi,

FTE here, feel free to reach out. Wanted to provide some general feedback as well as some feedback/raise an issue specific to the Enforcing AHUB policy.

I tested the Enforce AHUB policy in a subscription of mine and ran into an issue where Linux distros could no longer be deployed as they do not have the Microsoft.Compute/LicenseType attribute. My understanding is that Microsoft.Compute/LicenseType will return $null, and $null IS in fact not equal to "Windows_Server" which will register as $true and deny the build. I see a few way to get around this, 1) adding a condition that Microsoft.Compute/LicenseType notequals $null, or 2) adding some logic to ensure the ImageOffer is also "WindowsServer" or "WindowsServerSemiAnnual. These aren't fully flushed out, as certain offer types, like Nano server are contained, but don't offer AHUB. I've attached a work around that I use, however I manually checked which Microsoft Published Offers/Skus had AHUB available. Hoping I can get help vetting and testing a more flushed out solution that doesn't block Linux VMs.

As for general feedback, Azure Policy is a super powerful tool, but more documentation and PowerShell options would be really helpful here. It seems like there is a bit of overlap in Aliases within policy, e.g. Microsoft.Compute/imageSku & Microsoft.Compute/virtualMachines/imageSku. Mapping the aliases to REST API attributes might be helpful. This led to some of my confusion with modifying the sample AHUB template. Also would be useful to provide some cmdlets regarding policy initiatives, as I only see the option to create these in the Portal. Would be happy to help in this effort in any way possible or answer/ask additional questions.

sampleAHUBDeny.txt

Alias request: Microsoft.Network/virtualNetworks/subnets/addressPrefix

Scenario

Would like to be able to create policies based on subnet address prefixes.
For example see below:

Definition

{
    "type": "Microsoft.Authorization/policyDefinitions",
    "name": "disallow-subnet-address-prefix",
    "properties": {
        "displayName": "Disallow certain subnet address prefixes",
        "description": "This policy disallows specified address prefixes",
        "parameters": {
            "addrPrefix": {
                "type": "String",
                "metadata": {
                    "description": "Subnet Address Prefix",
                    "displayName": "AddressPrefix"
                }
            }
        },
        "policyRule": {
            "if": {
                "anyOf": [
                    {
                        "allOf": [
                            {
                                "field": "type",
                                "equals": "Microsoft.Network/virtualNetworks/subnets"
                            },
                            {
                                "not": {
                                    "field": "Microsoft.Network/virtualNetworks/subnets/addressPrefix",
                                    "like": "[parameters('addrPrefix')]"
                                }
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "deny"
            }
        }
    }
}

Alias request: "Microsoft.Web/sites/config/ipSecurityRestrictions"

  • Scenario
    Permit to check that webapp are correctly compliant with IP restrictions, for allow only IP Adress allowed
  • Definition

{
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites/config"
},
{
"field": "Microsoft.Web/sites/config/siteAuthEnabled",
"in": ["1.2.3.4,1.2.3.5"]
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {},
"metadata": {
"category": "x_CustomPolicy"
}
}

Support to manage parameter value inside jSON file

Saying that I would like to allow a few subnets with public IP addresses similar to the following example

{
	"if": {
		"allOf": [
			{
				"field": "type",
				"equals": "Microsoft.Network/networkInterfaces"
			},
			{
				"not": {
					"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].publicIpAddress.id",
					"exists": false
				}
			},
			{
				"not": {
					"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id",
					"in": "[parameters('subnetIds')]"
				}
			}
		]
	},
	"then": {
		"effect": "deny"
	}
}

Is there a backlog that Microsoft supports adding whitelist directly in my JSON definition? It is similar to strongType location which allows me to do as follows:

      {
        "field": "location",
        "notIn": [
          "southeastasia"
          "westeurope",
        ]
      },

@pilor

Make policy scan activities to be more transparent

I've realized that the policy scan activities are not transparent and almost time I have nothing to know if a scan or batch of scan is done and when.

Moreover, if I change my condition in policy definition and click Save, when does the assignment get triggered? Is it an immediate trigger?

Alias Request: Microsoft.Network/networkSecurityGroups/subnets[*].id, Microsoft.Network/networkSecurityGroups/networkinterfaces[*].id

Scenario
Need to use Azure Policy to audit empty Network Security Groups. NSGs that are not associated with any Interface or Subnet.

Alias:
Microsoft.Network/networkSecurityGroups/subnets[].id
Microsoft.Network/networkSecurityGroups/subnets/id
Microsoft.Network/networkSecurityGroups/networkinterfaces[
].id
Microsoft.Network/networkSecurityGroups/networkinterfaces/id

** Definition **

{
"type": "Microsoft.Authorization/policyDefinitions",
"name": "audit-empty-nsg",
"properties": {
"displayName": "Check if the NSG is empty",
"description": "This policy will audit any empty NSG.",
"parameters": {
"subnetsId": {
"type": "String",
"metadata": {
"description": "Resource Id of the Subnet",
"displayName": "NSG Id"
}
},
"interfacesId": {
"type": "String",
"metadata": {
"description": "Resource Id of the Interface",
"displayName": "NSG Id"
}
}
},
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/subnets[].id",
"equals": "[parameters('subnetsId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/subnets"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/subnets/id",
"equals": "[parameters('subnetsId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/networkinterfaces[
].id",
"equals": "[parameters('interfacesId')]"
}
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/networkinterfaces"
},
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/networkinterfaces/id",
"equals": "[parameters('interfacesId')]"
}
}
]
}
]
},
"then": {
"effect": "audit"
}
}
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.