This article is contributed. See the original author and article here.
Many organizations have an on premises Active Directory infrastructure that is synced to Azure cloud. However, given that the on-prem side is the authoritative source of truth, any changes, such as disabling a user in the cloud (Azure AD), are overridden by the setting defined in the on-prem AD in the next scheduled sync. This presents challenges when you want to orchestrate a user property change from Azure that needs to persist even after the sync happens. To address the problem, this solution leverages Azure Automation Accounts and Hybrid Worker features across Windows & Azure. Automation Accounts are used to perform cloud-based automation across Azure and non-Azure environments. For non-Azure environments such as an On-Premises Active Directory, an Automation Hybrid Worker is required in addition to the Automation Account to be able to issue commands to the On-Premises Active Directory from Azure. Hybrid Workers can be used in Linux and Windows environments and if one has deployed Azure Arc , then they can also be used with the same OS types running in AWS or GCP so long as those machines are reporting to a Log Analytics workspace.
Deployment Steps
Create an Automation Account and link it with the Log Analytics Workspace
- Create an Automation Account from the Azure Portal
2. Deploy the Automation Hybrid Worker solution from the Azure Market place
Link a Log Analytics Workspace to your Automation Account.
Link the LA workspace to an automation account using the “Change Tracking” menu item on the list. If the Log Analytics workspace is in either East US or East US2 then you need to use the region mapping in the following link to select the location of your automation account: Supported regions for linked Log Analytics workspace | Microsoft Docs
Param (
[string] $SAMAccountName
)
if (Get-Module -ListAvailable -Name ActiveDirectory) {
Write-Output "ActiveDirectory PowerShell module already exists on host."
}
else {
Write-Output "ActiveDirectory PowerShell module does not exist on host. Installing..."
try {
Import-Module ActiveDirectory
}
catch{
Write-Error "Error installing ActiveDirectory PowerShell module."
throw $_
break
}
Write-Output "ActiveDirectory PowerShell module installed."
}
Write-Output "Finding and disabling user $SAMAccountName"
try {
Get-ADUser -Identity $SAMAccountName | Disable-ADAccount
}
catch {
Write-Error "Error disabling user account $SAMAccountName"
throw $_
break
}
Write-Output "Successfully disabled user account $SAMAccountName"
The script takes in a SAMAccountName parameter which it uses to find the appropriate user and disable the account. This script can be modified to do a variety of other tasks, such as password resets, adding/removing users to/from groups, etc.
To confirm successful registration, navigate to your automation account then select Hybrid worker groups. You should see the recently registered Hybrid Worker Group in the list per below screen shot.
It is also recommended that you use TLS versions more recent than 1.0 and 1.1. For this reason you may be required to run the below command as well:
Steps to orchestrate from Azure Sentinel/Logic Apps
Below is the structure of the orchestration Logic App that triggers the runbook to disable qualifying accounts from the On-Prem AD. With this action the next on-prem to cloud AD sync will maintain the state on the account – in this case disabled, until the setting is reversed from the on-prem AD Users & Computers management console.
Parse the JSON output from the Entities-Get Actions step above in order to extract the Azure User ID and SAM Account name needed to perform disable operations-first on Azure then on the On-Prem Active directory.
Disable Account in Azure AD
This Playbook can be deployed directly from GitHub on this link: Azure-Sentinel/Playbooks/Block-OnPremADUser at master · Azure/Azure-Sentinel (github.com)
Troubleshooting guide: Troubleshoot Azure Automation Hybrid Runbook Worker issues | Microsoft Docs
Special thanks to @haelshab for his valuable collaboration in this project & @YanivS for suggestions to enhance the solution
Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.
Recent Comments