Active Directory Series

🔑 Understanding SPNs (Service Principal Names) from a "Top 1%" Perspective — How Kerberos Authentication Binds a Service to an Account

Introduction

This article is part of the Top 1% Series’ full article guide, and the eleventh article in the Active Directory series. Reading Understanding the Difference Between AD and DC, and Domains vs. Forests, from a “Top 1%” Perspective and What’s the Difference Between sysdm.cpl and netdom computername? first will make this article easier to follow.

Prerequisites

Getting the Big Picture

In a Nutshell

An SPN is like a service’s address — it’s what lets the KDC decide which account in AD DS a client’s “I want to access this service” request should be processed as a ticket for. The KDC searches AD DS for the account whose servicePrincipalName attribute holds the SPN the client presented, and encrypts the service ticket using the key derived from that account’s password. The key insight is that an SPN doesn’t point at “the server itself” — it points at “the account running that service.”

sequenceDiagram
    participant Client as Client
    participant KDC as KDC (DC)
    participant Server as Server hosting the service

    Client->>KDC: ① AS-REQ (username + pre-authentication)
    KDC-->>Client: Issues a TGT (Ticket-Granting Ticket)
    Note over Client: Wants to access the SPN<br/>"host/server1.corp.example.com"
    Client->>KDC: ② TGS-REQ (TGT + target SPN)
    Note over KDC: Searches for the account whose<br/>servicePrincipalName holds this SPN
    KDC-->>Client: Issues a service ticket encrypted<br/>with that account's key
    Client->>Server: ③ AP-REQ (presents the service ticket)
    Note over Server: Attempts to decrypt using the key<br/>derived from its own password
    Server-->>Client: Authentication succeeds if decryption works

Fundamentals, Explained Thoroughly

What “Accessing Multiple Services With One Authentication” Actually Means

The sequence diagram above only shows steps ② and ③ for a single service, but the convenience Kerberos is known for in practice — “log in once, and you don’t need to re-authenticate separately for every service” — more precisely means: “once you’ve obtained a TGT, all you need to do afterward, per service, is query the TGS to get an individual service ticket — you never need to redo the AS-REQ step (pre-authentication, which uses your password) to re-prove who you are.” In other words, a single ticket doesn’t universally work for every service — steps ② and ③ (TGS-REQ/TGS-REP, AP-REQ) happen again, every single time, for each service you access. That said, neither of those two steps ever involves the user’s password at all — they’re completed just by presenting the TGT you already hold — which is why, from the user’s perspective, it feels like “log in once, and you can access multiple services without a second thought.”

At What Point in a Connection Does the Kerberos Exchange Actually Happen?

If everything so far has felt like an abstract conversation about “talking to the KDC,” it helps to picture concretely where this fits into an actual network connection. Say a client is trying to access a shared folder like \\dbserver\share. Roughly, communication happens in this order:

  1. Name resolution: The hostname dbserver gets converted to an IP address via a DNS query.
  2. Establishing a TCP connection: A TCP connection is established to that IP address, on the target port (445 for SMB).
  3. Starting the application-layer protocol, and Kerberos authentication: Once the TCP connection is up, the application-layer protocol exchange (SMB, in this case) begins — and woven into that exchange, the client, behind the scenes, does an AS-REQ/AS-REP with the KDC (if it doesn’t already hold a TGT), then a TGS-REQ/TGS-REP for the target SPN (if it doesn’t already hold a service ticket for it), and finally presents the resulting service ticket to the target server as an AP-REQ. Since the TGT and service tickets are cached for a while, not every single one of these steps happens on every connection.

Keeping in mind that Kerberos authentication happens at a layer separate from IP routing or DNS resolution — closer to the application layer, as its own dedicated authentication exchange — and it happens after the TCP connection is already established, makes it clear why a network-layer connectivity check like ping or tracert alone can never surface a Kerberos problem. Communication with the KDC itself happens over UDP/TCP port 88.

The Concrete Format of an SPN

An SPN is expressed in the following format:

service-class/hostname:port/service-name

Some concrete examples:

Example SPNMeaning
HOST/server1.corp.example.comThe generic host service provided by server1 (covers many basic functions, including remote administration)
HTTP/intranet.corp.example.comWeb access aimed at intranet.corp.example.com (default ports 80/443)
MSSQLSvc/dbserver.corp.example.com:1433The SQL Server instance running on dbserver, on TCP port 1433
TERMSRV/rdshost.corp.example.comA Remote Desktop connection to rdshost

As touched on in What’s the Difference Between sysdm.cpl and netdom computername?, a computer account is automatically registered by default with an SPN in the form HOST/computer-name. This exists so that many basic services running on that computer (file sharing, printing, remote administration, and so on) can all authenticate by piggybacking off this one shared HOST SPN.

A Common Misconception: An SPN Is Registered on the Side Providing the Service, Not the Side Accessing It

This is a genuinely easy point to get backwards. The idea that “an account allowed to access a particular service has that service’s SPN registered on its own attributes” has the direction reversed. An SPN is registered on just one account — the one running the service itself — not on “every client that comes along to access that service.”

For example, if SQL Server is running on a server named dbserver, the SPN MSSQLSvc/dbserver.corp.example.com:1433 is registered on just one account: the service account SQL Server runs as. No matter how many hundreds or thousands of client accounts connect to that SQL Server, none of them ever get this SPN registered on themselves. A client is purely in the position of presenting a request to the KDC saying “I want to access whatever’s at this SPN” — it never needs to hold that SPN as an attribute of its own account at all.

The accurate way to think about it: it isn’t “the client holds a list, as SPNs, of the services it’s allowed to access” — it’s “the service itself holds, as its SPN, a self-introduction saying ‘I’m the one who answers to this name.’”

A Prerequisite: Both the Client and the Server Must Be Domain-Joined

Everything explained so far assumes both the client and the server providing the service are joined to a domain in the same forest (or to a separate domain with a trust relationship). Since both the SPN and the servicePrincipalName attribute are pieces of information registered against an account object in AD DS, a computer or user that has no AD DS account at all (i.e. isn’t domain-joined) simply can’t be a party to Kerberos authentication in the first place. Access to or from a non-domain-joined device or service uses some other authentication method instead of Kerberos — local account authentication, for instance.

What “Security Context” Actually Means

The term security context, which comes up repeatedly in this article and related ones, refers to which account’s privileges and identity a process or service is operating under at runtime. Saying “this service runs under the computer account’s own security context” means every operation that service performs is carried out with the computer account’s own privileges. When a service runs as a dedicated service account instead, it helps to picture that service’s security context as having switched from the computer account over to that dedicated service account.

Where an SPN Gets Registered: Computer Account vs. a Dedicated Service Account

An SPN is registered in the servicePrincipalName attribute of one of the account objects in AD DS — either a computer account or a user account. This is where an important practical choice comes in.

gMSAs (Group Managed Service Accounts) and their relationship to SPNs

Using a Group Managed Service Account (gMSA) automates SPN registration and updates in most cases. Configure a service to run as a gMSA, and Windows automatically registers and maintains the SPNs that service needs whenever it starts — cutting down significantly on how often you need to run setspn by hand. If you’ve been burned by SPN management headaches with a traditional service account (an ordinary user account), migrating to a gMSA is an option that substantially reduces that burden.

Checking, Adding, and Removing SPNs with setspn

SPN management is done with the setspn command (or PowerShell’s Set-ADComputer/Set-ADUser with the -ServicePrincipalNames parameter).

# List the SPNs registered on a given account
setspn -L server1

# Search the forest for who currently holds this SPN (useful for checking duplicates)
setspn -Q HTTP/intranet.corp.example.com

# Add an SPN (-A is the legacy option, which doesn't check for duplicates)
setspn -A HTTP/intranet.corp.example.com server1

# Add an SPN (-S is the safer option, which automatically checks for duplicates before adding)
setspn -S HTTP/intranet.corp.example.com server1

# Remove an SPN
setspn -D HTTP/intranet.corp.example.com server1

The difference between -A and -S matters in practice. -A simply adds the given SPN as-is, without checking whether the same SPN is already registered on some other account elsewhere in the forest. -S, on the other hand, searches the entire forest for duplicates before adding, and only proceeds if none are found. To head off the “duplicate SPN” problem covered next, using -S instead of -A is the recommended practice.

What Happens When SPNs Collide

An SPN needs to be unique across the entire forest. If the same SPN ends up registered on two or more accounts, the KDC can no longer uniquely identify which account a client’s presented SPN corresponds to, and ticket issuance fails with one of the following errors:

The typical real-world pattern that causes an SPN collision is changing the account a service runs under, adding the SPN to the new account, but never removing it from the old one. This leaves the same SPN sitting on both the old and new accounts, and Kerberos authentication starts failing with KDC_ERR_PRINCIPAL_NOT_UNIQUE. Whenever you change a service account, it’s essential to treat adding the SPN to the new account and removing it from the old account as one single, paired step.

What Happens When an SPN Isn’t Registered: A Silent Fallback to NTLM

If an SPN isn’t correctly registered, or is duplicated and can’t be resolved, Windows will (depending on configuration) sometimes give up on Kerberos authentication and fall back to NTLM authentication. What makes this tricky in practice is that you often don’t get an immediate error to alert you — instead, you end up in a state that looks like it’s working, where “authentication succeeds, but for some reason it’s using NTLM instead of Kerberos.” NTLM has more functional limitations than Kerberos (it can’t be delegated, it performs worse, and so on), and this can surface later as a seemingly unrelated problem, such as “double-hop authentication doesn’t work.” Whenever authentication itself succeeds but something feels off, the standard move is to first suspect whether that access is actually going over Kerberos at all.

The View From the Top 1% Perspective

Diagnosing SPN Problems That Cluster Around SQL Server

SQL Server is where SPN-related trouble tends to concentrate in practice. A typical case is changing SQL Server’s service account without updating the corresponding MSSQLSvc/... SPN, which is then left stale. The symptom in this case is often a partial malfunction that’s hard to pin down quickly: “the application’s connection to SQL Server itself succeeds (via NTLM), but only features that assume Kerberos — like double-hop authentication through delegation — fail.” The first diagnostic step is to run klist on the client to check what kind of ticket was actually obtained.

Checking ticket state with the klist command
# List the Kerberos tickets currently cached
klist

# Check the details of a ticket for a specific service
klist get MSSQLSvc/dbserver.corp.example.com:1433

If no ticket for the target service exists in the cache, or an attempt to obtain one errors out, that’s a strong signal there’s a problem with the SPN registration.

The Relationship Between SPNs and Delegation

SPNs also play a key role in configuring Kerberos delegation (the mechanism where one service accesses another service on a client’s behalf). When configuring constrained delegation, you explicitly specify, on the account’s properties, “which SPNs is this account allowed to delegate to.” When delegation is configured but doesn’t work, the basic troubleshooting step is to check whether the SPN you specified as the delegation target actually matches the SPN registered for that service. The mechanics of delegation itself are covered in more depth in a separate article on Kerberos authentication.

Common Misconceptions and Pitfalls

The Troubleshooting Perspective

Triage SPN-related failures around one axis: “is this SPN correctly registered on the one, single account it’s supposed to be on?”

  1. Access to a specific service alone fails with Kerberos authentication: Run setspn -L <account name> to check whether the SPN for that service is registered on the correct account.
  2. A KDC_ERR_PRINCIPAL_NOT_UNIQUE error occurs: Search the forest with setspn -Q <SPN> to check whether the same SPN is registered on multiple accounts, and remove the one that shouldn’t have it.
  3. Authentication succeeds, but only delegation-dependent features fail: Run klist on the client to check whether a Kerberos ticket was actually obtained for the target service (versus having fallen back to NTLM).
  4. Kerberos authentication started failing after changing a service account: Check whether the SPN is still sitting on the old account, and whether the migration to the new account’s SPN was fully completed.

Preventive Measures and Permanent Fixes

Summary

Things to Keep in Mind From Today

  1. Get in the habit of using setspn -S, which checks for duplicates, when adding SPNs.
  2. Whenever you change a service’s execution account, always plan the SPN addition and removal as one paired task.

References

Comments

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