Thursday, June 15, 2023
Azure: ARM template for simple Win2k22 server for testing purposes
Monday, June 12, 2023
Azure: Deploy a key vault with a private endpoint
This post describes an ARM template that deploys a key vault, with a private endpoint, into an existing VNet and subnet. The key vault does not have to be placed in the same resource group as the VNet.
It requires the following to already be deployed:
- VNet
- Subnet
- Resource group (for the key vault and private endpoint)
- Private DNS zone (privatelink.vaultcore.azure.net)
The key vault will be configured to use RBAC and will allow ARM templates to retrieve content (in this case it is to allow an ARM template that deploys a VM to retrieve a secret from the key vault), see below:
Wednesday, June 7, 2023
Azure Policy - Allow only specified IP ranges and regions for VNets
At current client we had a request to apply a policy to enforce that only VNets using specified IP address ranges and regions will be allowed. So for example, if you create a VNet in West Europe, then it must be within the 10.100.0.0/16 IP address space and if in North Europe it must be within 10.200.0.0/16 and 10.201.0.0/16. And anything outside that must be denied.
There is no built-in policy for this. It was possible to find simpler versions online of the above but we couldn't find anything that fit all the requirements.
The closest we got was a slimmed down version of this policy from AzPolicyAdvertizer named "Address space must be pre-allocated for region".
However, it didn't take into account extended VNets. So if you have a VNet consisting of two or more IP address ranges, it will show as non-compliant.
We raised a ticket with Microsoft support and after a few days they came back with an updated policy that works.
The functioning policy can be found here on Github. The only thing that needs to be updated is the content of the "spokeAllocations" array.
Monday, March 20, 2023
Auto create DNS records for RSV with policy including region code
When using private endpoints at scale, the recommended setup from Microsoft is to use Azure Policy to automatically create the DNS records in the central private DNS zones when the private endpoints are created. The reason for this is that users or owners of the spokes or landing zones do not have permissions to create A records in the central private DNS zones in the Hub.
The policies specified by Microsoft work as long as a region code does not have to be specified in the private DNS zone name (which is the case for most of them, see full list here). However, for e.g. Recovery Services Vault for Azure Backup (and for AKS/Kubernetes), this is the case.
The zones are region specific, for West Europe it's: privatelink.we.backup.windowsazure.com and for Sweden Central it's privatelink.sdc.backup.windowsazure.com.
The default policy only does a check on the subResource (or groupId) value which in this case is: AzureBackup. The result of having two policies (e.g. one for West Europe and one for Sweden Central) running with the same subResource value is that DNS records for the private endpoints are randomly generated in the two private DNS zones.
A fix for this is to add a conditional check in the policy on the location of the private endpoint (PE). This way it is ensured that the DNS records are created in the correct zone that matches the location of the PE.
The full policy is available on Github, see link here.
The main change can be seen below:
Tuesday, February 14, 2023
Azure: Adding a resource lock via ARM template
Resource locks can be added on Azure resources to prevent unintended deletion or unwanted changes. There are two types of locks: 1) Do not delete (where you can make updates/changes) and 2) Read only (where you can neither change nor delete), see more info here.
It can make sense to add locks to critical infrastructure resources, but note that it also comes with additional management overhead and some caveats, see link above.
Locks can be added to either a resource or a resource group.
In the example in this post, we'll look at a read only lock for a specific resource and how to add this to an ARM template.
It's fairly simple to add. The lock is a separate resource, an ExpressRoute circuit, but the principle is the same for all resources.
The lock resource itself is as follows:
{
"condition": "[parameters('enableReadOnlyLock')]",
"type": "Microsoft.Authorization/locks",
"apiVersion": "2020-05-01",
"name": "ER circuit lock",
"scope": "[concat('Microsoft.Network/expressRouteCircuits/', parameters('circuitName'))]",
"dependsOn": [
"[resourceId('Microsoft.Network/expressRouteCircuits', parameters('circuitName'))]"
],
"properties": {
"level": "ReadOnly",
"notes": "ER circuit should not be updated or deleted"
}
}
"enableReadOnlyLock": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Determines if the resources should be locked to prevent changes or deletion."
}
},
Updating ExpressRoute Circuit fails with error: Peering/Circuit was recently updated by service provider
Recently I had to make some minor updates to an ExpressRoute Circuit via Azure DevOps. The change was to apply a read-only resource lock via code so no actual changes were introduced to the circuit configuration itself. Still, when running the pipeline it fails showing the error below:
"Error: The Peering/Circuit was recently updated by the service provider and is not currently in sync" (see screenshot below).
This particular ER circuit has a private peering which has been configured by the service provider (this can either be done by the customer or by the service provider). However, we knew that the service provider had not recently updated the circuit so it did not make much sense.
We raised a ticket to Microsoft and they suggested to specify the "gatewayManagerEtag" in the code, see more info here. I didn't find much info around this parameter other than it's a string and supposedly it can be used to ensure that the service provider or the customer don't accidentally override a common setting with an older value. To identify the current value I went to the portal and exported the ARM template for the ER circuit (the value was 7).
After specifying this parameter, the push went through with no problems. And at the same time, we specified the private peering configuration info in the ARM template, which was not there from the beginning (as it had been set by the service provider). Additionally, we tried updating another ER circuit where we ourself had initially configured the private peering in the ARM template and where the gatewayManagerEtag value was empty or just showing as "". This also works fine and we included this on all circuits for consistency.
I've uploaded an example ARM template to GitHub which includes private peering configuration, the gatewayManagerEtag and a read-only resource lock, see links below (remember to update the content of the parameters file):
Friday, February 3, 2023
PowerShell and Az CLI commands to deploy ARM and Bicep templates
This is just a quick note on the PowerShell command to deploy ARM templates.
Command should be run from the location where the ARM templates are located (or update the file path).
New-AzResourceGroupDeployment
-Name deploy_storage_account -ResourceGroupName rg-some_resource_group-001 `
-TemplateFile .\deploy_storage_account.json `
-TemplateParameterFile .\deploy_storage_account.parameters.json
There is another example here for deploying a key vault.
And here's link to the Microsoft documentation.
For Az CLI the command format is:New-AzResourceGroupDeployment -WhatIf -Name deploy_storage_account -ResourceGroupName rg-some_resource_group-001 `
-TemplateFile .\deploy_storage_account.json `
-TemplateParameterFile .\deploy_storage_account.parameters.json





