Jul 16 2020 11:55 AM
Updating an existing SQL AlwaysOn cluster to Group Managed Service Accounts
It is basically a 3-step process to implement group managed service accounts on existing SQL AlwaysOn replicas if you want it to go smoothly.
STEP 1: On Domain Controller | |
| Test-KdsRootKey -KeyId (Get-KdsRootKey).KeyId |
| Add-KdsRootKey -EffectiveImmediately |
| $gMSAgrp = 'gMSA01SqlPrd' $gMSAAct = 'gMSA01' $gMSADNSHostName = 'gMSA01.azure.thojouno.com' New-ADGroup -Name $gMSAgrp -Description “Security group for Production SQL Servers” -GroupCategory Security -GroupScope Global Add-ADGroupMember -Identity $gMSAgrp -Members sqln1$, sqln2$, sqln3-dr$ Get-ADGroupMember -Identity $gMSAgrp |
| $gMSAgrp = 'gMSA01SqlPrd' $gMSAAct = 'gMSA01' $gMSADNSHostName = 'gMSA01.azure.thojouno.com' New-ADServiceAccount -Name $gMSAAct -PrincipalsAllowedToRetrieveManagedPassword $gMSAgrp -Enabled:$true -DNSHostName $gMSADNSHostName -SamAccountName $gMSAAct -ManagedPasswordIntervalInDays 30 |
Step 2: On each SQL AlwaysOn Replica (repeat for each node) | |
1. Reboot each replica node so that group membership takes affect |
|
2. Install group managed account on node and add managed service account group to local administrators group | $gMSAgrp = 'gMSA01SqlPrd' $gMSAAct = 'gMSA01' $gMSAUsr = 'Azure\gMSA01$' Install-WindowsFeature -Name RSAT-AD-PowerShell Install-ADServiceAccount -Identity $gMSAAct Test-ADServiceAccount -Identity $gMSAAct Add-LocalGroupMember -Group "Administrators" -Member $gMSAgrp |
3. Grant managed service account connect permissions to the SQL endpoint | USE [master] GO CREATE LOGIN [Azure\gMSA01$] FROM WINDOWS WITH DEFAULT_DATABASE=[master] GO GRANT CONNECT ON ENDPOINT::hadr_endpoint TO [Azure\gMSA01$] GO ALTER ENDPOINT hadr_endpoint STATE=STOPPED ALTER ENDPOINT hadr_endpoint STATE=STARTED |
STEP 3: Update SQL Service and Agent accounts on each replica | |
1. Using dbatools, update SQL service and SQL agent account passwords | #if you don't have internet connectivity, you can always update the SQL service account # via the SQL Server Configuration utility Install-Module dbatools $gMSAAct = 'gMSA01' $gMSAUsr = 'Azure\gMSA01$' Import-Module dbatools Update-DbaServiceAccount -ServiceName MSSQLSERVER -Username $gMSAUsr Update-DbaServiceAccount -ServiceName SQLSERVERAGENT -Username $gMSAUsr Restart-Service MSSQLSERVER |