Active Directory Series

🤖 The Top 1% Hands-On for Escaping Service Account Password Management With a gMSA

Introduction

This article is part of the Top 1% Series Complete Article Guide, the 36th article in the Active Directory Series.

Prerequisites

Why Traditional Service Accounts Were a Problem in the First Place

At many organizations, a service account named something like svc-app gets a fixed password set by an administrator, written down somewhere, and registered as the account a service runs under. In many cases, this password never actually gets changed, even once the password policy’s expiration date arrives. That’s because changing the password requires updating every single service configuration using that account at the same time — forget even one, and you get a service outage — so in practice, many organizations decide “if it’s working, don’t touch it,” and the same password stays in use for years. This is a clear security risk.

The Big Picture

This hands-on consists of four steps.

graph LR
    Step1["Step1<br/>Create the KDS root key"]
    Step2["Step2<br/>Create the gMSA"]
    Step3["Step3<br/>Install the gMSA on<br/>the target server"]
    Step4["Step4<br/>Switch the service's<br/>run-as account to the gMSA"]
    Step1 --> Step2 --> Step3 --> Step4

Hands-On Steps

Step 1: Create the KDS root key

A gMSA’s password is automatically generated by AD DS itself, based on a forest-wide key called the KDS (Key Distribution Services) root key. If you haven’t already, create exactly one for your forest.

Add-KdsRootKey -EffectiveTime ((Get-Date).AddHours(-10))

Notice that -EffectiveTime is specified as a time in the past. In production, you’d normally have to wait for this KDS root key to reliably replicate out to every DC, which by default means the gMSA can’t actually be used for about 10 hours after creation. If you want to verify this works right away in a test environment, backdating the effective time like this skips that wait entirely.

Step 2: Create the gMSA

Create the gMSA account, scoped to the server permitted to use it (WebSrv01 in this case).

New-ADServiceAccount -Name "gmsa-webapp" -DNSHostName "gmsa-webapp.example.com" -PrincipalsAllowedToRetrieveManagedPassword "WebSrv01$"

Only the computers (or groups) specified in -PrincipalsAllowedToRetrieveManagedPassword can retrieve this gMSA’s current password. Any server not listed here will fail to retrieve the password, even if you try to configure this gMSA as a service’s run-as account there.

Step 3: Install the gMSA on the target server

Log onto WebSrv01 and make this gMSA usable there.

Install-ADServiceAccount -Identity "gmsa-webapp"
Test-ADServiceAccount -Identity "gmsa-webapp"

If Test-ADServiceAccount returns True, WebSrv01 is correctly able to retrieve this gMSA’s password.

Step 4: Switch the service’s run-as account to the gMSA

Change the target Windows service’s run-as account to this gMSA.

Set-Service -Name "MyAppService" -Credential (New-Object System.Management.Automation.PSCredential ("EXAMPLE\gmsa-webapp$", (New-Object System.Security.SecureString)))

The single most important thing here is that we’re passing an empty password in the password field. A gMSA’s account name gets a trailing $, and no password is specified at all. Once Windows recognizes this account as a gMSA, it never prompts for a password — it automatically retrieves the current password from AD DS whenever it needs to authenticate. The administrator never needs to know, or ever type, this account’s actual password, at any point.

What a Pro Sees Here (Top 1% Understanding)

A gMSA’s password automatically rotates roughly every 30 days by default

A gMSA’s password is automatically updated by AD DS itself, at the interval set in the msDS-ManagedPasswordInterval attribute (30 days by default). The administrator never has to do anything for this automatic rotation, and services using the gMSA transparently switch to authenticating with the new password without ever noticing it changed behind the scenes. This is conceptually very similar to the mechanism covered in Understanding the Netlogon Service and the Secure Channel, where a computer account’s password rotates automatically.

The difference between a gMSA and its older predecessor, the standalone MSA (sMSA)

Before gMSA, there was an even older mechanism called the sMSA (standalone Managed Service Account). sMSA shared the same idea of automatic password management, but had a major limitation: a single sMSA account could only ever be used on one server. gMSA’s biggest advance is removing that limitation: by specifying multiple servers (or a group containing them) in PrincipalsAllowedToRetrieveManagedPassword, the same gMSA can be shared across multiple servers — a load-balanced fleet of web servers, for example.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. Test-ADServiceAccount returns False: Check whether the KDS root key’s propagation has completed (10 hours since creation, in production), and whether the target server is correctly listed in PrincipalsAllowedToRetrieveManagedPassword.
  2. The service fails to authenticate at startup: Check whether the service’s run-as account name is in the correct gMSA format, with the trailing $ (EXAMPLE\gmsa-webapp$).
  3. You want to share the same gMSA across multiple servers, but only one succeeds: Check whether the failing server is actually included in PrincipalsAllowedToRetrieveManagedPassword.

Summary

Takeaways to Apply Today

  1. When you need a new service account, consider whether a gMSA can achieve it before reaching for the traditional approach.
  2. When creating a new KDS root key in production, factor the roughly 10-hour propagation wait into your work plan.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).