Auto-add NSG rules

We use the built-in Windows VPN client to provide access to legacy applications that don't meet the security or usability requirements to be exposed to the internet. One of those applications just didn't work well over a VPN for various reasons but worked great over the internet. The application's network traffic was encrypted but the authentication was only username/password so just publishing it on the internet wasn't a good enough solution.

Allowing access to the resource over the internet from a specific IP address would meet the security requirements of the application but keeping up with manually adding everyone's home IP address to the Azure Network Security Group (NSG) would be impossible.

My solution in this case was to use a combination of the following resources to automate the process of adding a user's IP address to the NSG on a temporary basis:
  • Microsoft Power Automation (Flow)
  • Azure Automation Accounts
  • Powershell
  • Microsoft Graph API
Since our users are required to use multi-factor authentication to authenticate to Office 365/Azure I feel comfortable using the IP address from the sign-in logs as a trusted IP. Here's an overview:
  1. User logs into Office 365
  2. User triggers a Power Automation job (no input required by user)
  3. Power Automation job gets the user ID and passes it to a webhook which triggers an Azure Automation runbook
  4. Azure Automation runbook queries Microsoft Graph to obtain the user's sign-on IP address
  5. Azure Automation runbook runs a Powershell command to update the NSG protecting the resource
  6. A weekly Runbook runs to clean up the temporary rules in the NSG
The Power Automation job is very simple. All it does is get the ID of the logged in user and posts to a webhook for the Azure Automation Runbook:

The NSG rule creator Runbook code:


The NSG rule cleanup Runbook which runs on a weekly schedule:

Comments

Popular posts from this blog

Auto-installing extensions on Firefox using Intune

Disable DNS over HTTPS in Firefox using Intune

Moving Applocker control from Group Policy to Intune