Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IaaS DNS Forwarders #746

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/bicep/examples/iaas-dns-forwarders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Azure IaaS DNS Forwarders example
lisamurphy-msft marked this conversation as resolved.
Show resolved Hide resolved

This example deploys DNS Forwarder Virtual Machines in the MLZ HUB, to enables proper resolution of Private Endpoint and internal domains accross all Virtual Networks.

## What this example does

### Follows best-practices

This Infrastructure as Code deploys the components to follow best practices: [Private Link and DNS integration in hub and spoke network architectures](https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/private-link-and-dns-integration-at-scale#private-link-and-dns-integration-in-hub-and-spoke-network-architectures)

### Configures proper DNS resolution in DoD Azure environments

The two Windows DNS Servers are configured to act as DNS servers for all Virtual Networks, and then forward DNS requests three different ways, as depicted below.

![DNS Forwarders diagram](diagram.png)

1. Azure Private Endpoint-related DNS requests get forwarded to the Azure DNS server (168.63.129.16), which uses the Private DNS zones configured as part of MLZ.
2. Active Directory-related DNS requests get forwarded to the Domain Controllers in the Identity tier.
3. All other DNS requests (Internet...) get forwarded to the default server forwarder, typically DISA DNS servers.

## Pre-requisites

1. A Mission LZ deployment (a deployment of mlz.bicep)
2. The outputs from a deployment of mlz.bicep (./src/bicep/examples/deploymentVariables.json).

See below for information on how to create the appropriate deployment variables file for use with this template.

### Template Parameters

Template Parameters Name | Description
--- | ---
vmNamePrefix | 3 to 12 characters VM name prefix. -01 and -02 will get appended to that prefix.
vmAdminPassword | local administrator password.
nicPrivateIPAddresses | array of two static IP addresses available in the HUB VNET subnet.
extensionsFilesContainerUri | uri to the storage account used to host the DSC configuration and custom script file (if not relying on the public repo)
extensionsFilesContainerSas | storage account account SAS token used to host the DSC configuration and custom script file (if not relying on the public repo)
dnsServerForwardersIpAddresses | default DNS server forwarders (for instance: DISA's). Defaults to Azure DNS.
conditionalDnsServerForwarders | array of conditional forwarders to create, including Azure Private DNS zones and Active Directory-related zones. Defaults to Azure US Government's private endpoint DNS zones.

### Generate MLZ Variable File (deploymentVariables.json)

For instructions on generating 'deploymentVariables.json' using both Azure PowerShell and Azure CLI, please see the [README at the root of the examples folder](..\README.md).

Place the resulting 'deploymentVariables.json' file within the ./src/bicep/examples folder.

### Deploying IaaS DNS Forwarders

Connect to the appropriate Azure Environment and set appropriate context, see getting started with Azure PowerShell for help if needed. The commands below assume you are deploying in Azure Government and show the entire process from deploying MLZ and then adding DNS forwarders post-deployment.

```PowerShell
cd .\src\bicep
Connect-AzAccount -Environment AzureUSGovernment
New-AzSubscriptionDeployment -Name contoso -TemplateFile .\mlz.bicep -resourcePrefix 'contoso' -Location 'USGovVirginia'
cd .\examples
(Get-AzSubscriptionDeployment -Name contoso).outputs | ConvertTo-Json | Out-File -FilePath .\deploymentVariables.json
cd .\keyVault
New-AzResourceGroupDeployment -DeploymentName IaaSDNSForwarders `
-TemplateFile .\forwarderVm.bicep
-ResourceGroupName 'contoso-rg-hub-mlz'
-vmNamePrefix 'contoso-dnsfwd'
-nicPrivateIPAddresses "10.9.0.4", "10.9.0.5"
-dnsServerForwardersIpAddresses "2.2.2.2"
```

### Setting all Virtual Networks to use the Forwarders as DNS servers

The PowerShell script below configures the (existing) Virtual Networks to use the DNS Forwarders as DNS servers.

```PowerShell
$dnsForwarders = "10.9.0.4", "10.9.0.5"
$virtualNetworks = Get-AzVirtualNetwork
foreach($vnet in $virtualnetworks){
Write-Output ("Changing VNET " + [char]34 + $vnet.Name + [char]34 + " DNS Servers...")
$vnet.DhcpOptions.DnsServers = $dnsForwarders
$vnetSave = $vnet | Set-AzVirtualNetwork
}
```

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Script to set Windows DNS Server Conditional DNS Forwarders
[CmdletBinding()]
param (
[Parameter(Position = 0,
HelpMessage = "JSON Array of DNS Conditional Forwarders to configure",
Mandatory = $true)]
[String]
$ConditionalDnsForwardersJSON
)

# Convert from JSON
$conditionalDnsForwarders = $ConditionalDnsForwardersJSON | ConvertFrom-Json
if (!($conditionalDnsForwarders)) { throw("Could not convert from JSON:`r`n" + $ConditionalDnsForwardersJSON) }

# Loop through conditional forwarders
foreach ($conditionalDnsForwarder in $conditionalDnsForwarders) {
# Get existing zone
$existingZone = Get-DnsServerZone -Name $conditionalDnsForwarder.Name -ErrorAction:SilentlyContinue
if ($existingZone) {Write-Output ("Found existing zone for " + [char]34 + $conditionalDnsForwarder.Name + [char]34 + "...")}
# Create conditional forwarder
else {
Add-DnsServerConditionalForwarderZone -Name $conditionalDnsForwarder.Name -MasterServers $conditionalDnsForwarder.Forwarders
# Verify forwarder was created
$fwdGet = Get-DnsServerZone -Name $conditionalDnsForwarder.Name -ErrorAction:SilentlyContinue
if ($fwdGet) {
Write-Output ([char]34 + $conditionalDnsForwarder.Name + [char]34 + " was successfully created...")
}
else{throw("Could not create Conditional DNS Forwarder for name " + [char]34 + $conditionalDnsForwarder.Name + [char]34 + ".")}
}
}
Binary file not shown.
Loading