{"id":1752,"date":"2019-06-07T01:00:00","date_gmt":"2019-06-07T01:00:00","guid":{"rendered":"http:\/\/inswwdev.azurewebsites.net\/au\/insights\/uncategorized\/azure-ad-seamless-sso-kerberos-key-using-azure-automation-and-hybrid-runbook-worker-part-2-of-2\/"},"modified":"2024-09-13T03:54:09","modified_gmt":"2024-09-13T03:54:09","slug":"azure-ad-seamless-sso-kerberos-key-using-azure-automation-and-hybrid-runbook-worker-part-2-of-2","status":"publish","type":"post","link":"https:\/\/www.insentragroup.com\/us\/insights\/geek-speak\/cloud-and-modern-data-center\/azure-ad-seamless-sso-kerberos-key-using-azure-automation-and-hybrid-runbook-worker-part-2-of-2\/","title":{"rendered":"Azure AD Seamless SSO Kerberos Key Using Azure Automation and Hybrid Runbook Worker (Part 2 of 2)"},"content":{"rendered":"<p style=\"text-align: left;\">In\u00a0<a href=\"https:\/\/inswwdev.azurewebsites.net\/au\/neil-hoffmans-rotating-the-azure-ad-seamless-sso-kerberos-key-manually-part-1-of-2\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Part 1<\/a>\u00a0of this series, we looked at how to rotate this sensitive key manually.\u00a0 In this blog, we will go through how to automate the process.<\/p>\n<p style=\"text-align: left;\">There are several ways to automate this, the most obvious being a PowerShell Script run with Task Scheduler on your AD Connect Server but that introduces challenges to store the passwords for both accounts needed to execute the script.\u00a0 There are methods to save passwords using secure strings in password files, but they come with some limitations.<\/p>\n<p style=\"text-align: left;\">I see this as a perfect opportunity to use\u00a0<a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/automation\/\" rel=\"nofollow noopener\" target=\"_blank\">Azure Automation<\/a>\u00a0as it has a nifty feature called Credential Assets that will allow you to securely store credentials for just such an occasion.\u00a0 Azure Automation natively runs in Azure against publicly exposed endpoints such as Azure PowerShell, Exchange Online PowerShell etc., however by utilizing the Hybrid Runbook Worker feature, we will be able to execute scripts securely on servers within your datacenter as required here.<\/p>\n<p style=\"text-align: left;\">So, let\u2019s review\u2026<\/p>\n<p style=\"text-align: left;\">Automation Accounts = Cool<\/p>\n<p style=\"text-align: left;\">Automation Accounts + Credential Assets = Really Cool<\/p>\n<p style=\"text-align: left;\">Automation Accounts + Credential Assets + Hybrid Runbook Workers = Wickedly Cool!<\/p>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020; text-align: left;\">Let\u2019s get started!<\/h3>\n<p style=\"text-align: left;\">We will be using the AD Connect server as the Hybrid Runbook Worker since the script needs to be executed there anyway.\u00a0 If you are taking advantage of AD Connect Staging Mode, you can configure both the primary and staging servers as Hybrid Runbook Workers for redundancy.\u00a0 The script can be executed from either one.<\/p>\n<p style=\"text-align: left;\">You will need an Azure subscription associated with the same Azure AD Tenant as your Office 365 subscription. If you don\u2019t have one, just go to\u00a0<a href=\"https:\/\/portal.azure.com\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/portal.azure.com\/<\/a>\u00a0and create a free trial.\u00a0 The monthly cost to run the processes in this blog would be negligible so don\u2019t fret about that!<\/p>\n<p style=\"text-align: left;\"><strong>Step 1 \u2013\u00a0<\/strong>In your Azure Subscription, navigate to\u00a0<a href=\"https:\/\/portal.azure.com\/#blade\/HubsExtension\/BrowseResourceGroupBlade\/resourceType\/Microsoft.Resources%2Fsubscriptions%2FresourceGroups\" rel=\"nofollow noopener\" target=\"_blank\">Resource Groups<\/a>\u00a0and create a Resource Group to house the Azure components.\u00a0 Give it an appropriate name and choose the region based on your location then click Create.<\/p>\n<p style=\"text-align: left;\"><strong>Step 2 \u2013\u00a0<\/strong>In your Azure subscription, navigate to\u00a0<a href=\"https:\/\/portal.azure.com\/#blade\/HubsExtension\/BrowseResourceBlade\/resourceType\/Microsoft.Automation%2FAutomationAccounts\" rel=\"nofollow noopener\" target=\"_blank\">Automation Accounts<\/a>\u00a0and create an Automation Account (or you can use an existing one).\u00a0 Give it an appropriate name, choose the Resource Group created in Step 1 and choose the region based on your location then click Create.<\/p>\n<p style=\"text-align: left;\"><strong>Step 3 \u2013\u00a0<\/strong>In your Azure subscription, navigate to\u00a0<a href=\"https:\/\/portal.azure.com\/#blade\/HubsExtension\/BrowseResourceBlade\/resourceType\/Microsoft.OperationalInsights%2Fworkspaces\" rel=\"nofollow noopener\" target=\"_blank\">Log Analytic Workspaces<\/a>\u00a0and create a Log Analytics Workspace (or you can use an existing one).\u00a0 Choose the Resource Group created in Step 1 and choose the same region as you did for your Automation Account then click OK.<\/p>\n<p style=\"text-align: left;\">Once the Log Analytics Workspace is created, navigate to General \u2013 Workspace summary and click the + Add button to install the Azure Automation solution which will allow you to create Hybrid Runbook Workers.\u00a0 Search for the \u201cAutomation Hybrid Worker\u201d solution then click Create.<\/p>\n<p style=\"text-align: left;\"><strong>Step 4-\u00a0<\/strong>Create your accounts.<\/p>\n<ul style=\"text-align: left;\">\n<li>Create the on-premises AD service account and set the password to not expire. No special group memberships are needed aside from Domain Users.<\/li>\n<li>Create the cloud service account- you can optionally use on-premises service account, just make sure that it\u2019s synched and has a verified UPN suffix. This account must be a Global Admin in Azure AD.<\/li>\n<\/ul>\n<p style=\"text-align: left;\"><strong><em>Note: Multi-Factor Authentication must be disabled for the cloud service account or at least bypassed if connecting from your datacenter IP ranges<\/em><\/strong><\/p>\n<p style=\"text-align: left;\"><strong>Step 5 \u2013<\/strong>\u00a0Locate the computer account AZUREADSSOACC, which by default is in the Computers container.\u00a0 Right click it, choose properties and go to the security tab.\u00a0 Add the on-premises service account created in Step 4 and grant these two permissions: Write &amp; Reset Password then click OK.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 637px; height: 406px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_1.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/fc47d91829c140cabddf4c0008beb6d3\" \/><\/p>\n<p style=\"text-align: left;\"><strong>Step 6 \u2013\u00a0<\/strong>You must reset the AZUREADSSOACC Kerberos Key in each AD Domain within the Forest where AD Connect Seamless SSO is enabled.\u00a0 To determine which domains are configured in your environment, do the following on either AD Connect Server from PowerShell:<\/p>\n<p style=\"text-align: left;\">Import-Module \u201cC:\\Program Files\\Microsoft Azure Active Directory Connect\\AzureADSSO.psd1\u201d<\/p>\n<p style=\"text-align: left;\">New-AzureADSSOAuthenticationContext #Sign in with a Global Admin account<\/p>\n<p style=\"text-align: left;\">Get-AzureADSSOStatus | ConvertFrom-Json<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 512px; height: 185px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_2.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/b39b0c1df263442589b7bfb2976c3ebb\" \/><\/p>\n<p style=\"text-align: left;\">If you have multiple domains, you would need to reset the AZUREADSSOACC password in each domain which can be done by modifying the script provided below and assigning the appropriate permissions on each object.<\/p>\n<p style=\"text-align: left;\"><strong>Step 7 \u2013<\/strong>\u00a0In order to enable the Hybrid Runbook Worker role, you must first Install the Microsoft Monitoring Agent (MMA) to your AD Connect Server(s).\u00a0 Go to your Log Analytics Workspace created in Step 3 and navigate to Settings \u2013 Advanced Settings \u2013 Connected Sources \u2013 Windows Servers.\u00a0 From here you can download and install the Agent.\u00a0 You must also copy the Workspace ID and the Primary Key<\/p>\n<p style=\"text-align: left;\">\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 844px; height: 366px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_3.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/4d5c86f69aa249328fbedfbf575bdf6b\" \/><\/p>\n<p style=\"text-align: left;\">Run the MMA agent install wizard on your AD Connect Server(s) and choose \u201cConnect to Azure Log Analytics (OMS)\u201d, enter the Workspace ID and Key and finish the wizard.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 852px; height: 312px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_4.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/7fde0d663cb74f8eb800f51387969e94\" \/><\/p>\n<p style=\"text-align: left;\"><strong>Step 8 \u2013<\/strong>\u00a0Navigate to the Automation Account from Step 2 and select Keys.\u00a0 Copy the Primary Key and the URL<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 796px; height: 495px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_5.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/4dcbbb16f0314ed181be0116efd6be56\" \/><\/p>\n<p style=\"text-align: left;\">Register the AD Connect Server(s) as a Hybrid Runbook Worker by opening an elevated PowerShell window and navigating to the following directory:<\/p>\n<p style=\"text-align: left;\">\u201cC:\\Program Files\\Microsoft Monitoring Agent\\Agent\\AzureAutomation\\&lt;version&gt;\\HybridRegistration\u201d<\/p>\n<p style=\"text-align: left;\">Run the following commands:<\/p>\n<p style=\"text-align: left;\">Import-Module .\\HybridRegistration.psd1<\/p>\n<p style=\"text-align: left;\">Add-HybridRunbookWorker \u2013GroupName &lt;String&gt; -EndPoint &lt;Url&gt; -Token &lt;String&gt;<\/p>\n<ul style=\"text-align: left;\">\n<li>GroupName: This is the name of the Hybrid Worker Group. Either the node will be added to an existing group or a new group will be created if it doesn\u2019t exist.<\/li>\n<li>Endpoint: This is the URL<\/li>\n<li>Token: This is the Primary Key<\/li>\n<\/ul>\n<p style=\"text-align: left;\">Example:\u00a0Add-HybridRunbookWorker \u2013GroupName ADConnectWorkerGroup -EndPoint https:\/\/eus2-agentservice-prod-1.azure-automation.net\/accounts\/f48fa7ee-xxxxx-xxxxxx-xxxxx2-010f5894fc07 -Token 6b0Exxxxxxxxxxxxxxxxxx2XpwOhelZI7wbWA5f5Kxuyr9RXs9LyipgIR5CBw==<\/p>\n<p style=\"text-align: left;\">Once this is completed you should now see the Hybrid Worker Group and The Workers within that group by navigating to the Automation Account and navigating to Process Automation \u2013 Hybrid worker groups<\/p>\n<p style=\"text-align: left;\"><strong>Step 9 \u2013<\/strong>\u00a0Navigate to the Automation Account created in Step 2 and select Credentials<\/p>\n<ul style=\"text-align: left;\">\n<li>Create on-premises Credential\n<ul>\n<li>This is the on-premises account from in Step 4. Use the SamAccountName format e.g. DOMAIN\\Username and the non-expiring password that you used to create the account.\u00a0 In the example below this Credential is called AADSSOOnPremCredential.<\/li>\n<\/ul>\n<\/li>\n<li>Create Cloud Credential\n<ul>\n<li>This is the global admin account from Step 4. Use the fully qualified UPN format e.g. Username@domain.com.\u00a0 In the example below this credential is called AADSSOCloudCredential.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: left;\"><strong>Step 10 \u2013<\/strong>\u00a0Navigate to the Automation Account created in Step 2 and select Runbooks (there will be some tutorial Runbooks which you can leave there)<\/p>\n<p style=\"text-align: left;\">Create a new Runbook of type PowerShell, in this example we are calling it \u201cResetAADSeamlessSSOKerberosKey\u201d.\u00a0 Once you create the Runbook, you will be brought to the Runbook edit screen.\u00a0 Copy the below script, substitute the Credential names as necessary:<\/p>\n<p style=\"text-align: left;\"># This script will trigger a reset of the Kerberos key for Azure AD SSO \u2013 this should be run every 30 days<\/p>\n<p style=\"text-align: left;\">$OnPremCred = Get-AutomationPSCredential -Name \u201cAADSSOOnPremCredential\u201d<\/p>\n<p style=\"text-align: left;\">$CloudCred = Get-AutomationPSCredential -Name \u201cAADSSOCloudCredential\u201d<\/p>\n<p style=\"text-align: left;\">Import-Module \u201cC:Program FilesMicrosoft Azure Active Directory ConnectAzureADSSO.psd1\u201d<\/p>\n<p style=\"text-align: left;\">New-AzureADSSOAuthenticationContext -CloudCredentials $CloudCred<\/p>\n<p style=\"text-align: left;\">Update-AzureADSSOForest -OnPremCredentials $OnPremCred -PreserveCustomPermissionsOnDesktopSsoAccount<\/p>\n<p style=\"text-align: left;\">Once your script is setup, click Save and Publish.<\/p>\n<p style=\"text-align: left;\"><strong>Step 11 \u2013<\/strong>\u00a0Testing.\u00a0 In order to test, navigate to the Automation Account \u2013 Runbooks \u2013 The Runbook you created and select \u201cStart\u201d.\u00a0\u00a0<strong><em>Note: this should be tested first in a lab environment or during a maintenance window<\/em><\/strong><\/p>\n<p style=\"text-align: left;\"><strong><em><img decoding=\"async\" style=\"width: 783px; height: 379px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_6.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/951f6109e3834dfd96363a651b2523a8\" \/><\/em><\/strong><\/p>\n<p style=\"text-align: left;\">Under Run Settings choose \u201cHybrid Worker\u201d and choose your Hybrid Worker Group.\u00a0 Then click OK.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 511px; height: 471px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_7.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/1f3093dc774f46f6872d70f71c390924\" \/><\/p>\n<p style=\"text-align: left;\">Wait until the Status shows \u201cCompleted\u201d then click on the Output tab and you should see \u201cThe operation completed successfully\u201d.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 755px; height: 474px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_8.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/f329c73329584cae8a64445e0b1edc16\" \/><\/p>\n<p style=\"text-align: left;\">Finally, to confirm that it worked, open PowerShell from a Domain Controller and run:<\/p>\n<p style=\"text-align: left;\">Get-ADComputer AZUREADSSOACC -Properties * | FL Name,PasswordLastSet<\/p>\n<p style=\"text-align: left;\">The timestamp should coincide with the Runbook execution.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 799px; height: 123px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_9.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/3ad43724ca4446d496f3721d07844a29\" \/><\/p>\n<p style=\"text-align: left;\"><strong>At this point verify that Seamless SSO still works.<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>Step 12 \u2013<\/strong>\u00a0Go to the Automation Account and navigate to Shared Resources \u2013 Schedules and create a Schedule to run once a month on the appropriate day and click Create.\u00a0 Then navigate to the Automation Account, select Runbooks, choose your Runbook and select Schedules.\u00a0 Link the Schedule you just created.\u00a0 Under \u201cParameters and run settings\u201d choose your Hybrid Worker Group then click OK.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" style=\"width: 789px; height: 360px;\" src=\"https:\/\/www.insentragroup.com\/wp-content\/uploads\/sites\/21\/2021\/02\/neil_hoffman_blog2_img_10.jpg\" alt=\"\" data-udi=\"umb:\/\/media\/8270647a301944f4a2ec1eb10a6444e3\" \/><\/p>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020; text-align: left;\">Summary<\/h3>\n<p style=\"text-align: left;\">We have successfully created an automated process that runs every 30 days to reset the Kerberos Key for Azure AD Seamless SSO account, AZUREADSSOACC, as per Microsoft\u2019s recommendation.\u00a0 We accomplished this by using Azure Automation and Hybrid Runbook Workers.\u00a0 I hope you enjoyed this blog and please reach out to us if you have any questions!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In\u00a0Part 1\u00a0of this series, we looked at how to rotate this sensitive key manually.\u00a0 In this blog, we will go through how to automate the process. There are several ways to automate this, the most obvious being a PowerShell Script run with Task Scheduler on your AD Connect Server but that introduces challenges to store&hellip; <a class=\"more-link\" href=\"https:\/\/www.insentragroup.com\/us\/insights\/geek-speak\/cloud-and-modern-data-center\/azure-ad-seamless-sso-kerberos-key-using-azure-automation-and-hybrid-runbook-worker-part-2-of-2\/\">Continue reading <span class=\"screen-reader-text\">Azure AD Seamless SSO Kerberos Key Using Azure Automation and Hybrid Runbook Worker (Part 2 of 2)<\/span><\/a><\/p>\n","protected":false},"author":91,"featured_media":1753,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-1752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-and-modern-data-center","entry"],"_links":{"self":[{"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/posts\/1752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/users\/91"}],"replies":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":5,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"predecessor-version":[{"id":9728,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/posts\/1752\/revisions\/9728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/media\/1753"}],"wp:attachment":[{"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.insentragroup.com\/us\/wp-json\/wp\/v2\/tags?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}