Spring Boot
MSSQL
Kerberos
Authentication
Java

Spring Boot MSSQL Kerberos Authentication

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Spring Boot does not implement Kerberos for SQL Server by itself. The real work happens in the SQL Server JDBC driver, the JVM Kerberos configuration, and your Active Directory or KDC setup. When all three line up, Spring Boot can use a normal datasource configuration and connect to SQL Server with integrated authentication.

Configure the JDBC URL for Kerberos

For Microsoft SQL Server, the JDBC driver needs to know that it should use Kerberos rather than username-and-password authentication. A typical datasource URL looks like this:

yaml
1spring:
2  datasource:
3    url: jdbc:sqlserver://sql01.example.com:1433;databaseName=appdb;integratedSecurity=true;authenticationScheme=JavaKerberos;serverSpn=MSSQLSvc/sql01.example.com:1433
4    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

The important pieces are integratedSecurity=true and authenticationScheme=JavaKerberos. The serverSpn value should match the SQL Server service principal name registered in your directory service.

Make the JVM Kerberos-Aware

The JVM needs access to Kerberos realm and ticket information. In many environments, that means setting system properties when the Spring Boot app starts.

bash
1java \
2  -Djava.security.krb5.conf=/etc/krb5.conf \
3  -Djavax.security.auth.useSubjectCredsOnly=false \
4  -Dsun.security.krb5.debug=true \
5  -jar app.jar

krb5.conf tells Java where the realm and KDC live. The debug flag is extremely useful during setup because Kerberos failures are otherwise opaque.

If the application runs under a user that already has a valid Kerberos ticket cache, the driver can often use that cache directly. In server environments, teams sometimes use a keytab instead.

Using a JAAS Login With a Keytab

When a service account should authenticate non-interactively, define a JAAS entry and point the JVM at it.

properties
1SqlJaas {
2  com.sun.security.auth.module.Krb5LoginModule required
3  useKeyTab=true
4  keyTab="/etc/security/sql-app.keytab"
5  principal="[email protected]"
6  storeKey=true
7  doNotPrompt=true;
8};

Then launch the app with the JAAS file:

bash
1java \
2  -Djava.security.auth.login.config=/etc/security/jaas.conf \
3  -Djava.security.krb5.conf=/etc/krb5.conf \
4  -jar app.jar

This setup is common for long-running services where a human user is not available to run kinit.

Environment Prerequisites Outside Spring Boot

Most Kerberos connection failures are caused by infrastructure mismatches rather than by Spring configuration. Check these before blaming the application:

  • the SQL Server service account has the correct SPN registered
  • the hostname in the JDBC URL resolves to the server that owns that SPN
  • the client machine clock is synchronized closely enough for Kerberos
  • the service account or user actually has a valid ticket

If any of those are wrong, the JDBC driver cannot obtain or use the correct Kerberos token.

Common Pitfalls

The most common mistake is an SPN mismatch. If the SQL Server service is registered under one hostname but the JDBC URL uses another alias, Kerberos can fail even though the server is reachable.

Another frequent issue is assuming that Windows integrated login and Java Kerberos are interchangeable settings. The Microsoft JDBC driver distinguishes between native integrated security and Java-based Kerberos authentication, and the URL flags need to match your environment.

Be careful with ticket lifetime and startup context. An application launched manually from a shell that already ran kinit may work, while the same app started as a service fails because that service account has no ticket cache or keytab configuration.

Finally, keep debugging enabled while you are bringing the system up. Kerberos errors often look like generic login failures until you inspect the JVM debug output and see the exact realm, SPN, or credential lookup problem.

Summary

  • Spring Boot uses the SQL Server JDBC driver and JVM Kerberos support for this setup.
  • Configure the datasource URL with integratedSecurity=true and authenticationScheme=JavaKerberos.
  • Provide Kerberos realm information through krb5.conf and, when needed, JAAS configuration.
  • Verify SPNs, DNS, ticket availability, and clock sync outside the application.
  • Expect most failures to come from environment setup rather than from Spring Boot code.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.