Azure SQL PaaS and Azure Policy interactions - azure

Does anyone have any idea as to how I can restrict the IP addresses added to the SQL firewall rule via policy?
I have been attempting it for a while now, my policy looks like the below... i have tried everything - is there something im overlooking? :
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.SQL/servers/firewallRules"
},
{
"Not": {
"anyOf": [
{
"field": "Microsoft.Sql/servers/firewallRules/startIpAddress",
"in": "[parameters('StartIP')]"
},
{
"field": "Microsoft.Sql/servers/firewallRules/endIpAddress",
"in": "[parameters('EndIP')]"
}
]
}
}
]
},
"then": {
"effect": "Deny"
}
}
But it always throws a policy error when I update the firewall rules despite whats provided in the policy assignment.
For example, if my parameters are both " 0.0.0.0;8.8.8.8 "I would think i could have the access to Azure services enabled and 8.8.8.8 but that's not the case - I just get the same old denied due to policy error.
If I use just 0.0.0.0 as the parameter on the assignment I can provision new SQL servers, with it removed I cannot which leads me to believe that to some extent, the policy is working.
I know I can do the whole vnet route and use NSGS to accomplish just about the same thing; however, my organization does not want to go this route and would rather it be done in policy.

I don't have enough reputation to comment on your question. However, make sure you are being careful with your assignment parameters when entering them in the Portal. It takes the strings as-is so if you entered " 0.0.0.0;8.8.8.8 " as you specified the leading and trailing space would mess up the comparisons.
You can check to see what the exact parameter values are in the assignment by using the Get-AzureRmPolicyAssignment powershell cmdlet (or similar Azure CLI commands). To make using the cmdlet easier the full ID of the assignment is exposed on the assignment's compliance view in the Portal.

Related

Azure Policy - Deny New Network interfaces in vnets that doesn't have an specific tag

I'm having a hard time to create a policy to deny the creation of network interfaces when the vnic is not connected to specific vnet\subnets (allowed vnets have a specific tag)
It looks like I can restrict the creation based on the network interface fields. In this case the only idea that came to my mind was to have a parameter configured with a list of allowed subnet ids, and deny based on this parameters. In this case I would need to build a separated mechanism to update this policy definition (Maybe a powershell script).
Just would like to ask if this is a good way to get it done and ask for suggestions,
Thanks
Rob
There is workaround ie built-in policy in azure “require an tag on resources” means under selected resource group when you create any resource without having any tag it will failed . Assign this policy in your resource group.
I have named tag ‘Rahul’ without Rahul Tag I won’t be able to create any resource under resource group
Here I repro and found without any specified tag I cannot able create any resources.
Was able to get it done using this:
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkInterfaces"
},
{
"count": {
"field": "Microsoft.Network/networkInterfaces/ipconfigurations[*]",
"where": {
"value": "[substring(current('Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id'),0,lastIndexOf(current('Microsoft.Network/networkInterfaces/ipconfigurations[*].subnet.id'),'/'))]",
"notIn": "[parameters('subnetId')]"
}
},
"greater": 0
}
]
},
"then": {
"effect": "deny"
}
},
And I'll pupulate the parameter with my vnets using the Set-AzPolicyAssignment to update the parameter.
I've created a policy with the subnet as a paremeter, and will use Set-AzPolicyAssignment to update the list of allowed subnets in the policy assignment parameter – TheRob

Azure policy - prevent the creation of app services without authentication

I wish to create a policy that will prevent the creation of app services without authentication enabled (just auditing them is not enough).
The following policy can correctly identify existing resources that do not have authentication enabled:
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "Microsoft.Web/sites/config/siteAuthEnabled",
"equals": "false"
}
]
},
"then": {
"effect": "deny"
}
}
}
however it does not prevent them being created in the first place (either via ARM template or through the portal).
I suspect this is because the Microsoft.Web/sites/config resource isn't being explicitly created.
Does anyone know if this is possible?
Apparently, the Microsoft.Web/sites/config/* resource type (except Microsoft.Web/sites/config/web) is not supported by Azure Policy at this point.
Quoting #camillemarie from this similar GitHub issue:
authSettings cannot be managed via policy at this time. In the interest of hiding secrets from users in the default Reader role, this resource provider doesn't expose secrets via GET calls (hence the null in /config/web, and lack of GET support for /config/authSettings).
This means that the existing Microsoft.Web/sites/config/siteAuthSettings.* aliases are invalid. We'll look into removing these, but we don't have a good deprecation story at the moment.
Reference:
Microsoft.Web/sites/config/siteAuthSettings.* aliases are not valid #264
Azure Policy - Known Issues
You can try using the Microsoft.Web/sites/siteConfig alias.

Azure Policy Assignment - Exclude Resource Type(s)

I have an Azure Policy that validates the Region of 2 resource groups via 2 Assignments. The allowed Regions are South Central US and global. My problem is that there are policy violation in each resource group that I can't seem to get rid of. For example, in one resource group, the resource which violates the policy is the Assignment itself, which I cannot change the Region for (or I don't know how to) and I can't see it as an excludable resource in the Exclusions list. For the 2nd resource group, the failing items are a number of SQL database managed instance vulnerability assessments and a number of Security Assessments; the interesting part about these, when I try to view the resources Azure can't find them, just returns "Resource Not Found", so unsurprisingly I can't exclude these either. So right now I seem to be stuck with a Policy and 2 Assignments that cannot achieve 100% compliance, and I'm hoping someone can offer tips to resolve. Perhaps a way to exclude a Type of resource instead of by name, but I'm open to any ideas. Thanks.
Found the answer while digging through the pre-canned Policies. You can put a restriction on the type field in the policyRule.if section as per below. Just have to specify the types that should be excluded.
"policyRule": {
"if": {
"allOf": [
{
"field": "location",
"notIn": "[parameters('listOfAllowedLocations')]"
},
{
"field": "location",
"notEquals": "global"
},
{
"field": "type",
"notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
}
]
},
Adding type restriction to your policy will help, but you'll need to maintain the list of excluded resource types.
If you change the mode of your policy to Indexed, then your policy will only evaluate resources which actually have a location field.

How to Restrict Any/Any RDP & SSH access on network security groups using Azure Policy?

I am trying to deny the creation of NSG rules with ports SSH & RDP exposed to any IP address. I would like the rule to be able to exist if source IP addresses are provided for restriction. I have been able to successfully block the opening of ports 22 and 3389 using Azure Policy, but haven't been able to get Azure Policy to decipher whether to allow or Deny depending on if source IPs are listed or not.
Here is the Policy:
{
"if": {
"allOf": [
{
"not": {
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefix",
"equals": "*"
}
},
{
"anyOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"equals": "22"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"equals": "3389"
}
]
}
]
},
"then": {
"effect": "deny"
}
}
When this Policy is applied I am still able to create a anyany NSG rule on ports 22 and/or 3389, as if the policy were not in affect. As mentioned before I did get a Policy working that blocked RDP and SSH in any situation
I pulled the fields in the Json using the Azure CLI. Here is the list:
Microsoft.Network/networkSecurityGroups/securityRules[*].protocol
Microsoft.Network/networkSecurityGroups/securityRules[*].sourcePortRange
Microsoft.Network/networkSecurityGroups/securityRules[*].sourcePortRanges[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationPortRange
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationPortRanges[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationApplicationSecurityGroups[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].priority
Microsoft.Network/networkSecurityGroups/securityRules[*].direction
Microsoft.Network/networkSecurityGroups/securityRules[*].access
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationAddressPrefix
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationAddressPrefixes[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefix
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefixes[*]
Microsoft.Network/networkSecurityGroups/securityRules[*].description
Microsoft.Network/networkSecurityGroups/securityRules[*].provisioningState
Microsoft.Network/networkSecurityGroups/securityRules[*].name
Microsoft.Network/networkSecurityGroups/securityRules[*].etag
Microsoft.Network/networkSecurityGroups/securityRules[*]
Microsoft.Network/networkSecurityGroups/securityRules
Microsoft.Network/networkSecurityGroups/securityRules[*].id
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefixes
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationAddressPrefixes
Microsoft.Network/networkSecurityGroups/securityRules[*].sourcePortRanges
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationPortRanges
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].resourceGuid
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].provisioningState
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].etag
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].id
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].name
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].type
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].location
Microsoft.Network/networkSecurityGroups/securityRules[*].sourceApplicationSecurityGroups[*].tags
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationApplicationSecurityGroups[*].etag
Microsoft.Network/networkSecurityGroups/securityRules[*].destinationApplicationSecurityGroups
Microsoft.Network/networkSecurityGroups/securityRules/protocol
Microsoft.Network/networkSecurityGroups/securityRules/sourcePortRange
Microsoft.Network/networkSecurityGroups/securityRules/sourcePortRanges[*]
Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange
Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*]
Microsoft.Network/networkSecurityGroups/securityRules/destinationApplicationSecurityGroups[*]
Microsoft.Network/networkSecurityGroups/securityRules/priority
Microsoft.Network/networkSecurityGroups/securityRules/direction
Microsoft.Network/networkSecurityGroups/securityRules/access
Microsoft.Network/networkSecurityGroups/securityRules/destinationAddressPrefix
Microsoft.Network/networkSecurityGroups/securityRules/destinationAddressPrefixes[*]
Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefix
Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefixes[*]
Microsoft.Network/networkSecurityGroups/securityRules/description
Microsoft.Network/networkSecurityGroups/securityRules/provisioningState
Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefixes
Microsoft.Network/networkSecurityGroups/securityRules/destinationAddressPrefixes
Microsoft.Network/networkSecurityGroups/securityRules/sourcePortRanges
Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].resourceGuid
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].provisioningState
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].etag
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].id
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].name
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].type
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].location
Microsoft.Network/networkSecurityGroups/securityRules/sourceApplicationSecurityGroups[*].tags
Microsoft.Network/networkSecurityGroups/securityRules/destinationApplicationSecurityGroups[*].etag
Microsoft.Network/networkSecurityGroups/securityRules/destinationApplicationSecurityGroups
If I could please receive some assistance on determining what I may have wrong, it would be greatly appreciated.
IMHO, this cannot be achieved using Azure Policies (alone). Azure Policies are used to enforce different rules and effects over your resources, rather than on the entities performing them.
Therefore, consider exploring other services like RBAC or Conditional Access, which offer more features and control over aspects like geo-location.

Azure Policy not denying Custom Role creation

I am currently helping investigate adopting Azure for my organization's public cloud. One of the tasks I have been assigned is locking down accounts to prevent users from being able to elevate their permissions within a subscription.
One of the things in particular I am interested in is denying the creation of Custom Roles, as we don't want people to go and start creating their own roles until the need for the role has been vetted by security.
I have been trying to do this via an Azure policy with the following definition
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Authorization/roleDefinitions"
},
{
"field": "Microsoft.Authorization/roleDefinitions/type",
"equals": "CustomRole"
}
]
},
"then": {
"effect": "Deny"
}
}
It was actually just the built in "Audit Custom Roles" policy copied over and changing the effect from "Audit" to "Deny"
However I have applied this policy to the Management Group that contains the subscription I am testing with, and yet when I login to the CLI and try and create a new custom role it goes ahead and creates the role.
I have ensured that the policy is present on the subscription, and I have confirmed that I am in the correct subscription in the CLI (using az account show) yet I am still allowed to create custom roles.
Is this just not something Azure supports, or is there something else I am missing? Any help or guidance would be greatly appreciated as the Microsoft docs and the numerous examples available online don't seem to have any information on controlling roles with policies.
P.S.
I know that you can control roles to some extent through policies as we have another policy that prevents the assignment of a certain set of roles from happening and that does work.
It looks like Azure CLI creates the role definition without populating the "type" field. The following policy will handle this:
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Authorization/roleDefinitions"
},
{
"anyOf": [
{
"field": "Microsoft.Authorization/roleDefinitions/type",
"equals": "CustomRole"
},
{
"field": "Microsoft.Authorization/roleDefinitions/type",
"exists": "false"
}
]
}
]
},
"then": {
"effect": "Deny"
}
}

Resources