A month on a Mac

During the second job interview with my new employer I was asked if I’d like to use a Mac or a Windows PC with the assurance I’d get a Linux workstation after my probation time. Just put me behind a Mac then, that’s closer to Linux than Windows and from what I recalled it comes with a native terminal that does SSH. And what do I need more?

So there I am in front of a big, glossy screen and a tiny keyboard that lacks some familiar keys. My findings so far? Kind of neutral. I’ve got my terminal and I can run SSH from the CLI so I’m happy. There are some quirks that annoy me though (in no particular order):

  • No Compose key and I had to jump through quite some hoops to map a key as a Compose key.
  • No easy way to map a keyboard shortcut for opening a terminal. I had to resort to something called ‘Automator’ to get it working. And it still doesn’t work the way I want too. When there are no windows open pressing the shortcut doesn’t do anything. When there are open windows it works but why does it open two terminals when pressing the shortcut for the first time? Not a real big deal as I need multiple terminals anyway (I just can’t get used to tabbed terminals).
  • I prefer non-glare monitors to glossy ones.
  • No Home, End, PageDown and PageUp keys. Not a real big deal either, in fact, it’s a real good incentive to start getting accustomed to Vi(m) shortcuts since I kind of live inside Vim these days. I even bought this, great stuff.
  • Can’t get used to the default window management settings. For instance when you minimize a window and Alt+Tab to it the window doesn’t open. So I’m not minimizing any windows anymore since this is really annoying. Haven’t looked into changing this behaviour though, it’s probably something relatively simple.
  • Annoying pop-ups from updates and programs that are downloaded from the internet (“blabla” is an application downloaded from the Internet. Are you sure you want to open it?). Especially the latter ones are annoying. Disabling the pop-ups has to be done from a terminal. Wow, so much for a “user-friendly” OS.
  • Clicking the close button of an application doesn’t quit it. Cmd+Q does. This is something I won’t get used to either. Actually I don’t want to get used to the Cmd button at all.
  • I prefer a panel with a window list on it. I don’t know how other folks do it but this Alt+Tab stuff is counter-efficient in my case.

Are there things I particularly like about Mac OS X or the Mac itself? Actually no, can’t think of anything. Yeah, the keyboard feel is really nice but that pro gets nulled out because of the missing keys, ~ being placed next to the left Shift key and the Fn keys being mapped to the F1/F12 keys. Add to this the meaningless keys with all kinds of arrows on them and this key with a crossed square. No idea what they do. On a software level MacPorts is nice, it allowed me to install some of my favorite tools that I found were missing. Other than that I can’t wait to have my own workstation with Linux on it. The plan is that I get a Dell XPS 15 with a dual monitor setup. Something to look forward to.

And yes, I have to deal with quite some Windows servers now. I’m not going to dedicate a blogpost to my findings on that OS. Just one word. Meh.

A month on a Mac

YubiKeys, SSH, PAM en LDAP

Hoe tweeweg authenticatie op te zetten voor SSH logins met behulp van YubiKeys, PAM en LDAP (via SSL) op een Ubuntu 12.04 installatie.

Benodigde pakketjes

sudo apt-get install ldap-auth-client libpam-yubico

Conflicterende pakketjes

Mocht het pakketje nscd geïnstalleerd zijn, deïnstalleer deze. Dit pakket verhindert een goede werking van de YubiKey-LDAP authenticatiemethode.

ldap-auth-config

Tijdens het installeren van het pakketje ldap-auth-client wordt er een aantal gegevens gevraagd. Doorloop de set-up als volgt:

  • LDAP server Uniform Resource Identifier: ldaps://fqdn.van.ldap.server:poortnummer
  • Distinguished name of the search base: dc=voorbeeld,dc=com
  • LDAP version to use: 3
  • Make local root Database admin: No
  • Does the LDAP database require login? No

/etc/ldap.conf

Dit bestand regelt de verbinding met je LDAP server. De setup van ldap-auth-client heeft de boel nu ingesteld maar eigenlijk heb je deze hele setup niet nodig want met een /etc/ldap.conf met de volgende drie regels ben je er ook:

base dc=voorbeeld,dc=com
uri ldaps://fqdn.ban.ldap.server:poortnummer
tls_cacertfile /etc/ssl/certs/cacert.org.pem

Je kunt dus een deel van wat de setup heeft aangemaakt laten staan, de rest kun je uithekken. Zoals je ziet heb ik voor de SSL kant van het verhaal voor CAcert.org gekozen als CA. Je moet dan ook expliciet verwijzen naar de root certificaten van CAcert.org anders kan er niet gebind worden met de LDAP server. De LDAP server, in mijn geval een OpenDJ directory server, maakt dus gebruik van door CAcert.org getekende certifcaten.

/etc/nsswitch.conf

Dit bestand regelt op welke manier en in welke volgorde de verschillende nameservices worden aangesproken. In ons geval gaat het om de entries password, shadow en groups in dit bestand. Standaard staan die in Ubuntu 12.04 op compat. Om Ubuntu eerst de fysieke bestanden en daarna LDAP te laten checken moet compat veranderd worden in files ldap. Dit gaat het snelst met een sed commando:

sudo sed -i 's/compat/files ldap/g' /etc/nsswitch.conf

Nu /etc/nsswitch.conf is ingesteld kun je gaan testen of je LDAP connectie goed is:

id ldapgebruiker
getent passwd
getent group

PAM

Nu is het zaak PAM zo in te stellen dat je zowel tegenover de Yubico servers authenticeert met je YubiKey als tegenover LDAP wanneer je SSH’t naar je machine. Dit regel je in /etc/pam.d/sshd:

# PAM configuration for the Secure Shell service

# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
auth       required     pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
auth       required     pam_env.so envfile=/etc/default/locale

# Yubikey authentication
#
# Allow local accounts for the moment.
auth sufficient pam_unix.so

# Fetch LDAP password + OTP, verify OTP and move on ('required' control value).
# LDAP password is stripped and passed on.
auth required pam_yubico.so id=1234 ldap_uri=ldaps://fqdn.van.ldap.server:poortnummer [ldapdn=ou=People,DC=voorbeeld,DC=com] user_attr=uid yubi_attr=yubikeyid

# LDAP authentication
#
# Verify the LDAP password that has been passed on ('use_first_password' argument)
# and grant access when password gets accepted ('sufficient' control value).
auth sufficient pam_ldap.so use_first_pass

# Standard Un*x authentication.
@include common-auth

# Disallow non-root logins when /etc/nologin exists.
account    required     pam_nologin.so

# Uncomment and edit /etc/security/access.conf if you need to set complex
# access limits that are hard to express in sshd_config.
# account  required     pam_access.so

# Standard Un*x authorization.
@include common-account

# LDAP session
#
# Create homedir for LDAP user if it doesn't exist yet.
session required pam_mkhomedir.so skel=/etc/skel/ umask=0022

# Standard Un*x session setup and teardown.
@include common-session

# Print the message of the day upon successful login.
session    optional     pam_motd.so # [1]

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

# Set up user limits from /etc/security/limits.conf.
session    required     pam_limits.so

# Set up SELinux capabilities (need modified pam)
# session  required     pam_selinux.so multiple

# Standard Un*x password updating.
@include common-password

De dikgedrukte gedeeltes zijn toegevoegd. Het id wat is toegevoegd bij de pam_yubico.so module kun je aanvragen via Yubico. Dit id is de zgn. API Key. Ook heb ik een extra opties toegevoegd:

yubi_attr=yubikeyid

Wat dit doet is de mapping gebruiker – YubiKey Public ID checken op de LDAP server, dus niet op de machine zelf. Het gros van de handleidingen gaat ervan uit dat je de mappings op de machine zelf maakt in platte bestandjes. Maar dat wil je helemaal niet, daar heb je nou juist je LDAP server voor, zodat je dit soort dingen als mappings centraal kan regelen. Wat ik heb gedaan is een objectclass yubikey toegevoegd aan de OpenDJ configuratie en deze een attribute yubikeyid meegegeven. Hoe ik dit heb gedaan komt nog wel aan bod in een latere entry waarin ik ook zal uitleggen hoe je users die in moeten kunnen loggen op je machine moet aanmaken in OpenDJ. De objectclass yubikey heb ik op zijn beurt weer toegevoegd als auxiliary objectclass bij de gebruikers die een YubiKey hebben. Vervolgens kan ik dan in het veld yubikeyid het Public ID ingeven van de YubiKey die bij een bepaalde gebruiker hoort. Het Public ID bestaat uit de eerste 12 tekens van de OTP die een YubiKey genereert. Je kan ook een bestaande attribute gebruiken, Zarafa gebruikt bijvoorbeeld het carLicense attribute. Maar dit gaat er bij mij niet in, een YubiKey Public ID is geen rijbewijs, dus krijgt het een eigen attribute.

Als je nu via SSH inlogt met je LDAP wachtwoord meteen gevolgd door je YubiKey OTP op dezelfde regel zou je keurig geauthenticeerd moeten worden. Eerst tegenover de Yubico Cloud, vervolgens stript de pam_yubico.so module het wachtwoord en haalt het YubiKey OTP eraf en geeft de rest door aan pam_ldap.so die je nu met het overgebleven wachtwoord authenticeert tegenover je LDAP server. En mocht je nog geen home directory hebben dan wordt deze aangemaakt door pam_mkhomedir.so.

YubiKeys, SSH, PAM en LDAP

YubiKeys

De afgelopen tijd zijn de nodige bedrijven gehackt waaronder ook wat telecombedrijven. M’n baas kreeg daar de kriebels van en heeft een zak met YubiKeys aangeschaft. Of ik de authenticatie met die dingen even kon implementeren voor het hele netwerk.

Met YubiKeys kun je tweeweg authenticatie opzetten, in ons geval LDAP authenticatie in combinatie met de YubiKeys. Maar een LDAP server was er ook nog niet. SSH’en bijvoorbeeld ging met lokale accounts en ik werk wel met keys maar mijn collega’s niet. Vragen om moeilijkheden dus eigenlijk.

Van LDAP had ik weinig kaas gegeten maar uiteindelijk kwam ik na wat tips van mijn chef uit bij OpenDJ, een op Java gebaseerde LDAP directory server. OpenDJ installeren is redelijk eenvoudig, alleen staat nergens beschreven hoe je dit echt veilig moet doen. Het viel me al op dat er in de installatiehandleiding niet-standaard LDAP poorten gebruikt werden hoger dan 1024. Dit zijn unprivileged poorten die geopend mogen worden door gewone gebruikers dus heb het ook zo opgezet, dus dat OpenDJ draait onder een systeemuseraccount wat verder niks mag.

Volgende stap was het opzetten van een RADIUS server voor de YubiKeys. Je kan natuurlijk ook direct tegen de Yubico servers authenticeren maar die kun je voor zover ik weet niet koppelen aan je eigen LDAP server en ook niet goed beheren qua gebruikers. Ik ben degene die bepaalt aan wie welke YubiKey wordt toegewezen die toegang krijgt tot ons netwerk, niet de collega’s zelf. Voor het opzetten van een dergelijke server heb ik de YubiRADIUS Virtual Appliance gebruikt, een VMware image dat ik gedeployed heb op onze ESXi server. Dat is een Debian 6 installatie die ik nog wel wat heb moeten tweaken, ik ga bijvoorbeeld echt geen netwerkinstellingen op een server configureren via Network Manager.

Wat users opgevoerd in LDAP, YubiKeys toegewezen op de YubiRADIUS server, maar hoe nu verder? Hoe zet ik de tweeweg authenticatie op voor bijvoorbeeld SSH toegang? De beschikbare documentatie is summier en wat betreft het opzetten van tweeweg authenticatie met behulp van LDAP en YubiKeys onder Linux is er eigenlijk helemaal geen documentatie beschikbaar. Dit moet je met PAM doen en er is een YubiKey PAM module beschikbaar maar hoe je de authenticatie uiteindelijk moet implementeren wordt nergens beschreven.

Uiteindelijk heb ik het goed werkend gekregen en ik zal proberen om de werkende configuratie om via SSH in te loggen met behulp van YubiKeys en LDAP authenticatie te beschrijven in een vervolgentry.

YubiKeys