Skip to content

Kerberos Authentication✯

SSH authentication for most workstations, servers, or virtual machines at ISIMA/LIMOS relies on Kerberos, interfaced with our user directory (Active Directory, itself synchronized with the UCA LDAP).

Standard Authentication (login/password)✯

To connect to a Kerberized SSH server, simply prepend <account>@ before the server name.

For example:

ssh vimazeno@vm-etu-vimazeno.local.isima.fr

Kerberos Ticket Authentication (replacing public/private key authentication)✯

Generating a Kerberos ticket is mandatory for each connection, so it is not possible to use SSH keys for passwordless authentication

However, it is possible to generate a keytab to obtain a Kerberos ticket without entering a password.

Kerberized servers

  • perso
  • home.local.isima.fr (SSH access to shared homedirs — personal pages storage)
  • turing
  • ada
  • certain student VMs
  • bastion (this machine requires multi-factor authentication. It also requires an SSH key)

Linux✯

Prerequisites✯

Preconfigure the installation of the krb5-config package:

echo -e "krb5-config krb5-config/default_realm string LOCAL.ISIMA.FR" | sudo debconf-set-selections

or

Enter the Realm name (here: LOCAL.ISIMA.FR - uppercase) when prompted during krb5-config installation:

sudo apt install krb5-user krb5-config

Authentication✯

kinit -f <uca-account>
# or
kinit -f <uca-account>@LOCAL.ISIMA.FR # If using multiple Kerberos realms

The Realm (LOCAL.ISIMA.FR) does not need to be specified if it is set as default during requirements installation.

You will be prompted for your password.

The -f flag requests a forwardable TGT — required for ssh -K

By default, kinit does not obtain forwardable tickets. However, ssh -K (delegation) transmits a forwarded copy of your TGT: without the F flag, delegation is silently ignored. Result: you are authenticated on the server, but your remote session has no tickets (klist on the server shows: "No credentials cache found") and your homedir responds with "permission denied".

Verify on the client side with klist -f: the TGT flags must be FIA. Alternatively, set forwardable = true in /etc/krb5.conf (in the [libdefaults] section).

The klist command lists the user's tickets

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: <uca-account>@LOCAL.ISIMA.FR

Valid starting     Expires            Service principal
08/24/20 10:10:37  08/24/20 20:10:37  krbtgt/LOCAL.ISIMA.FR@LOCAL.ISIMA.FR
        renew until 08/25/20 10:10:37

Here, the user has obtained their Ticket-Granting Ticket (TGT). This will allow them to authenticate with school servers and access certain school services (personal directory on dirs, administrative shares).

This ticket has a limited lifespan and must be renewed when expired (using kinit).

You can now test an SSH connection using your TGT. You can also force the transfer of the Kerberos ticket to your remote session using the -K option. This is often necessary to access resources from the session you open on the server (e.g., access to a Kerberized NFS share like your personal directory in ~/shared).

This option may be required if your homedir is directly on the Kerberized NFS share. This is the case for servers like perso.local.isima.fr, home.local.isima.fr, turing.local.isima.fr, or ada.local.isima.fr. If you do not forward the TGT to your remote session, you will be allowed to connect to the server but will not have access to your homedir.

ssh -K <uca-account>@perso.local.isima.fr
# Or
ssh -K <uca-account>@home.local.isima.fr
# Or
ssh -K <uca-account>@turing.local.isima.fr
# Or
ssh -K <uca-account>@ada.local.isima.fr

kdestroy allows you to destroy a ticket. Run this before continuing with the keytab to ensure you obtain a KRB5 ticket with the keytab without entering a password.

Creating the keytab✯

The interactive ktutil command allows you to create a keytab file.

$ ktutil
ktutil:  ?
Available ktutil requests:

clear_list, clear        Clear the current keylist.
read_kt, rkt             Read a krb5 keytab into the current keylist.
read_st, rst             Read a krb4 srvtab into the current keylist.
write_kt, wkt            Write the current keylist to a krb5 keytab.
write_st, wst            Write the current keylist to a krb4 srvtab.
add_entry, addent        Add an entry to the current keylist.
delete_entry, delent     Delete an entry from the current keylist.
list, l                  List the current keylist.
list_requests, lr, ?     List available requests.
quit, exit, q            Exit program.

ktutil:  addent -password -p <uca-account>@LOCAL.ISIMA.FR -k 1 -e aes256-cts-hmac-sha1-96
Password for <uca-account>@LOCAL.ISIMA.FR:
ktutil:  wkt my.keytab
ktutil:  exit

A secret derived from the password is generated in the file ~/my.keytab

Best Practices✯

Like your SSH keys, it is prudent to place your keytab (which, remember, is a secret) in a directory with 0700 permissions (owner-only access).

mkdir ~/.krb5
chmod 0700 ~/.krb5
mv my.keytab ~/.krb5

Authentication with Keytab (passwordless)✯

Notes

It is not possible to configure SSH to retrieve the ticket from the KDC/AD; only the kinit command (and libpam-krb5) can do this. SSH can only use a ticket already present in the session. You must first run kinit with the keytab, then use ssh -K which will use your ticket to authenticate on a Kerberized SSH server.

This keytab allows you to obtain a KDC/AD ticket without entering your password.

$ kinit -k -f -t ~/.krb5/my.keytab <uca-account>@LOCAL.ISIMA.FR
$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: <uca-account>@LOCAL.ISIMA.FR

Valid starting     Expires            Service principal
08/24/20 10:31:13  08/24/20 20:31:13  krbtgt/LOCAL.ISIMA.FR@LOCAL.ISIMA.FR
        renew until 08/25/20 10:31:13

The -f flag is mandatory if you subsequently use ssh -K (TGT delegation, see warning above) — this is the case for CI/CD deployments.

You can test the connection by forcing the sending of the obtained Kerberos ticket with the -K option:

ssh -K <uca-account>@perso.local.isima.fr
# Or
ssh -K <uca-account>@home.local.isima.fr
# Or
ssh -K <uca-account>@turing.local.isima.fr
# Or
ssh -K <uca-account>@ada.local.isima.fr

It may be useful to retrieve a Kerberos ticket via kinit from your .bashrc. This way, you always have a Kerberos ticket available to connect to ISIMA/LIMOS servers.

Add the following to your ~/.bashrc file:

if timeout 0.4 ping -c1 192.168.100.75 > /dev/null 2>&1; then
  if ! klist -s; then
      kinit -k -f -t ~/.krb5/my.keytab <uca-account>@LOCAL.ISIMA.FR 2> /dev/null
      true
  fi
fi

If you do not already have a KRB5 ticket, one will be requested from the domain controller. We suppress the kinit error message (2> /dev/null) because if you are not at ISIMA, you would always receive an error when opening a terminal.

I have set a 0.4-second timeout for the ping command. If the domain controller is unreachable (you are not at ISIMA or on the VPN), the shell opening process is only slightly delayed (this timeout may cause the ping command to fail 1-2% of the time, but the ticket can still be obtained by running the kinit command as described above).

Windows✯

Mac✯

CI / GitLab✯

Exporting your keytab in hexadecimal✯

hexdump -v -e '1/1 "%02x"'  ~/.krb5/my.keytab > ~/.krb5/my.keytab.hex

Recovering the keytab from its hexadecimal version✯

To be used in CI/CD:

sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI'  ~/.krb5/my.keytab.hex | xargs printf

GitLab CI variable✯

On GitLab, in CI/CD > Variables [collapse] > create the following entry:

  • Key: KEYTAB
  • Value: (contents of the file ~/.krb5/my.keytab.hex)

Example .gitlab-ci.yml file for deploying code to a remote server using rsync and a Kerberos keytab✯

The build and test stages are not shown in this example; only the Kerberos-based deployment is demonstrated.

You can add stages using other Docker images to build your project and use the stage below to deploy the code to the remote server.

stages:
  - deploy

production:
  stage: deploy
  image: instrumentisto/rsync-ssh:latest
  script:

    # Install Kerberos in the Docker container and replace the default SSH client with one capable of using Kerberos
    - apk update
    - apk del openssh-client-default
    - apk add krb5 openssh-client-krb5

    # Do not verify SSH host keys
    - mkdir -p ~/.ssh
    - test -f /.dockerenv && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

    # Retrieve the hexadecimal KEYTAB
    - echo "${KEYTAB}" > my.keytab.hex

    # Convert the KEYTAB to binary
    - sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' my.keytab.hex | xargs printf > my.keytab

    # Request a Kerberos ticket using the KEYTAB (-f: forwardable TGT, required for ssh -K delegation)
    - kinit -k -f -t my.keytab ${USERNAME}@LOCAL.ISIMA.FR

    # Verify Kerberos ticket acquisition
    - klist

    # Deploy the code
    - rsync -az -e "ssh -K" ${DIRS_AND_FILES_TO_COPY} ${USERNAME}@${REMOTE_HOST_FQDN}:${REMOTE_LOCATION}