LLI Wiki — My Digital Knowledge Base

Kerberos: ticket flow, double hop, SPNs and firewall ports

How Kerberos works, the double-hop scenario with delegation to SQL Server, SPN registration and the ports to open.

Kerberos is the default authentication protocol in Active Directory. This article summarises the normal ticket flow, the "double hop" scenario (web front end delegating to SQL Server), the SPNs to register for it, and the ports to open between domains or forests.

Normal Kerberos flow

  1. The password is converted to an NTLM hash. A timestamp is encrypted with that hash and sent to the KDC (Key Distribution Center, on the domain controller) as an authenticator in the Ticket-Granting Ticket request (AS-REQ). The KDC checks the user (logon restrictions, group membership...) and creates the TGT.
  2. The TGT is encrypted, signed and returned to the user (AS-REP). Only the Kerberos service (KRBTGT) of the domain can open and read the TGT data.
  3. To reach a service, the user presents the TGT to the DC (TGS-REQ). The DC opens the TGT and validates the PAC checksum. If both are valid, the TGT data is effectively copied to create the service ticket.
  4. The service ticket (TGS) is encrypted with the password hash of the target service account and sent to the user (TGS-REP).
  5. The user connects to the server hosting the service on the appropriate port and presents the ticket (AP-REQ). The service opens it with its own password hash.

Kerberos authentication sequence across trusts

Double hop with delegation

Typical case: a reporting web application that queries SQL Server on behalf of the user.

  1. The user accesses http://reports.contoso.com with anonymous credentials.
  2. The web server returns HTTP 401.2 with an Authenticate header.
  3. The user requests a ticket for the SPN registered for the site (http/reports.contoso.com).
  4. The KDC returns the ticket if the SPN is found, encrypted with the key of the account the SPN is registered on (for example CONTOSO\svc_web).
  5. The user authenticates to the web application with this ticket.
  6. The web application account decrypts and validates the ticket.
  7. The web application account requests a ticket for the SQL Server SPN, for example MSSQLSvc/sqlserver01.contoso.com:1433.
  8. The KDC returns the ticket if the SPN is found, encrypted with the key of the SQL Server service account (for example CONTOSO\svc_sql).
  9. The web application authenticates to SQL Server with that ticket and impersonates the user, using delegation rights.
  10. The SQL Server service account decrypts and validates the ticket.
  11. SQL Server returns the data to the web server.
  12. The web server returns the page to the user.

Step 9 requires the web application account to be allowed to delegate (constrained or unconstrained delegation configured in Active Directory).

Kerberos exchanges with an application server using unconstrained delegation

Kerberos double hop diagram between client, front-end and back-end servers

Delegation tab of a service account with constrained delegation to MSSQLSvc port 1433

SPN registration

Register the SPNs on the account that actually runs the service.

SQL Server running under a domain account:

setspn -A MSSQLSvc/sqlserver01:1433 CONTOSO\svc_sql
setspn -A MSSQLSvc/sqlserver01.contoso.com:1433 CONTOSO\svc_sql

IIS running as Local System (the SPN goes on the computer account):

setspn -a http/web01 web01$
setspn -a http/web01.contoso.com web01$

Web application / reporting service running under a domain account:

setspn -a http/web01 CONTOSO\svc_web
setspn -a http/web01.contoso.com CONTOSO\svc_web

Be careful: the last two blocks register the same http/web01 SPN on two different accounts. This creates a duplicate SPN and Kerberos authentication will fail. Register each SPN on one account only.

List the SPNs registered on an account with setspn -l <account>:

setspn -l web01
Registered ServicePrincipalNames for CN=WEB01,OU=Servers,DC=contoso,DC=com:
    TERMSRV/WEB01
    TERMSRV/web01.contoso.com
    WSMAN/web01
    WSMAN/web01.contoso.com
    RestrictedKrbHost/WEB01
    HOST/WEB01
    RestrictedKrbHost/web01.contoso.com
    HOST/web01.contoso.com

setspn -l CONTOSO\svc_web
Registered ServicePrincipalNames for CN=svc_web,OU=ServiceAccounts,DC=contoso,DC=com:
    HTTP/web01.contoso.com
    HTTP/web01

setspn -l CONTOSO\svc_sql
Registered ServicePrincipalNames for CN=svc_sql,OU=ServiceAccounts,DC=contoso,DC=com:
    MSSQLSvc/sqlserver01.contoso.com:14331
    MSSQLSvc/sqlserver01:14331
    MSSQLSvc/sqlserver01.contoso.com:14330
    MSSQLSvc/sqlserver01:14330
    MSSQLSvc/sqlserver01:1433

With several instances on one host, each instance needs its own SPN with its own port.

Firewall ports

Ports required between clients and domain controllers (including across trusts):

Client ports Server port Service
49152-65535/UDP 123/UDP W32Time
49152-65535/TCP 135/TCP RPC endpoint mapper
49152-65535/TCP 464/TCP/UDP Kerberos password change
49152-65535/TCP 49152-65535/TCP RPC for LSA, SAM, Netlogon (*)
49152-65535/TCP/UDP 389/TCP/UDP LDAP
49152-65535/TCP 636/TCP LDAP SSL
49152-65535/TCP 3268/TCP LDAP global catalog
49152-65535/TCP 3269/TCP LDAP global catalog SSL
53, 49152-65535/TCP/UDP 53/TCP/UDP DNS
49152-65535/TCP 49152-65535/TCP FRS RPC (*)
49152-65535/TCP/UDP 88/TCP/UDP Kerberos
49152-65535/TCP/UDP 445/TCP SMB (**)
49152-65535/TCP 49152-65535/TCP DFSR RPC (*)

References

Mastodon LLIMastodon SocialFosstodon