Это старая версия документа.


Kerberos и LDAP

Большинство людей не используют Kerberos сам по себе; как только пользователь аутентифицировался (Kerberos), нам нужно вычислить что пользователь может делать (авторизация). И это становится задачей таких программ, как LDAP.

Репликация баз данных учетных записей Kerberos между двумя серверами может усложниться и добавить дополнительную базу данных пользователей в вашей сети. К счастью MIT Kerberos может быть настроен на использование каталога LDAP как базы учетных записей.

Приведенные здесь примеры предполагают использование MIT Kerberos и OpenLDAP.

Настройка OpenLDAP

Для начала требуется загрузить на сервер OpenLDAP необходимую схему, которая содержит поддержку соединения по сети с первичным и вторичным KDC. Кроме того эта глава подразумевает, что у вас настроена репликация LDAP между как минимум двумя серверами. Информацию по настройке OpenLDAP смотрите в разделе OpenLDAP сервер.

Также требуется настроить OpenLDAP для TLS и SSL соединений, чтобы передача между KDC и LDAP серверами была зашифрована. Смотрите детали в секции TLS.

cn=admin,cn=config - пользователь, которого мы создали с правами редактирования базы ldap. Много раз это был RootDN. Измените его значение для соответствия вашим настройкам.

1. Для загрузки схемы в LDAP, на сервере LDAP установите пакет krb5-kdc-ldap. В терминале введите:

sudo apt-get install krb5-kdc-ldap

2. Далее распакуйте файл kerberos.schema.gz:

    sudo gzip -d /usr/share/doc/krb5-kdc-ldap/kerberos.schema.gz
    sudo cp /usr/share/doc/krb5-kdc-ldap/kerberos.schema /etc/ldap/schema/

3. Схема kerberos должна быть добавлена к дереву cn=config. Процедура добавления новой схемы к slapd детально описана в секции Изменение базы данных настройки slapd.

  • Сначала создадим файл настроек с именем schema_convert.conf или другим значащим именем, содержащим следующие строки:

        include /etc/ldap/schema/core.schema
        include /etc/ldap/schema/collective.schema
        include /etc/ldap/schema/corba.schema
        include /etc/ldap/schema/cosine.schema
        include /etc/ldap/schema/duaconf.schema
        include /etc/ldap/schema/dyngroup.schema
        include /etc/ldap/schema/inetorgperson.schema
        include /etc/ldap/schema/java.schema
        include /etc/ldap/schema/misc.schema
        include /etc/ldap/schema/nis.schema
        include /etc/ldap/schema/openldap.schema
        include /etc/ldap/schema/ppolicy.schema
        include /etc/ldap/schema/kerberos.schema
  • Создадим временный каталог для хранения LDIF файлов:

mkdir /tmp/ldif_output
  • Теперь используем slapcat для конвертирования файлов схемы:

        slapcat -f schema_convert.conf -F /tmp/ldif_output -n0 -s \
        "cn={12}kerberos,cn=schema,cn=config" > /tmp/cn=kerberos.ldif

Измените имена файла и каталога выше для соответствия вашим именам, если они отличаются.

  • Отредактируйте созданный файл /tmp/cn\=kerberos.ldif, изменив следующие атрибуты:

        dn: cn=kerberos,cn=schema,cn=config
        ...
        cn: kerberos

и удалите следующие строки в конце файла:

        structuralObjectClass: olcSchemaConfig
        entryUUID: 18ccd010-746b-102d-9fbe-3760cca765dc
        creatorsName: cn=config
        createTimestamp: 20090111203515Z
        entryCSN: 20090111203515.326445Z#000000#000#000000
        modifiersName: cn=config
        modifyTimestamp: 20090111203515Z

Значения атрибутов могут отличаться, просто убедитесь, что атрибуты удалены.

  • Загрузите новую схему с помощью ldapadd:

ldapadd -x -D cn=admin,cn=config -W -f /tmp/cn\=kerberos.ldif
  • Добавьте индекс для атрибута krb5principalname:

        ldapmodify -x -D cn=admin,cn=config -W
        Enter LDAP Password:
        dn: olcDatabase={1}hdb,cn=config
        add: olcDbIndex
        olcDbIndex: krbPrincipalName eq,pres,sub

        modifying entry "olcDatabase={1}hdb,cn=config"

В конце обновите списки контроля доступа (ACL):

        ldapmodify -x -D cn=admin,cn=config -W
        Enter LDAP Password: 
        dn: olcDatabase={1}hdb,cn=config
        replace: olcAccess
        olcAccess: to attrs=userPassword,shadowLastChange,krbPrincipalKey by
         dn="cn=admin,dc=example,dc=com" write by anonymous auth by self write by * none
        -
        add: olcAccess
        olcAccess: to dn.base="" by * read
        -
        add: olcAccess
        olcAccess: to * by dn="cn=admin,dc=example,dc=com" write by * read

        modifying entry "olcDatabase={1}hdb,cn=config"

Ну вот, теперь ваш каталог LDAP готов обслуживать базу данных учетных записей Kerberos.

Настройка первичного KDC

With OpenLDAP configured it is time to configure the KDC.

  First, install the necessary packages, from a terminal enter:
  sudo apt-get install krb5-kdc krb5-admin-server krb5-kdc-ldap
  Now edit /etc/krb5.conf adding the following options to under the appropriate sections:
  [libdefaults]
          default_realm = EXAMPLE.COM
  ...
  [realms]
          EXAMPLE.COM = {
                  kdc = kdc01.example.com
                  kdc = kdc02.example.com
                  admin_server = kdc01.example.com
                  admin_server = kdc02.example.com
                  default_domain = example.com
                  database_module = openldap_ldapconf
          }
  ...
  [domain_realm]
          .example.com = EXAMPLE.COM
  ...
  [dbdefaults]
          ldap_kerberos_container_dn = dc=example,dc=com
  [dbmodules]
          openldap_ldapconf = {
                  db_library = kldap
                  ldap_kdc_dn = "cn=admin,dc=example,dc=com"
                  # this object needs to have read rights on
                  # the realm container, principal container and realm sub-trees
                  ldap_kadmind_dn = "cn=admin,dc=example,dc=com"
                  # this object needs to have read and write rights on
                  # the realm container, principal container and realm sub-trees
                  ldap_service_password_file = /etc/krb5kdc/service.keyfile
                  ldap_servers = ldaps://ldap01.example.com ldaps://ldap02.example.com
                  ldap_conns_per_server = 5
          }
  Change example.com, dc=example,dc=com, cn=admin,dc=example,dc=com, and ldap01.example.com to the appropriate domain, LDAP object, and LDAP server for your network.
  Next, use the kdb5_ldap_util utility to create the realm:
  sudo kdb5_ldap_util -D  cn=admin,dc=example,dc=com create -subtrees \
  dc=example,dc=com -r EXAMPLE.COM -s -H ldap://ldap01.example.com
  Create a stash of the password used to bind to the LDAP server. This password is used by the ldap_kdc_dn and ldap_kadmin_dn options in /etc/krb5.conf:
  sudo kdb5_ldap_util -D  cn=admin,dc=example,dc=com stashsrvpw -f \
  /etc/krb5kdc/service.keyfile cn=admin,dc=example,dc=com
  Copy the CA certificate from the LDAP server:
  scp ldap01:/etc/ssl/certs/cacert.pem .
  sudo cp cacert.pem /etc/ssl/certs
  And edit /etc/ldap/ldap.conf to use the certificate:
  TLS_CACERT /etc/ssl/certs/cacert.pem
  The certificate will also need to be copied to the Secondary KDC, to allow the connection to the LDAP servers using LDAPS.

You can now add Kerberos principals to the LDAP database, and they will be copied to any other LDAP servers configured for replication. To add a principal using the kadmin.local utility enter:

sudo kadmin.local Authenticating as principal root/admin@EXAMPLE.COM with password. kadmin.local: addprinc -x dn=«uid=steve,ou=people,dc=example,dc=com» steve WARNING: no policy specified for steve@EXAMPLE.COM; defaulting to no policy Enter password for principal «steve@EXAMPLE.COM»: Re-enter password for principal «steve@EXAMPLE.COM»: Principal «steve@EXAMPLE.COM» created.

There should now be krbPrincipalName, krbPrincipalKey, krbLastPwdChange, and krbExtraData attributes added to the uid=steve,ou=people,dc=example,dc=com user object. Use the kinit and klist utilities to test that the user is indeed issued a ticket.

If the user object is already created the -x dn=«…» option is needed to add the Kerberos attributes. Otherwise a new principal object will be created in the realm subtree.

Настройка вторичного KDC

Configuring a Secondary KDC using the LDAP backend is similar to configuring one using the normal Kerberos database.

  First, install the necessary packages. In a terminal enter:
  sudo apt-get install krb5-kdc krb5-admin-server krb5-kdc-ldap
  Next, edit /etc/krb5.conf to use the LDAP backend:
  [libdefaults]
          default_realm = EXAMPLE.COM
  ...
  [realms]
          EXAMPLE.COM = {
                  kdc = kdc01.example.com
                  kdc = kdc02.example.com
                  admin_server = kdc01.example.com
                  admin_server = kdc02.example.com
                  default_domain = example.com
                  database_module = openldap_ldapconf
          }
  ...
  [domain_realm]
          .example.com = EXAMPLE.COM
  ...
  [dbdefaults]
          ldap_kerberos_container_dn = dc=example,dc=com
  [dbmodules]
          openldap_ldapconf = {
                  db_library = kldap
                  ldap_kdc_dn = "cn=admin,dc=example,dc=com"
                  # this object needs to have read rights on
                  # the realm container, principal container and realm sub-trees
                  ldap_kadmind_dn = "cn=admin,dc=example,dc=com"
                  # this object needs to have read and write rights on
                  # the realm container, principal container and realm sub-trees
                  ldap_service_password_file = /etc/krb5kdc/service.keyfile
                  ldap_servers = ldaps://ldap01.example.com ldaps://ldap02.example.com
                  ldap_conns_per_server = 5
          }
  Create the stash for the LDAP bind password:
  sudo kdb5_ldap_util -D  cn=admin,dc=example,dc=com stashsrvpw -f \
  /etc/krb5kdc/service.keyfile cn=admin,dc=example,dc=com
  Now, on the Primary KDC copy the /etc/krb5kdc/.k5.EXAMPLE.COM Master Key stash to the Secondary KDC. Be sure to copy the file over an encrypted connection such as scp, or on physical media.
  sudo scp /etc/krb5kdc/.k5.EXAMPLE.COM steve@kdc02.example.com:~
  sudo mv .k5.EXAMPLE.COM /etc/krb5kdc/
  Again, replace EXAMPLE.COM with your actual realm.
  Back on the Secondary KDC, (re)start the ldap server only,
  sudo service slapd restart
  Finally, start the krb5-kdc daemon:
  sudo /etc/init.d/krb5-kdc start
  Verify the two ldap servers (and kerberos by extension) are in sync.

You now have redundant KDCs on your network, and with redundant LDAP servers you should be able to continue to authenticate users if one LDAP server, one Kerberos server, or one LDAP and one Kerberos server become unavailable.

Ссылки

  The Kerberos Admin Guide has some additional details.
  For more information on kdb5_ldap_util see Section 5.6 and the kdb5_ldap_util man page.
  Another useful link is the krb5.conf man page.
  Also, see the Kerberos and LDAP Ubuntu wiki page.