Implementing Kerberos Authentication

1. Understanding Kerberos Protocol

ComponentRole
KDCKey Distribution Center (AS + TGS)
ASAuthentication Server — issues TGT
TGSTicket Granting Service — issues service tickets
PrincipalNamed entity (user@REALM, HTTP/host@REALM)
RealmAdministrative authentication domain

2. Implementing Kerberos Authentication Flow

1. User → AS: AS-REQ (preauth with password-derived key)
2. AS → User: TGT encrypted with TGS key + session key encrypted with user key
3. User → TGS: TGS-REQ (TGT + service principal)
4. TGS → User: Service ticket encrypted with service key
5. User → Service: AP-REQ with service ticket
6. Service decrypts ticket → authenticated
      

3. Using Ticket Granting Ticket

PropertyDetail
Issued byAS at initial login
LifetimeDefault 10 hours, renewable 7 days
Encrypted withTGS service key (krbtgt)
CacheCredential cache (ccache) on client
RiskPass-the-ticket / Golden Ticket if krbtgt key stolen

4. Requesting Service Tickets

StepDetail
SPNService Principal Name (e.g., HTTP/web.example.com@REALM)
TGS-REQIncludes TGT + SPN
TGS-REPService ticket encrypted with service's long-term key
EncryptionAES-256-CTS-HMAC-SHA1 preferred (RC4 deprecated)

5. Validating Kerberos Tickets

CheckDetail
DecryptWith service's keytab key
AuthenticatorValidates timestamp (≤5 min skew)
ReplayCache authenticator until ticket exp
PACValidate Privilege Attribute Certificate signature (AD)

6. Implementing Key Distribution Center

ImplementationNotes
MIT KerberosReference, Unix/Linux
HeimdalBSD-licensed alternative
Active DirectoryMicrosoft's KDC + LDAP combined
Ports88/tcp+udp (KDC), 464 (kpasswd)

7. Using Kerberos with Active Directory

ConceptDetail
AD = KDC + LDAPDCs serve both
SPN registrationsetspn -A HTTP/host service-account
KeytabGenerated via ktpass
SPNEGOHTTP "Negotiate" wraps Kerberos for browsers

8. Implementing Kerberos Delegation

TypeDetail
UnconstrainedService can impersonate user anywhere — risky AVOID
Constrained (S4U2Proxy)Limited to specific SPNs
Resource-Based (RBCD)Target resource grants delegation
Protocol Transition (S4U2Self)Service obtains ticket as user without password

9. Handling Kerberos Ticket Expiration

EventAction
TGT expiresRe-prompt for credentials or use renewable until renew_till
Service ticket expiresRequest new from TGS using TGT
Clock skew >5 minKRB_AP_ERR_SKEW — sync NTP
Renewalkinit -R before renew_till

10. Implementing Cross-Realm Authentication

ConceptDetail
TrustRealms share inter-realm krbtgt keys
Transitive trustA trusts B, B trusts C → A trusts C (AD forests)
ReferralKDC returns ticket to remote realm's TGS
CaveatEach cross-realm hop must be auditable