Windows authentication in Linux Docker container .Net 5
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Windows Authentication (Kerberos/NTLM) in a Linux Docker container running .NET 5+ requires configuring the container to authenticate against Active Directory using Kerberos. Linux cannot use NTLM natively, so Kerberos is the path forward. This involves installing the krb5 package in the container, providing a krb5.conf configuration file, obtaining a Kerberos ticket, and configuring the ASP.NET Core application to use Negotiate authentication.
Prerequisites
- An Active Directory domain controller accessible from the container
- A service account (SPN) registered in AD for the application
- A keytab file generated for the service account
- .NET 5 or later
Dockerfile Setup
Kerberos Configuration (krb5.conf)
Replace MYCOMPANY.COM with your AD domain (uppercase for the realm) and dc01.mycompany.com with your domain controller hostname.
Generating a Keytab File
Run this on a machine with access to Active Directory:
The SPN (HTTP/myapp.mycompany.com) must match the hostname clients use to access the application.
ASP.NET Core Configuration
Install NuGet Package
Program.cs / Startup.cs
.NET 6+ Minimal API
Accessing the Authenticated User
Docker Compose Configuration
The container must be able to resolve the domain controller hostname. Set DNS to your AD DNS server.
Testing Kerberos from the Container
If kinit fails, the issue is network connectivity, DNS resolution, or incorrect credentials — not the .NET application.
Troubleshooting
Common Pitfalls
- Clock skew: Kerberos requires the container clock to be within 5 minutes of the domain controller. Docker containers inherit the host clock, but if the host drifts, authentication fails with
Clock skew too great. Use NTP synchronization on the Docker host. - DNS resolution: The container must resolve the domain controller by hostname, not just IP. Add
dnsentries in Docker Compose or useextra_hoststo map the DC hostname. - SPN mismatch: The SPN in the keytab must exactly match
HTTP/hostnamewherehostnameis what clients use in the URL. If clients accesshttps://myapp.mycompany.com, the SPN must beHTTP/[email protected]. - Keytab permissions: The keytab file contains credentials. Set restrictive permissions (
chmod 600) and never commit it to source control. Use Docker secrets or a vault in production. - NTLM fallback: Linux does not support NTLM natively. If the client sends NTLM instead of Kerberos (common with older Windows clients or non-domain-joined machines), authentication fails. Ensure clients are configured for Kerberos.
Summary
- Install
krb5-userandlibgssapi-krb5-2in the container for Kerberos support - Provide
krb5.confwith your AD realm and KDC hostname - Generate a keytab file for the service account SPN
- Set
KRB5_KTNAMEenvironment variable to the keytab path - Use
Microsoft.AspNetCore.Authentication.Negotiatein ASP.NET Core - Ensure DNS resolution and clock synchronization between the container and domain controller
Related reading
- Windows Server Containers in Google Kubernetes Engine GKE
- Wordpress Docker won't increase upload limit
- Zonal network endpoint group unhealthy even though that container application working properly
- 1d Array - determine best container size with minimum waste
- x509 certificate signed by unknown authority- Kubernetes
- x509 certificate signed by unknown authority possibly because of crypto/rsa verification error in Kubernetes
- Windows Forms' CheckBox CheckedChanged vs. CheckStateChanged
- Windows Forms vs. WPF

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.