1Installing KDCs 2=============== 3 4When setting up Kerberos in a production environment, it is best to 5have multiple replica KDCs alongside with a primary KDC to ensure the 6continued availability of the Kerberized services. Each KDC contains 7a copy of the Kerberos database. The primary KDC contains the 8writable copy of the realm database, which it replicates to the 9replica KDCs at regular intervals. All database changes (such as 10password changes) are made on the primary KDC. Replica KDCs provide 11Kerberos ticket-granting services, but not database administration, 12when the primary KDC is unavailable. MIT recommends that you install 13all of your KDCs to be able to function as either the primary or one 14of the replicas. This will enable you to easily switch your primary 15KDC with one of the replicas if necessary (see 16:ref:`switch_primary_replica`). This installation procedure is based 17on that recommendation. 18 19.. warning:: 20 21 - The Kerberos system relies on the availability of correct time 22 information. Ensure that the primary and all replica KDCs have 23 properly synchronized clocks. 24 25 - It is best to install and run KDCs on secured and dedicated 26 hardware with limited access. If your KDC is also a file 27 server, FTP server, Web server, or even just a client machine, 28 someone who obtained root access through a security hole in any 29 of those areas could potentially gain access to the Kerberos 30 database. 31 32 33Install and configure the primary KDC 34------------------------------------- 35 36Install Kerberos either from the OS-provided packages or from the 37source (See :ref:`do_build`). 38 39.. note:: 40 41 For the purpose of this document we will use the following 42 names:: 43 44 kerberos.mit.edu - primary KDC 45 kerberos-1.mit.edu - replica KDC 46 ATHENA.MIT.EDU - realm name 47 .k5.ATHENA.MIT.EDU - stash file 48 admin/admin - admin principal 49 50 See :ref:`mitK5defaults` for the default names and locations 51 of the relevant to this topic files. Adjust the names and 52 paths to your system environment. 53 54 55Edit KDC configuration files 56---------------------------- 57 58Modify the configuration files, :ref:`krb5.conf(5)` and 59:ref:`kdc.conf(5)`, to reflect the correct information (such as 60domain-realm mappings and Kerberos servers names) for your realm. 61(See :ref:`mitK5defaults` for the recommended default locations for 62these files). 63 64Most of the tags in the configuration have default values that will 65work well for most sites. There are some tags in the 66:ref:`krb5.conf(5)` file whose values must be specified, and this 67section will explain those. 68 69If the locations for these configuration files differs from the 70default ones, set **KRB5_CONFIG** and **KRB5_KDC_PROFILE** environment 71variables to point to the krb5.conf and kdc.conf respectively. For 72example:: 73 74 export KRB5_CONFIG=/yourdir/krb5.conf 75 export KRB5_KDC_PROFILE=/yourdir/kdc.conf 76 77 78krb5.conf 79~~~~~~~~~ 80 81If you are not using DNS TXT records (see :ref:`mapping_hostnames`), 82you must specify the **default_realm** in the :ref:`libdefaults` 83section. If you are not using DNS URI or SRV records (see 84:ref:`kdc_hostnames` and :ref:`kdc_discovery`), you must include the 85**kdc** tag for each *realm* in the :ref:`realms` section. To 86communicate with the kadmin server in each realm, the **admin_server** 87tag must be set in the 88:ref:`realms` section. 89 90An example krb5.conf file:: 91 92 [libdefaults] 93 default_realm = ATHENA.MIT.EDU 94 95 [realms] 96 ATHENA.MIT.EDU = { 97 kdc = kerberos.mit.edu 98 kdc = kerberos-1.mit.edu 99 admin_server = kerberos.mit.edu 100 } 101 102 103kdc.conf 104~~~~~~~~ 105 106The kdc.conf file can be used to control the listening ports of the 107KDC and kadmind, as well as realm-specific defaults, the database type 108and location, and logging. 109 110An example kdc.conf file:: 111 112 [kdcdefaults] 113 kdc_listen = 88 114 kdc_tcp_listen = 88 115 116 [realms] 117 ATHENA.MIT.EDU = { 118 kadmind_port = 749 119 max_life = 12h 0m 0s 120 max_renewable_life = 7d 0h 0m 0s 121 master_key_type = aes256-cts 122 supported_enctypes = aes256-cts:normal aes128-cts:normal 123 # If the default location does not suit your setup, 124 # explicitly configure the following values: 125 # database_name = /var/krb5kdc/principal 126 # key_stash_file = /var/krb5kdc/.k5.ATHENA.MIT.EDU 127 # acl_file = /var/krb5kdc/kadm5.acl 128 } 129 130 [logging] 131 # By default, the KDC and kadmind will log output using 132 # syslog. You can instead send log output to files like this: 133 kdc = FILE:/var/log/krb5kdc.log 134 admin_server = FILE:/var/log/kadmin.log 135 default = FILE:/var/log/krb5lib.log 136 137Replace ``ATHENA.MIT.EDU`` and ``kerberos.mit.edu`` with the name of 138your Kerberos realm and server respectively. 139 140.. note:: 141 142 You have to have write permission on the target directories 143 (these directories must exist) used by **database_name**, 144 **key_stash_file**, and **acl_file**. 145 146 147.. _create_db: 148 149Create the KDC database 150----------------------- 151 152You will use the :ref:`kdb5_util(8)` command on the primary KDC to 153create the Kerberos database and the optional :ref:`stash_definition`. 154 155.. note:: 156 157 If you choose not to install a stash file, the KDC will 158 prompt you for the master key each time it starts up. This 159 means that the KDC will not be able to start automatically, 160 such as after a system reboot. 161 162:ref:`kdb5_util(8)` will prompt you for the master password for the 163Kerberos database. This password can be any string. A good password 164is one you can remember, but that no one else can guess. Examples of 165bad passwords are words that can be found in a dictionary, any common 166or popular name, especially a famous person (or cartoon character), 167your username in any form (e.g., forward, backward, repeated twice, 168etc.), and any of the sample passwords that appear in this manual. 169One example of a password which might be good if it did not appear in 170this manual is "MITiys4K5!", which represents the sentence "MIT is 171your source for Kerberos 5!" (It's the first letter of each word, 172substituting the numeral "4" for the word "for", and includes the 173punctuation mark at the end.) 174 175The following is an example of how to create a Kerberos database and 176stash file on the primary KDC, using the :ref:`kdb5_util(8)` command. 177Replace ``ATHENA.MIT.EDU`` with the name of your Kerberos realm:: 178 179 shell% kdb5_util create -r ATHENA.MIT.EDU -s 180 181 Initializing database '/usr/local/var/krb5kdc/principal' for realm 'ATHENA.MIT.EDU', 182 master key name 'K/M@ATHENA.MIT.EDU' 183 You will be prompted for the database Master Password. 184 It is important that you NOT FORGET this password. 185 Enter KDC database master key: <= Type the master password. 186 Re-enter KDC database master key to verify: <= Type it again. 187 shell% 188 189This will create five files in |kdcdir| (or at the locations specified 190in :ref:`kdc.conf(5)`): 191 192* two Kerberos database files, ``principal``, and ``principal.ok`` 193* the Kerberos administrative database file, ``principal.kadm5`` 194* the administrative database lock file, ``principal.kadm5.lock`` 195* the stash file, in this example ``.k5.ATHENA.MIT.EDU``. If you do 196 not want a stash file, run the above command without the **-s** 197 option. 198 199For more information on administrating Kerberos database see 200:ref:`db_operations`. 201 202 203.. _admin_acl: 204 205Add administrators to the ACL file 206---------------------------------- 207 208Next, you need create an Access Control List (ACL) file and put the 209Kerberos principal of at least one of the administrators into it. 210This file is used by the :ref:`kadmind(8)` daemon to control which 211principals may view and make privileged modifications to the Kerberos 212database files. The ACL filename is determined by the **acl_file** 213variable in :ref:`kdc.conf(5)`; the default is |kdcdir|\ 214``/kadm5.acl``. 215 216For more information on Kerberos ACL file see :ref:`kadm5.acl(5)`. 217 218.. _addadmin_kdb: 219 220Add administrators to the Kerberos database 221------------------------------------------- 222 223Next you need to add administrative principals (i.e., principals who 224are allowed to administer Kerberos database) to the Kerberos database. 225You *must* add at least one principal now to allow communication 226between the Kerberos administration daemon kadmind and the kadmin 227program over the network for further administration. To do this, use 228the kadmin.local utility on the primary KDC. kadmin.local is designed 229to be run on the primary KDC host without using Kerberos 230authentication to an admin server; instead, it must have read and 231write access to the Kerberos database on the local filesystem. 232 233The administrative principals you create should be the ones you added 234to the ACL file (see :ref:`admin_acl`). 235 236In the following example, the administrative principal ``admin/admin`` 237is created:: 238 239 shell% kadmin.local 240 241 kadmin.local: addprinc admin/admin@ATHENA.MIT.EDU 242 243 No policy specified for "admin/admin@ATHENA.MIT.EDU"; 244 assigning "default". 245 Enter password for principal admin/admin@ATHENA.MIT.EDU: <= Enter a password. 246 Re-enter password for principal admin/admin@ATHENA.MIT.EDU: <= Type it again. 247 Principal "admin/admin@ATHENA.MIT.EDU" created. 248 kadmin.local: 249 250.. _start_kdc_daemons: 251 252Start the Kerberos daemons on the primary KDC 253--------------------------------------------- 254 255At this point, you are ready to start the Kerberos KDC 256(:ref:`krb5kdc(8)`) and administrative daemons on the primary KDC. To 257do so, type:: 258 259 shell% krb5kdc 260 shell% kadmind 261 262Each server daemon will fork and run in the background. 263 264.. note:: 265 266 Assuming you want these daemons to start up automatically at 267 boot time, you can add them to the KDC's ``/etc/rc`` or 268 ``/etc/inittab`` file. You need to have a 269 :ref:`stash_definition` in order to do this. 270 271You can verify that they started properly by checking for their 272startup messages in the logging locations you defined in 273:ref:`krb5.conf(5)` (see :ref:`logging`). For example:: 274 275 shell% tail /var/log/krb5kdc.log 276 Dec 02 12:35:47 beeblebrox krb5kdc[3187](info): commencing operation 277 shell% tail /var/log/kadmin.log 278 Dec 02 12:35:52 beeblebrox kadmind[3189](info): starting 279 280Any errors the daemons encounter while starting will also be listed in 281the logging output. 282 283As an additional verification, check if :ref:`kinit(1)` succeeds 284against the principals that you have created on the previous step 285(:ref:`addadmin_kdb`). Run:: 286 287 shell% kinit admin/admin@ATHENA.MIT.EDU 288 289 290Install the replica KDCs 291------------------------ 292 293You are now ready to start configuring the replica KDCs. 294 295.. note:: 296 297 Assuming you are setting the KDCs up so that you can easily 298 switch the primary KDC with one of the replicas, you should 299 perform each of these steps on the primary KDC as well as 300 the replica KDCs, unless these instructions specify 301 otherwise. 302 303 304.. _replica_host_key: 305 306Create host keytabs for replica KDCs 307~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 308 309Each KDC needs a ``host`` key in the Kerberos database. These keys 310are used for mutual authentication when propagating the database dump 311file from the primary KDC to the secondary KDC servers. 312 313On the primary KDC, connect to administrative interface and create the 314host principal for each of the KDCs' ``host`` services. For example, 315if the primary KDC were called ``kerberos.mit.edu``, and you had a 316replica KDC named ``kerberos-1.mit.edu``, you would type the 317following:: 318 319 shell% kadmin 320 kadmin: addprinc -randkey host/kerberos.mit.edu 321 No policy specified for "host/kerberos.mit.edu@ATHENA.MIT.EDU"; assigning "default" 322 Principal "host/kerberos.mit.edu@ATHENA.MIT.EDU" created. 323 324 kadmin: addprinc -randkey host/kerberos-1.mit.edu 325 No policy specified for "host/kerberos-1.mit.edu@ATHENA.MIT.EDU"; assigning "default" 326 Principal "host/kerberos-1.mit.edu@ATHENA.MIT.EDU" created. 327 328It is not strictly necessary to have the primary KDC server in the 329Kerberos database, but it can be handy if you want to be able to swap 330the primary KDC with one of the replicas. 331 332Next, extract ``host`` random keys for all participating KDCs and 333store them in each host's default keytab file. Ideally, you should 334extract each keytab locally on its own KDC. If this is not feasible, 335you should use an encrypted session to send them across the network. 336To extract a keytab directly on a replica KDC called 337``kerberos-1.mit.edu``, you would execute the following command:: 338 339 kadmin: ktadd host/kerberos-1.mit.edu 340 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 341 type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab. 342 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 343 type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab. 344 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 345 type aes256-cts-hmac-sha384-192 added to keytab FILE:/etc/krb5.keytab. 346 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 347 type arcfour-hmac added to keytab FILE:/etc/krb5.keytab. 348 349If you are instead extracting a keytab for the replica KDC called 350``kerberos-1.mit.edu`` on the primary KDC, you should use a dedicated 351temporary keytab file for that machine's keytab:: 352 353 kadmin: ktadd -k /tmp/kerberos-1.keytab host/kerberos-1.mit.edu 354 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 355 type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab. 356 Entry for principal host/kerberos-1.mit.edu with kvno 2, encryption 357 type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab. 358 359The file ``/tmp/kerberos-1.keytab`` can then be installed as 360``/etc/krb5.keytab`` on the host ``kerberos-1.mit.edu``. 361 362 363Configure replica KDCs 364~~~~~~~~~~~~~~~~~~~~~~ 365 366Database propagation copies the contents of the primary's database, 367but does not propagate configuration files, stash files, or the kadm5 368ACL file. The following files must be copied by hand to each replica 369(see :ref:`mitK5defaults` for the default locations for these files): 370 371* krb5.conf 372* kdc.conf 373* kadm5.acl 374* master key stash file 375 376Move the copied files into their appropriate directories, exactly as 377on the primary KDC. kadm5.acl is only needed to allow a replica to 378swap with the primary KDC. 379 380The database is propagated from the primary KDC to the replica KDCs 381via the :ref:`kpropd(8)` daemon. You must explicitly specify the 382principals which are allowed to provide Kerberos dump updates on the 383replica machine with a new database. Create a file named kpropd.acl 384in the KDC state directory containing the ``host`` principals for each 385of the KDCs:: 386 387 host/kerberos.mit.edu@ATHENA.MIT.EDU 388 host/kerberos-1.mit.edu@ATHENA.MIT.EDU 389 390.. note:: 391 392 If you expect that the primary and replica KDCs will be 393 switched at some point of time, list the host principals 394 from all participating KDC servers in kpropd.acl files on 395 all of the KDCs. Otherwise, you only need to list the 396 primary KDC's host principal in the kpropd.acl files of the 397 replica KDCs. 398 399Then, add the following line to ``/etc/inetd.conf`` on each KDC 400(adjust the path to kpropd):: 401 402 krb5_prop stream tcp nowait root /usr/local/sbin/kpropd kpropd 403 404You also need to add the following line to ``/etc/services`` on each 405KDC, if it is not already present (assuming that the default port is 406used):: 407 408 krb5_prop 754/tcp # Kerberos replica propagation 409 410Restart inetd daemon. 411 412Alternatively, start :ref:`kpropd(8)` as a stand-alone daemon. This is 413required when incremental propagation is enabled. 414 415Now that the replica KDC is able to accept database propagation, 416you’ll need to propagate the database from the primary server. 417 418NOTE: Do not start the replica KDC yet; you still do not have a copy 419of the primary's database. 420 421 422.. _kprop_to_replicas: 423 424Propagate the database to each replica KDC 425~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 426 427First, create a dump file of the database on the primary KDC, as 428follows:: 429 430 shell% kdb5_util dump /usr/local/var/krb5kdc/replica_datatrans 431 432Then, manually propagate the database to each replica KDC, as in the 433following example:: 434 435 shell% kprop -f /usr/local/var/krb5kdc/replica_datatrans kerberos-1.mit.edu 436 437 Database propagation to kerberos-1.mit.edu: SUCCEEDED 438 439You will need a script to dump and propagate the database. The 440following is an example of a Bourne shell script that will do this. 441 442.. note:: 443 444 Remember that you need to replace ``/usr/local/var/krb5kdc`` 445 with the name of the KDC state directory. 446 447:: 448 449 #!/bin/sh 450 451 kdclist = "kerberos-1.mit.edu kerberos-2.mit.edu" 452 453 kdb5_util dump /usr/local/var/krb5kdc/replica_datatrans 454 455 for kdc in $kdclist 456 do 457 kprop -f /usr/local/var/krb5kdc/replica_datatrans $kdc 458 done 459 460You will need to set up a cron job to run this script at the intervals 461you decided on earlier (see :ref:`db_prop`). 462 463Now that the replica KDC has a copy of the Kerberos database, you can 464start the krb5kdc daemon:: 465 466 shell% krb5kdc 467 468As with the primary KDC, you will probably want to add this command to 469the KDCs' ``/etc/rc`` or ``/etc/inittab`` files, so they will start 470the krb5kdc daemon automatically at boot time. 471 472 473Propagation failed? 474################### 475 476You may encounter the following error messages. For a more detailed 477discussion on possible causes and solutions click on the error link 478to be redirected to :ref:`troubleshoot` section. 479 480.. include:: ./troubleshoot.rst 481 :start-after: _prop_failed_start: 482 :end-before: _prop_failed_end: 483 484 485Add Kerberos principals to the database 486--------------------------------------- 487 488Once your KDCs are set up and running, you are ready to use 489:ref:`kadmin(1)` to load principals for your users, hosts, and other 490services into the Kerberos database. This procedure is described 491fully in :ref:`principals`. 492 493You may occasionally want to use one of your replica KDCs as the 494primary. This might happen if you are upgrading the primary KDC, or 495if your primary KDC has a disk crash. See the following section for 496the instructions. 497 498 499.. _switch_primary_replica: 500 501Switching primary and replica KDCs 502---------------------------------- 503 504You may occasionally want to use one of your replica KDCs as the 505primary. This might happen if you are upgrading the primary KDC, or 506if your primary KDC has a disk crash. 507 508Assuming you have configured all of your KDCs to be able to function 509as either the primary KDC or a replica KDC (as this document 510recommends), all you need to do to make the changeover is: 511 512If the primary KDC is still running, do the following on the *old* 513primary KDC: 514 515#. Kill the kadmind process. 516#. Disable the cron job that propagates the database. 517#. Run your database propagation script manually, to ensure that the 518 replicas all have the latest copy of the database (see 519 :ref:`kprop_to_replicas`). 520 521On the *new* primary KDC: 522 523#. Start the :ref:`kadmind(8)` daemon (see :ref:`start_kdc_daemons`). 524#. Set up the cron job to propagate the database (see 525 :ref:`kprop_to_replicas`). 526#. Switch the CNAMEs of the old and new primary KDCs. If you can't do 527 this, you'll need to change the :ref:`krb5.conf(5)` file on every 528 client machine in your Kerberos realm. 529 530 531Incremental database propagation 532-------------------------------- 533 534If you expect your Kerberos database to become large, you may wish to 535set up incremental propagation to replica KDCs. See 536:ref:`incr_db_prop` for details. 537