Tuesday, December 21, 2010

Debian Kerberos Client

You must have Kerberos server running on the network, read here how to get it up. We are going to add host deby01 as a client for dev.local Kerberos realm.
  1. Ensure the host name is FQDN:
    ldap1:~# hostname -f
    deby01.dev.local
    
    If it is not, issue the following:
    echo "deby01" > /etc/hostname
    hostname -F /etc/hostname
    
  2. Install Kerberos client:
    apt-get -y install krb5-user libpam-krb5
    
  3. Configure client (file /etc/krb5.conf):
    [libdefaults]
            default_realm = DEV.LOCAL
    # ...
    [realms]
            DEV.LOCAL = {
                    # The entry below can be commented 
                    # out in case there is dns 
                    # resolution for kdc
                    kdc = kdc1.dev.local
                    admin_server = krb.dev.local
            }
    
    [domain_realm]
    
    
  4. Add host principal:
    kadmin -p admin -q "addprinc -randkey host/deby01.dev.local"
    
    kadmin -p admin -q "ktadd host/deby01.dev.local"
    
Let verify it:
  1. List kerberos principals:
    deby01:~# kadmin -p admin -q "list_principals"
    ...
    host/deby01.dev.local@DEV.LOCAL
    ...
    user1@DEV.LOCAL
    ...
    
  2. List keys in keytab:
    klist -ke
    
  3. Now you can login to deby01 as user1.
  4. Have a look at log on kerberos server (file /var/log/krb5/kdc.log):
    kdc1.dev.local krb5kdc[988](info): AS_REQ (4 etypes {18 17 16 23}) 192.168.10.41: NEEDED_PREAUTH: user1@DEV.LOCAL for krbtgt/DEV.LOCAL@DEV.LOCAL, Additional pre-authentication required
    kdc1.dev.local krb5kdc[988](info): AS_REQ (4 etypes {18 17 16 23}) 192.168.10.41: ISSUE: authtime 1293635137, etypes {rep=18 tkt=18 ses=18}, user1@DEV.LOCAL for krbtgt/DEV.LOCAL@DEV.LOCAL
    kdc1.dev.local krb5kdc[988](info): TGS_REQ (4 etypes {18 17 16 23}) 192.168.10.41: ISSUE: authtime 1293635137, etypes {rep=18 tkt=18 ses=18}, user1@DEV.LOCAL for host/deby01.dev.local@DEV.LOCAL
    
The pam authentication by default is configured to authenticate user with kerberos with fallback to local authentication, that is fine so nothing need to be configured there.

How to add a new user to Kerberos

The Kerberos is used only for authentication purpose that means that user we are going to add must exists as a normal unix account (or ldap account).
root@kdc1:~# kadmin.local -q "addprinc user1"
...
Principal "user1@DEV.LOCAL" created.
Let test it out:
root@kdc1:~# kinit user1 && klist && kdestroy 
...
Default principal: user1@DEV.LOCAL
...
The operations must be performed on kdc1 that is Kerberos administrative server.

How to add a new host to Kerberos

Each host (a client computer) that need to be a part of kerberos realm must have principal and keytab. Let do that for host deby01. The command must be invoked on Kerberos administrative server (kdc1):
kadmin.local -q "addprinc -randkey host/deby01.dev.local"
This is run on client (deby01):
kadmin -p admin -q "ktadd host/deby01.dev.local"
or consider using the following script (file /usr/local/sbin/kdc-add):
#!/bin/sh

type=host
if [ ! -z $1 ]; then type=$1; fi

sh -c "`cat /etc/hostname | xargs -t -I {} echo \
"kadmin -p admin -q \\\"addprinc -randkey $type/{}\\\""`"

sh -c "`cat /etc/hostname | xargs -t -I {} echo \
"kadmin -p admin -q \\\"ktadd $type/{}\\\""`"
You can run it on a machine you wish to add (you will be prompted to enter password two times):
kdc-add
Please note that each host added to kerberos must have fully qualified hostname. Both forward and reverse mapping must work properly. Here are few simple tests:
deby01:~# hostname
deby01.dev.local

deby01:~# dig deby01.dev.local +short
192.168.2.41

deby01:~# dig -x 192.168.2.41 +short
deby01.dev.local.
Read more here.

Debian Kerberos Master

Kerberos is a network authentication protocol. The idea is to be a secure, single sign-on authentication provider.
  1. Install Kerberos Server.
    apt-get -y install rsyslog krb5-{admin-server,user,doc}
    
  2. Create realm (this may take a long time, up to few minutes).
    krb5_newrealm
    
  3. Activate Kerberos administration by authorizing admin access (file /etc/krb5kdc/kadm5.acl).
    # ...
    */admin *
    admin *
    
  4. Setup logging (new file /etc/logrotate.d/krb5):
    /var/log/krb5/kadmin.log /var/log/krb5/kdc.log {
            daily
            missingok
            rotate 7
            compress
            delaycompress
            notifempty
    }
    
    Create log directory
    mkdir /var/log/krb5
    
  5. Realm Configuration (file /etc/krb5.conf). In our case the kerberos server name is kdc1 and there is alias to it krb (used for administration purpose).
    [libdefaults]
            default_realm = DEV.LOCAL
    
    [realms]
            DEV.LOCAL = {
                    kdc = kdc1.dev.local
                    # kdc = kdc2.dev.local
                    admin_server = krb.dev.local
            }
    
    [domain_realm]
            .dev.local = DEV.LOCAL
            dev.local = DEV.LOCAL
    
    [logging]
            kdc = FILE:/var/log/krb5/kdc.log
            admin_server = FILE:/var/log/krb5/kadmin.log
    
  6. Restart kerberos services.
    invoke-rc.d krb5-admin-server restart ; \
    invoke-rc.d krb5-kdc restart
    
  7. Open another console and have a look at log files.
    cd /var/log/krb5/ ; \
    tail -f kadmin.log kdc.log
    
  8. Ensure services are running.
    root@kdc1:~# netstat -tunlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:464             0.0.0.0:*               LISTEN      840/kadmind     
    tcp        0      0 0.0.0.0:749             0.0.0.0:*               LISTEN      840/kadmind     
    tcp6       0      0 :::464                  :::*                    LISTEN      840/kadmind     
    udp        0      0 0.0.0.0:464             0.0.0.0:*                           840/kadmind     
    udp        0      0 0.0.0.0:88              0.0.0.0:*                           861/krb5kdc     
    udp        0      0 0.0.0.0:750             0.0.0.0:*                           861/krb5kdc     
    
So far we have the services up and running, however in order to administer it we need create an administrative account:
  1. Add admin principal:
    kadmin.local -q "addprinc admin"
    
  2. Add host (kdc1) principal:
    kadmin.local -q "addprinc -randkey host/kdc1.dev.local"
    
    kadmin.local -q "ktadd host/kdc1.dev.local"
    
Now let test it:
root@kdc1:~# kinit admin && klist && kdestroy 
Password for admin@DEV.LOCAL: 
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: admin@DEV.LOCAL

Valid starting     Expires            Service principal
12/21/10 18:05:14  12/22/10 04:05:14  krbtgt/DEV.LOCAL@DEV.LOCAL
 renew until 12/22/10 18:05:11
Read more here.

Thursday, December 16, 2010

How to edit Dynamic DNS zone

All changes made to a zone using dynamic update are stored in the zone's journal file. The zone file is updated every 15 min. The zone files of dynamic zones cannot normally be edited by hand because they are not guaranteed to contain the most recent dynamic changes (those are only in the journal file). Here are few steps that let you edit entries in dynamic dns zone:
  1. Suspend updates to all dynamic zones.
    rndc freeze
    
  2. Edit zone file
  3. Enable updates to all dynamic zones and reload them.
    rndc thaw
    
Read more about advanced dns features here.