Here’s the complete solution that addresses all three aspects - JIT configuration, security group exceptions, and patch automation requirements:
Approach 1: Time-Based NSG Exception (Recommended)
Create an NSG rule that temporarily allows automation access:
# Enable automation window
$nsg = Get-AzNetworkSecurityGroup -Name "ERP-NSG"
Add-AzNetworkSecurityRuleConfig -Name "Patch-Window"
-Priority 200 -Access Allow -Protocol Tcp
-Direction Inbound -SourceAddressPrefix AzureCloud
-SourcePortRange * -DestinationPortRange 5985,5986
The key is priority: JIT rules are typically 100-199, so setting your rule to 200+ ensures JIT takes precedence for interactive access while your automation rule provides the exception. In your runbook, enable this rule at the start of your maintenance window and remove it afterward.
Approach 2: Azure Update Management Integration
Migrate to Azure Update Management which bypasses JIT entirely because it uses Azure Resource Manager APIs rather than direct VM connectivity. Configure it via Azure Automation:
- Enable Update Management solution in your workspace
- Link your VMs to the solution
- Create deployment schedules for Sunday 2 AM maintenance
- Update Management uses the Azure control plane, so JIT policies don’t apply
This is the cleanest solution because Update Management is designed for this scenario and includes compliance reporting, pre/post scripts, and maintenance window management built-in.
Approach 3: Dedicated Hybrid Worker
Deploy an Azure Automation Hybrid Worker on a locked-down management VM:
- Create a dedicated management VM in a secure subnet
- Add this VM to JIT permanent exceptions (single exception point)
- Install Hybrid Worker agent on this VM
- Configure your runbooks to execute on this worker group
- The worker VM has a static IP that can be whitelisted in JIT policies
Security Considerations for All Approaches:
- Enable NSG flow logs to monitor all automation access attempts
- Use Azure Policy to ensure consistent JIT configuration across all ERP VMs
- Configure alerts for any JIT policy modifications
- Document the exception in your security baseline
- Review automation logs weekly to detect any anomalies
- Ensure your managed identity has only the minimum required permissions
My Recommendation:
Go with Azure Update Management (Approach 2) because it’s purpose-built for this scenario, maintains your security posture without exceptions, and provides better patch compliance visibility. If you need custom pre/post patch scripts, Update Management supports those as well. The JIT policy remains fully intact with no exceptions needed, and you get enterprise patch management capabilities as a bonus.
If Update Management doesn’t meet your needs due to custom scripting requirements, use the time-based NSG approach but automate both the enabling and disabling in the same runbook to minimize the exposure window. Never leave the exception rule active permanently.