This project allows making HTTP calls to a Kerberos protected server using SPNego/Negotiate protocol. It is heavily based on https://github.com/spring-projects/spring-security-kerberos/tree/master/spring-security-kerberos-samples/sec-server-client-auth.
The main differences are:
- Completely independent of Spring or Spring Security using
KerberosHttpClient. Spring dependencies are only present in the project in order to execute it as Spring Boot application. - That
KerberosHttpClientallowsHOST_BASEDandUSER_BASEDGSSNamegeneration for login to the Authentication Server. Besides, for host based names, the service type present in the SPN can be not onlyHTTPbut any value (HTTPis hardcoded into the default implementation ofSPNegoScheme)
-
Create a user (principal) in Windows Active Directory. In the
Accounttab set:SERV/yourusername.domain.comasUser logon nameyourusernameasUser logon name (pre-Windows 2000)if present
-
In Windows, as Administrator, set an SPN for that user:
setspn -A SERV/yourusername.domain.com yourusername
- Then generate a
keytabfile:
ktpass /out C:\yourusername.keytab /mapuser [email protected] /princ SERV/[email protected] /pass yourpassword /kvno 0
- Install and configure Kerberos in the host machine. This an example of
/etc/krb5.conf:
[libdefaults]
default_realm = DOMAIN.COM
default_tkt_enctypes = arcfour-hmac-md5 des-cbc-crc des-cbc-md5
default_tgs_enctypes = arcfour-hmac-md5 des-cbc-crc des-cbc-md5
ticket_lifetime = 24h
forwardable = yes
dns_lookup_kdc = false
[realms]
DOMAIN.COM = {
kdc = yourActiveDirectoryHost.domain.com
default_domain = domain.com
}
[domain_realm]
.domain.com = DOMAIN.COM
[logging]
krb5 = SYSLOG:
default = FILE:/var/logs/krb5.log
admin_server = FILE:/var/logs/krb5.log
kdc = FILE:/var/logs/krb5.log
- Ensure the
kdc(Windows Active Directory domain in this case) is accessible from the current host
- Copy the
yourusername.keytabinto a location in the machine running the client. Put that location in this app config fileapplication.ymlalong with the following:
access-url: endpoint to access in the server. This has to contain a fully qualified domain name of the server host. This hostname has to be a user defined in the same Kerberos Realm / Domain Controller as the client if usingHOST_BASEDname strategy for GSS (i.e:yourusername.domain.com)user-principal: fully qualified SPN of the created user, i.e.SERV/[email protected]
-
Launch
Kerberos Serverin a host namedyourusername.domain.comif this client usesHOST_BASEDname generation. -
Generate the JAR file:
./gradlew assemble
- Execute the client:
java -jar build/libs/kerberos-client-0.1.jar
- Config file
application.ymlcan be overriden at execution time. Just provide a file with the same name in directory the previous command in executed from (not where the JAR lives) or give an extra command line attribute:
java -jar build/libs/kerberos-client-0.1.jar --spring.config.location=/path/to/propertiesFile.yml
- Only
HOST_NAME-based naming for principals/SPNs is supported at the moment. This requires a proper hostname in the server aligned with a user principal in AD. - Only GET requests can be performed at the moment, returning a String response