Automatically add trusted IPs to an Azure IP Group for Azure Firewall
For many reasons we choose to not use a VPN for traffic which is already encrypted and authenticated. Sometimes this is a challenge though, especially when the authentication opens us up for password guessing attacks.
In this case, that vulnerability is our on-premises Exchange Server which is needed for Public Folder access amongst other things. We've tried different solutions to prevent this, including the Azure Web Application Firewall, but always end up needing to expose a portion of the Exchange Web Services to the internet.
I'm sure some of you are wondering what we are doing wrong with Exchange to need this but I really can't recall each of the obstacles we ran into while trying to nail this down.
Our latest attempt at mitigating this vulnerability collects the IP addresses of all of our trusted clients and automatically adds then to an Azure IP Group which is used in an Azure Firewall rule to allow HTTPS traffic to our on-premises Exchange Server.
The solution utilizes the following:
- Azure Functions
- Azure Firewall
- Azure IP Groups
- PowerShell
- Intune
1. We used Intune to push out a Powershell Script which will run every 5 minutes. One caveat we ran into was Intune Powershell scripts will only run once in most cases but we found a great script from Jos Lieben which will allow for the script to run every 5 minutes. It can be found here.
using namespace System.Net | |
# Input bindings are passed in via param block. | |
param($Request, $TriggerMetadata) | |
# Interact with query parameters or the body of the request. | |
$ipaddress = $Request.Query.ipaddress | |
if (-not $ipaddress) { | |
$name = $Request.Body.ipaddress | |
} | |
# Write to the Azure Functions log stream. | |
Write-Host "PowerShell HTTP trigger function processed a request." | |
$ipGroup = Get-AzIpGroup -Name "p-ipg-exchangeclients" -ResourceGroupName "p-ipg-exchangeclients" | |
if ($ipGroup.IpAddresses.Contains($ipaddress)) { | |
return | |
} | |
else { | |
$ipGroup.IpAddresses.Add($ipaddress) | |
Set-AzIpGroup -IpGroup $ipGroup | |
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." | |
if ($ipaddress) { | |
} | |
$body = "The IP address $ipaddress has been added to the IP Group $ipGroup.IpAddresses" | |
} | |
# Associate values to output bindings by calling 'Push-OutputBinding'. | |
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | |
StatusCode = [HttpStatusCode]::OK | |
Body = $body | |
}) |
Comments
Post a Comment