Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 38 ยท Authentication: Kerberos

SPNs, Kerberos Delegation and Managed Service Accounts

Learn Service Principal Names, why duplicate SPNs break Kerberos, how unconstrained, constrained and resource-based delegation differ, and why gMSAs are safer service accounts.

Kerberos tickets are issued for services, and a service is identified by its Service Principal Name (SPN). If the SPN is missing, wrong or registered twice, the client cannot get a ticket and quietly falls back to NTLM, or fails altogether. SPNs are therefore the most common thing you will fix in a Kerberos problem.

The second half of this lesson covers delegation: letting a service act on behalf of a user, for example a web front end that reads the user's files on a back-end server. Delegation is powerful and dangerous, so you will learn the three kinds and which to prefer. Windows commands appear as read-only blocks; the Python examples parse and audit SPNs and delegation settings.

SPN format

TEXT
service/host[:port][/service-name]
SPN Meaning
cifs/files.example.com File share on host files
HTTP/intranet.example.com Web site; also used for IIS application pools
MSSQLSvc/sql01.example.com:1433 SQL Server instance on port 1433
HOST/pc042 Alias that covers many default services of a computer
ldap/dc1.example.com/example.com LDAP service on a domain controller for a domain

The SPN is stored in the multi-valued attribute servicePrincipalName of the account that runs the service: a computer account for services running as Network Service or Local System, or a user (or managed service) account for services with their own identity. Computer accounts automatically get HOST/ and RestrictedKrbHost/ SPNs, which stand in for many standard services.

To manage them from a Windows command line (read-only here):

TEXT
setspn -L svc-sql
setspn -S MSSQLSvc/sql01.example.com:1433 EXAMPLE\svc-sql
setspn -X

-L lists the SPNs on an account, -S adds one after checking for duplicates (prefer it to -A), and -X searches the forest for duplicates.

Duplicate SPNs

An SPN must be unique in the forest. If two accounts hold HTTP/intranet.example.com, the KDC does not know whose key to use to encrypt the ticket. The result is Kerberos failure, with a KRB_AP_ERR_MODIFIED error on the client or a "multiple accounts with the same SPN" event on the domain controller. The usual cause is a website moved from one service account to another without removing the old SPN.

Also remember the client builds the SPN from the name you typed. Browsing to https://intranet (an alias) asks for HTTP/intranet; connecting by IP address asks for nothing useful and falls back to NTLM.

Python SPN parser and duplicate finder

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Delegation: acting on behalf of a user

Imagine a web portal that must open the user's files on a file server as that user, so file permissions still apply. The portal needs a ticket to the file server in the user's name. Kerberos supports this through delegation, in three flavours.

Unconstrained delegation. The account is trusted to delegate to any service. Technically the user sends a forwardable copy of their TGT to the front end, which can then impersonate the user anywhere. If that server is compromised (and an administrator once connected to it), the attacker collects TGTs and owns the domain. Domain controllers have it by design; everything else should not. Audit it regularly.

Constrained delegation. The service account is configured with an explicit list of target SPNs (msDS-AllowedToDelegateTo), for example only cifs/files.example.com. It uses protocol extensions (S4U2Self and S4U2Proxy) to request tickets only for those targets. The front-end's administrator decides what it may reach, which is a weakness: a front-end admin can grant themselves access to a back-end they do not own.

Resource-based constrained delegation (RBCD). The decision moves to the back-end: the target account lists which front-end accounts may delegate to it, in the attribute msDS-AllowedToActOnBehalfOfOtherIdentity. Back-end owners control their own exposure and cross-domain delegation works. It is the recommended model today.

Accounts can also be marked Account is sensitive and cannot be delegated, and members of the Protected Users group cannot be delegated at all, which shields privileged accounts.

Python Delegation audit (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two PowerShell queries that find these in a real domain are Get-ADComputer -Filter {TrustedForDelegation -eq $true} and the same filter on Get-ADUser, shown in the PowerShell lesson.

Managed service accounts

Running a service as a normal user account means a password that someone types, sets to "never expires" and forgets. That is exactly what Kerberoasting attacks target. Group Managed Service Accounts (gMSA) fix this:

  • The password is a 240-byte random value managed by Active Directory and rotated automatically (every 30 days by default).
  • No human ever knows it. Authorised computers (listed in PrincipalsAllowedToRetrieveManagedPassword) fetch it from a domain controller.
  • One gMSA can run the same service on a whole server farm.
  • SPN registration is handled by the account.

Creating one needs the KDS root key to exist in the forest (once) and then something like (read-only):

POWERSHELL
New-ADServiceAccount -Name gmsa-web -DNSHostName gmsa-web.example.com `
  -PrincipalsAllowedToRetrieveManagedPassword WebServers -KerberosEncryptionType AES256
Install-ADServiceAccount gmsa-web

Use gMSAs wherever the service supports them (IIS application pools, SQL Server, scheduled tasks). Where one is not possible, set a long (25+ character) random password and AES-only encryption.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which SPN is correct for a SQL Server instance listening on port 1433?

    The format is service/host:port, with MSSQLSvc as the service class for SQL Server.
  2. 2. Two accounts hold the same SPN. What happens?

    SPNs must be unique within the forest; duplicates break ticket issuance and cause fallback or errors.
  3. 3. Which delegation model lets the back-end resource decide who may delegate to it?

    RBCD stores the allowed front ends on the target in msDS-AllowedToActOnBehalfOfOtherIdentity.
  4. 4. Why prefer a gMSA to a normal service account?

    That removes the weak, never-expiring password that Kerberoasting targets.

Summary

  • An SPN names a service; it lives on the account that runs it and must be unique in the forest.
  • Duplicate or missing SPNs cause failures and NTLM fallback; setspn -S and -X help.
  • Avoid unconstrained delegation, prefer resource-based constrained delegation, and protect admins with Protected Users.
  • Use gMSAs for services to get automatic strong passwords.

Next: Kerberos Errors, NTLM and Troubleshooting