Kerberos Windows Interoperability

= Introduction = Kerberos allows single sign and can assist with Windows and Linux interoperability. The basic goal is to get systems attached to an AD domain to be able to access servers using pass through authentication. For example, start up a browser and point it at an Apache webserver. The web server allows access to the browser user because they have been authenticated in the background via Kerberos.

The setup here is designed to use Samba to manage the Kerberos keytab side of things for servers like Squid, Apache and sshd. As is often the case there are other ways to do it but these notes provide an approach that seems to work with minimal maintenance once set up. Winbind will sort out keytabs for server applications and also for workstation apps like Evolution.

Before you start this you must ensure that the clock on your system agrees with the Windows DC that holds the "PDC Emulator" FSMO role. Realistically any of them will do not just that one but that DC is the time source for the whole AD. You must also make sure that DNS is set up correctly. If you can resolve the name of the AD domain, then that is a good start. If either time or DNS go astray then you will get some tricky errors to debug. Always check them both first. You can mitigate DNS via the [realms] section in krb5.conf but not time.

= Kerberos (MIT) = On Gentoo enabling the  USE flag should pull in. Configuration for a simple setup (set your realm):

You may want to create a realm to domain mapping section [realms]. This is especially useful for Apache when the system may have a different external domain to its internal one. See krb5.conf docs

Do not create the file - Samba may give an error if it can't create the keytab file.

The following command will grab a Kerberos ticket for the currently logged in user. can actually be any valid Kerberized user account, if omitted then the current Unix username is used. If the default realm is already specified in then it can be also be omitted.

If the realm is already set and the ticket is for a username that matches the Unix user then simply run kinit and enter a password.

It is not always possible to use supplementary groups with some daemons eg Squid. The following will add additional ACLs to the Kerberos keytab file file to allow the processes to read the keytab. This assumes that you have ACL support on the system. If not then you will need some other method of allowing the daemons to access the single keytab. Failing that you will have to create separate keytabs for each application and get them set up manually - web search for that. Only do this bit after getting Samba to create the file, otherwise you may get errors.

= Samba = Make sure you have a reasonably recent Samba release installed (eg 3.5 or 3.6+)
 * Set Samba to allow access via both secrets (winbind and local passwd) and Kerberos. There are many more options that you might want to configure when joining an AD domain but here we only consider Kerberos related ones.


 * Tell winbind to setup a ticket cache for a logged in user.


 * Join the domain


 * Start or restart Samba. Make sure that  has winbind included in the list of daemons.

= Apache =
 * emerge
 * Add  to


 * Edit the module config or add it into your vhost configuration

Set  on to get prompted for authentication. I suggest you only use this over SSL/TLS (https) for obvious reasons.


 * Use Samba to set the service principle(s) for Apache (HTTP):

Note the format in the second command. This will get non default Service Principle Names into the keytab, eg for externally facing vhosts. Remember to set the [realms] section in if you need an external domain to map to an internal realm (or AD domain as MS call them!) The second command also seems to need the SPN added to AD using setspn.exe (on a Windows machine with Domain Admin rights and probably an elevated command prompt on server 2008+): c:\>setspn.exe -A HTTP/

Test it with this in the web server's htdocs somewhere (assuming you have PHP installed and configured):

Errors like this in errors_log means that the keytab can't be read - check the permissions on it for the apache user: gss_acquire_cred failed: Unspecified GSS failure. Minor code may provide more information (, Permission denied)

= SSHD = Use Samba to get the service principle for SSHD - "host". Just to spell it out in case of confusion: use the word host in your command. It is not part of an example, only change the bits between.

When you turn off PAM you obviously won't be able to get it to make a home directory for a new user. So another method will be needed to do this. Winbindd can do this - see the docs for it if you need this.

= Squid = Squid also seems to use "HTTP" as its service name like Apache. This will probably need a Squid 3.1.x release.

= Client apps =

setspn.exe
Check Service Principle Names: c:\>setspn.exe -l 

net ads keytab
Check a Samba maintained keytab like this:

ktutil and klist
Check keytabs like this:

or

Firefox

 * about:config
 * Type  into the filter
 * Set  to
 * Additional domains (eg short names) can be added separated by commas: e.g..
 * (On Linux only) at a user shell prompt type  and enter your AD password to authenticate and get a ticket from the KDC (This is not needed if you set up )

Chrome(ium)
Start Chrome with:. You can edit to add this or create another launcher.

Another method using policies: | Chromium docs, see Setup Policies and then apply something like | this For example, with Chrome:

Create a .jason file such as my_local_policy.json: { "HomepageLocation": "https://www.example.co.uk", "AuthServerWhitelist": ".example.co.uk", "AuthNegotiateDelegateWhitelist": ".example.co.uk" }

IE
Does single signon out of the box. IE 7+. Don't use <=6!

ssh
For the SSH client on Linux. This can go in the system wide configuration or in a user specific configuration:

Evolution EWS
You can connect to Exchange via Evolution EWS and provided that autodiscover is set up correctly it will work out of the box. I have found that adding additional SPNs to the client access server's machine account can assist with getting Kerberos instead of NTLM working. eg: c:\>setspn.exe -S HTTP/exchange.example.co.uk EXCHCAS

To determine what names are needed, switch Evolution to using Kerberos and have Wireshark or tcpdump running and look out for the name that Evolution tries to contact the server with. You should see a flurry of DNS lookups followed by Kerberos related packets. One of the fields will show the host name that your client is trying to use.

If everything is in place (winbind etc) then you simply start Evolution up, add a new account, fill in your name and set the type to ews and then press the lookup button after filling in your email address

PuTTY

 * Get hold of a development snapshot until it is in the core release.
 * Connection -> Data, select Use system username (your name)
 * Connection -> SSH -> Auth -> GSSAPI, make sure Attempt GSSAPI authentication is selected

= Full Domain Member on a laptop = Here's a quick rundown for a laptop domain member. I use KDE Plasma 5 as my WM with SDDM for login. I changed the theme to one without a user list. The configs provided are direct copies from my working config, I have only changed domain names to EXAMPLE.


 * Samba4
 * systemd
 * ~amd64
 * AD - 2012R2 forest and domain functionality
 * Exchange 2016 (CU2 at the moment)
 * VPN to the AD DCs
 * Time via ntpd and DNS is setup correctly
 * Autodiscover - internal and external domains are the same and all Exchange names are the same ones
 * HA proxy in use which makes things a bit more interesting
 * setspn.exe used to add more SPNs to the machine account for the Exchange CAS

Kerberos
app-crypt/mit-krb5 USE=keyutils pkinit threads -doc -libressl -openldap -selinux -test -xinetd

Samba
net-fs/samba USE=acl ads client cups gnutls ldap pam syslog system-mitkrb5 systemd winbind -addc -addns -aio -avahi -cluster -dmapi -fam -iprint -quota -selinux -test

NIS:

Make sure that everything is in place, join the domain and then test the join:
 * 1) net ads info
 * 2) net ads join -U AD_username_with_computer_account_create_rights
 * 3) net ads testjoin

Check NIS is working (should spit out a list of local and then AD users):
 * 1) getent passwd

Setup PAM:

Now login as a domain user via a console and make sure all is well.