OpenAFS with MIT Kerberos

From Gentoo Linux Wiki

Jump to: navigation, search

Filesystems TOC

Filesystem.png

AFS is a distributed network filesystem that also allows for replication. Organizations such as Google and the Internet Archive have been known to use AFS (along with Linux) for its scalability.

From http://www.openafs.org:

AFS is a distributed filesystem product, pioneered at Carnegie Mellon University and supported and developed as a product by Transarc Corporation (now IBM Pittsburgh Labs). It offers a client-server architecture for file sharing, providing location independence, scalability, security, and transparent migration capabilities for data.

IBM branched the source of the AFS product, and made a copy of the source available for community development and maintenance. They called the release OpenAFS.

Kerberos offers a network authentication protocol for use in client/server network topologies. AFS originally implemented a version of Kerberos for its authentication purposes and was based on the Kerberos v4 protocol. However, since DES is no longer approved for Federal use, organizations are replacing AFS's authentication server (kaserver) with a Kerberos v5 authentication server.

Contents

[edit] Kerberos Installation

The first step is to install kerberos on the server and setup a KDC

emerge -a mit-krb5

Since there can be more than one kerberos server working together, kerberos breaks servers into logical groups called realms. Kerberos realms are always uppercase, and by convention consist of your domain. You will need to select a name for your realm, and add to the file on your server:

cp /etc/krb5.conf.example /etc/krb5.conf
File: /etc/krb5.conf
[libdefaults]
        default_realm = EXAMPLE.COM

[realms]
        EXAMPLE.COM = {
                admin_server = server.example.com
                default_domain = example.com
                kdc = server.example.com
        }

[domain_realm]
        .example.com  = EXAMPLE.COM
        example.com = EXAMPLE.COM

replace "EXAMPLE.COM" above with your kerberos realm, "example.com" with your domain, and "server.example.com" with your server.

This same file will need to be copied to clients who need to access your kerberos server.

[edit] Primary KDC

Next, you'll need to create the Key Distribution Center (KDC) which is responsible for housing Kerberos principals, passwords and access control lists.

Now create a directory for storing the KDC files and databases:

mkdir /var/lib/krb5kdc
Note: The path specified here is arbitrary, as it will be later set in your /etc/kdc.conf. If you choose a different path, do not forget to update this file.

Now you must create the /etc/kdc.conf file. This will contain the details for how your KDC will run.

cp /etc/kdc.conf.example /etc/kdc.conf

Edit this file replacing the given realm with your own, and specifying the path you used above if it differs from /var/lib/krb5kdc. You can edit the other options if you know what you are doing or have some special need. The manpage has more information about the file:

man kdc.conf

In order to allow your database to be editable, you need to give principals access to it. This is done through the kadm5.acl file in the directory you created above. The most basic configuration allows all principals that have an instance name of admin (ends in /admin) access to everything:

File: /var/lib/krb5kdc/kadm5.acl
*/admin@EXAMPLE.COM *

A more secure way that requires more maintenance is to list the principals that will have access:

File: /var/lib/krb5kdc/kadm5.acl
joe/admin@EXAMPLE.COM *

See the kadmind man page for more detail if you need a more complex setup:

man kadmind

Now you are ready to initialize the kerberos database.

cd /var/lib/krb5kdc kdb5_util create -r EXAMPLE.COM -s

don't forget to replace EXAMPLE.COM with your realm name.

Note: If for some reason kdb5_util takes an usually long time to finish, your kernel may not have enough entropy or random data used for encryption. You can use sys-apps/rng-tools to solve this.

[edit] Principal Creation

At this point you should test your Kerberos installation by creating an admin principal for kerberos and afs administration. You may call it whatever you like.

kadmin.local kadmin.local: addprinc afsadmin@EXAMPLE.COM kadmin.local: addprinc afsadmin/admin@EXAMPLE.COM

Now create a principal for afs itself. You will never use this principal, it's for afs only, so we use -randkey to generate a random key that can be used by afs.

kadmin.local: addprinc -randkey afs/example.com@EXAMPLE.COM

The example.com above is the afs cell name. Similar to a kerberos realm, an afs cell is a logical grouping of afs servers. Convention dictates that you should name your cell after your kerberos realm, but in lowercase, since afs cell names are always lowercase.

Each afs server needs to have the key that was generated in the last step, so we export it here:

kadmin.local: ktadd -e des-cbc-crc:normal -k /etc/krb5.keytab.afs afs/example.com

It is important to remember (or write down) the key version number (kvno) that this command gives in its output, you will need it later.

Note: You may press Ctrl+d or type q to quit kadmin

[edit] Start Kerberos Servers

You are now ready to start the kerberos kdc and kadmin server.

/etc/init.d/mit-krb5kadmind start /etc/init.d/mit-krb5kdc start

Set them to start at boot:

rc-update add mit-krb5kadmind default rc-update add mit-krb5kdc default

Now that kadmind and the kdc is running, you can use kadmind instead of kadmind.local.

[edit] OpenAFS Server

You will now need to install net-fs/openafs:

Use Flags: kerberos (?)

emerge -a openafs

[edit] Configure AFS Cell info

You will need to edit several files in /etc/openafs/ to set up your new afs cell.

File: /etc/openafs/server/ThisCell
example.com
File: /etc/openafs/server/CellServDB
>example.com #Example Cell
192.168.1.1 #afs.example.com
Warning: The part above that looks like a comment: #afs.example.com, is required and must contain the hostname of the server for afs to work!

Put this info in the client configurations too:

cat /etc/openafs/server/CellServDB>>/etc/openafs/CellServDB
cp /etc/openafs/server/ThisCell /etc/openafs/ThisCell

Now that your configurations are correct, you can tell afs what kerberos principal it needs to use, and what key to use to authenticate:

asetkey add 3 /etc/krb5.keytab.afs afs/example.com

The 3 above should be replaced with the kvno from earlier.

[edit] Bos and Other AFS Servers

BOS is the Basic OverSeer Server. It coordinates and starts all of the other afs servers. First you need to start the bosserver manually without authentication in order to set the server up.

Warning: Disabling authorization checking gravely compromises cell security. You must complete all subsequent steps in one uninterrupted pass and must not leave the machine unattended until you restart the BOS Server with authorization checking enabled, according to the official afs documentation
bosserver -noauth

Now that the bosserver is running, you can have it start and configure the protection server (for user accounts) and the volume location server:

bos create afs.example.com ptserver simple /usr/libexec/openafs/ptserver -cell example.com -noauth bos create afs.example.com vlserver simple /usr/libexec/openafs/vlserver -cell example.com -noauth

with these started you can add your admin user to the afs user database and make it an afs admin:

pts createuser -name afsadmin -cell example.com -noauth pts adduser afsadmin system:administrators -cell example.com -noauth bos adduser afs.example.com afsadmin -noauth

Setup the final few services:

bos create afs.example.com fs fs /usr/libexec/openafs/fileserver \ /usr/libexec/openafs/volserver /usr/libexec/openafs/salvager \ -cell example.com -noauth

Stop the temporary (and insecure) bosserver:

bos shutdown afs.example.com -wait -noauth
killall -9 bosserver
Note: bos shutdown does not actually stop the bosserver itself, just all of the other servers (ptserver, etc.). Please remember to kill the temporary server before trying to start another bosserver.

[edit] /vicepx partitions

The afs fileserver stores its volumes on partitions mounted in the root directory as /vicepa, /vicepb, etc. Before you start the afs server through the initscripts, you should create and mount a partition at /vicepa.

[edit] Starting the openafs server

You are now ready to start the OpenAFS server for the first time:

/etc/init.d/openafs-server start

To have it start at boot, which you probably want:

rc-update add openafs-server default

[edit] OpenAFS File Structure

In order to set up the file structure, a client has to run that can connect to your server. It is easiest to do this if the client is run on the server, as it will help while setting things up.

[edit] Starting the client

Before starting the client for the first time, it is necessary to disable DYN_ROOT, in order to set up the root.afs volume:

File: /etc/conf.d/openafs-client
ENABLE_DYNROOT="no"

Start the client:

/etc/init.d/openafs-client start


Note: I suggest creating the root.afs and root.cell volumes via vos as described below before attempting to start the openafs-client. Otherwise starting openafs-client failed with dynroot disabled and everything behaved weird.

[edit] Create Basic volume framework

Note: If your AFS Cell name is not the same as your Kerberos realm, you must create /etc/openafs/krb.conf (and /etc/openafs/server/krb.conf). The format of the file is one Kerberos realm per line. This allows for one (or more) Kerberos realms to authenticate with an AFS cell that does not match the Kerberos realm name. Otherwise, you can authenticate, get an AFS token, and will be left wondering why you get authorization errors.

Authenticate to kerberos:

kinit afsadmin

Use the kerberos authentication to authenticate to afs:

aklog

You can now run commands as the afs admin. You need to create the root.afs volume which when DYN_ROOT is disabled, is normally mounted on /afs

vos create afs.example.com /vicepa root.afs -cell example.com
Note: Any filesystem mounted under a directory called /vicepx, where x is in the range of a-z, will be considered and used as an AFS Server partition. Any unix filesystem will do (as opposed to the client's cache, which can only be ext2/3). Tip: the server checks for each /vicepx mount point whether a filesystem is mounted there. If not, the server will not attempt to use it. This behaviour can be overridden by putting a file named AlwaysAttach in this directory.

With DYN_ROOT disabled, you can now make /afs readable to everyone with:

fs sa /afs system:anyuser rl

Now you can create the root volume for your cell (which will be the basis for your whole AFS File Structure):

vos create afs.example.com /vicepa root.cell

Mount it on /afs/example.com:

fs mkmount /afs/example.com root.cell

Make sure your cell's contents are readable too:

fs setacl /afs/example.com system:anyuser rl

Mount a read-write copy on /afs/.example.com:

fs mkmount /afs/.<cell name> root.cell -rw

Other volumes can be mounted underneath the root of your cell in the same way, if you wish.

Congratulations, you now have a full AFS server!

[edit] Restarting the client

You may want to set DYN_ROOT back to yes:

File: /etc/conf.d/openafs-client
ENABLE_DYNROOT="yes"

You then need to restart your client:

/etc/init.d/openafs-client restart

[edit] AFS/Kerberos Enabled Login

In order to authenticate to kerberos and get an afs token when logging in, you need to install and configure sys-auth/pam_krb5 and sys-auth/pam-afs-session:

emerge -a pam_krb5 pam-afs-session

You will also need to edit your PAM configuration files. It should look something like this when you are done:

File: /etc/pam.d/system-auth
auth required pam_env.so
auth sufficient pam_krb5.so
auth optional pam_afs_session.so program=/usr/bin/aklog
auth sufficient pam_unix.so try_first_pass likeauth nullok
auth required pam_deny.so

account sufficient pam_krb5.so
account required pam_unix.so

password required pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 retry=3
password sufficient pam_krb5.so use_authtok ignore_root
password sufficient pam_unix.so nullok md5 shadow use_authtok
password required pam_deny.so

session required pam_limits.so
session optional pam_krb5.so ignore_root debug
session required pam_afs_session.so program=/usr/bin/aklog
session required pam_unix.so
Warning: Be VERY careful when editing this file. You could lock yourself from being able to log in. It is advisable to leave a root terminal open while making sure you can still log in after editing this file, so that you can change it back. For example:
ssh localhost

[edit] See Also

Personal tools