xref: /freebsd/crypto/krb5/doc/admin/database.rst (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1Database administration
2=======================
3
4A Kerberos database contains all of a realm's Kerberos principals,
5their passwords, and other administrative information about each
6principal.  For the most part, you will use the :ref:`kdb5_util(8)`
7program to manipulate the Kerberos database as a whole, and the
8:ref:`kadmin(1)` program to make changes to the entries in the
9database.  (One notable exception is that users will use the
10:ref:`kpasswd(1)` program to change their own passwords.)  The kadmin
11program has its own command-line interface, to which you type the
12database administrating commands.
13
14:ref:`kdb5_util(8)` provides a means to create, delete, load, or dump
15a Kerberos database.  It also contains commands to roll over the
16database master key, and to stash a copy of the key so that the
17:ref:`kadmind(8)` and :ref:`krb5kdc(8)` daemons can use the database
18without manual input.
19
20:ref:`kadmin(1)` provides for the maintenance of Kerberos principals,
21password policies, and service key tables (keytabs).  Normally it
22operates as a network client using Kerberos authentication to
23communicate with :ref:`kadmind(8)`, but there is also a variant, named
24kadmin.local, which directly accesses the Kerberos database on the
25local filesystem (or through LDAP).  kadmin.local is necessary to set
26up enough of the database to be able to use the remote version.
27
28kadmin can authenticate to the admin server using the service
29principal ``kadmin/admin`` or ``kadmin/HOST`` (where *HOST* is the
30hostname of the admin server).  If the credentials cache contains a
31ticket for either service principal and the **-c** ccache option is
32specified, that ticket is used to authenticate to KADM5.  Otherwise,
33the **-p** and **-k** options are used to specify the client Kerberos
34principal name used to authenticate.  Once kadmin has determined the
35principal name, it requests a ``kadmin/admin`` Kerberos service ticket
36from the KDC, and uses that service ticket to authenticate to KADM5.
37
38See :ref:`kadmin(1)` for the available kadmin and kadmin.local
39commands and options.
40
41
42.. _principals:
43
44Principals
45----------
46
47Each entry in the Kerberos database contains a Kerberos principal and
48the attributes and policies associated with that principal.
49
50To add a principal to the database, use the :ref:`kadmin(1)`
51**add_principal** command.  User principals should usually be created
52with the ``+requires_preauth -allow_svr`` options to help mitigate
53dictionary attacks (see :ref:`dictionary`)::
54
55    kadmin: addprinc +requires_preauth -allow_svr alice
56    Enter password for principal "alice@KRBTEST.COM":
57    Re-enter password for principal "alice@KRBTEST.COM":
58
59User principals which will authenticate with :ref:`pkinit` should
60instead by created with the ``-nokey`` option:
61
62    kadmin: addprinc -nokey alice
63
64Service principals can be created with the ``-nokey`` option;
65long-term keys will be added when a keytab is generated::
66
67    kadmin: addprinc -nokey host/foo.mit.edu
68    kadmin: ktadd -k foo.keytab host/foo.mit.edu
69    Entry for principal host/foo.mit.edu with kvno 1, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:foo.keytab.
70    Entry for principal host/foo.mit.edu with kvno 1, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:foo.keytab.
71
72To modify attributes of an existing principal, use the kadmin
73**modify_principal** command::
74
75    kadmin: modprinc -expire tomorrow alice
76    Principal "alice@KRBTEST.COM" modified.
77
78To delete a principal, use the kadmin **delete_principal** command::
79
80    kadmin: delprinc alice
81    Are you sure you want to delete the principal "alice@KRBTEST.COM"? (yes/no): yes
82    Principal "alice@KRBTEST.COM" deleted.
83    Make sure that you have removed this principal from all ACLs before reusing.
84
85To change a principal's password, use the kadmin **change_password**
86command.  Password changes made through kadmin are subject to the same
87password policies as would apply to password changes made through
88:ref:`kpasswd(1)`.
89
90To view the attributes of a principal, use the kadmin`
91**get_principal** command.
92
93To generate a listing of principals, use the kadmin
94**list_principals** command.
95
96
97.. _policies:
98
99Policies
100--------
101
102A policy is a set of rules governing passwords.  Policies can dictate
103minimum and maximum password lifetimes, minimum number of characters
104and character classes a password must contain, and the number of old
105passwords kept in the database.
106
107To add a new policy, use the :ref:`kadmin(1)` **add_policy** command::
108
109    kadmin: addpol -maxlife "1 year" -history 3 stduser
110
111To modify attributes of a principal, use the kadmin **modify_policy**
112command.  To delete a policy, use the kadmin **delete_policy**
113command.
114
115To associate a policy with a principal, use the kadmin
116**modify_principal** command with the **-policy** option:
117
118    kadmin: modprinc -policy stduser alice
119    Principal "alice@KRBTEST.COM" modified.
120
121A principal entry may be associated with a nonexistent policy, either
122because the policy did not exist at the time of associated or was
123deleted afterwards.  kadmin will warn when associated a principal with
124a nonexistent policy, and will annotate the policy name with "[does
125not exist]" in the **get_principal** output.
126
127
128.. _updating_history_key:
129
130Updating the history key
131~~~~~~~~~~~~~~~~~~~~~~~~
132
133If a policy specifies a number of old keys kept of two or more, the
134stored old keys are encrypted in a history key, which is found in the
135key data of the ``kadmin/history`` principal.
136
137Currently there is no support for proper rollover of the history key,
138but you can change the history key (for example, to use a better
139encryption type) at the cost of invalidating currently stored old
140keys.  To change the history key, run::
141
142    kadmin: change_password -randkey kadmin/history
143
144This command will fail if you specify the **-keepold** flag.  Only one
145new history key will be created, even if you specify multiple key/salt
146combinations.
147
148In the future, we plan to migrate towards encrypting old keys in the
149master key instead of the history key, and implementing proper
150rollover support for stored old keys.
151
152
153.. _privileges:
154
155Privileges
156----------
157
158Administrative privileges for the Kerberos database are stored in the
159file :ref:`kadm5.acl(5)`.
160
161.. note::
162
163          A common use of an admin instance is so you can grant
164          separate permissions (such as administrator access to the
165          Kerberos database) to a separate Kerberos principal. For
166          example, the user ``joeadmin`` might have a principal for
167          his administrative use, called ``joeadmin/admin``.  This
168          way, ``joeadmin`` would obtain ``joeadmin/admin`` tickets
169          only when he actually needs to use those permissions.
170
171
172.. _db_operations:
173
174Operations on the Kerberos database
175-----------------------------------
176
177The :ref:`kdb5_util(8)` command is the primary tool for administrating
178the Kerberos database when using the DB2 or LMDB modules (see
179:ref:`dbtypes`).  Creating a database is described in
180:ref:`create_db`.
181
182To create a stash file using the master password (because the database
183was not created with one using the ``create -s`` flag, or after
184restoring from a backup which did not contain the stash file), use the
185kdb5_util **stash** command::
186
187    $ kdb5_util stash
188    kdb5_util: Cannot find/read stored master key while reading master key
189    kdb5_util: Warning: proceeding without master key
190    Enter KDC database master key:  <= Type the KDC database master password.
191
192To destroy a database, use the kdb5_util destroy command::
193
194    $ kdb5_util destroy
195    Deleting KDC database stored in '/var/krb5kdc/principal', are you sure?
196    (type 'yes' to confirm)? yes
197    OK, deleting database '/var/krb5kdc/principal'...
198    ** Database '/var/krb5kdc/principal' destroyed.
199
200
201.. _restore_from_dump:
202
203Dumping and loading a Kerberos database
204~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205
206To dump a Kerberos database into a text file for backup or transfer
207purposes, use the :ref:`kdb5_util(8)` **dump** command on one of the
208KDCs::
209
210    $ kdb5_util dump dumpfile
211
212    $ kbd5_util dump -verbose dumpfile
213    kadmin/admin@ATHENA.MIT.EDU
214    krbtgt/ATHENA.MIT.EDU@ATHENA.MIT.EDU
215    kadmin/history@ATHENA.MIT.EDU
216    K/M@ATHENA.MIT.EDU
217    kadmin/changepw@ATHENA.MIT.EDU
218
219You may specify which principals to dump, using full principal names
220including realm::
221
222    $ kdb5_util dump -verbose someprincs K/M@ATHENA.MIT.EDU kadmin/admin@ATHENA.MIT.EDU
223    kadmin/admin@ATHENA.MIT.EDU
224    K/M@ATHENA.MIT.EDU
225
226To restore a Kerberos database dump from a file, use the
227:ref:`kdb5_util(8)` **load** command::
228
229    $ kdb5_util load dumpfile
230
231To update an existing database with a partial dump file containing
232only some principals, use the ``-update`` flag::
233
234    $ kdb5_util load -update someprincs
235
236.. note::
237
238          If the database file exists, and the *-update* flag was not
239          given, *kdb5_util* will overwrite the existing database.
240
241
242.. _updating_master_key:
243
244Updating the master key
245~~~~~~~~~~~~~~~~~~~~~~~
246
247Starting with release 1.7, :ref:`kdb5_util(8)` allows the master key
248to be changed using a rollover process, with minimal loss of
249availability.  To roll over the master key, follow these steps:
250
251#. On the primary KDC, run ``kdb5_util list_mkeys`` to view the
252   current master key version number (KVNO).  If you have never rolled
253   over the master key before, this will likely be version 1::
254
255    $ kdb5_util list_mkeys
256    Master keys for Principal: K/M@KRBTEST.COM
257    KVNO: 1, Enctype: aes256-cts-hmac-sha384-192, Active on: Thu Jan 01 00:00:00 UTC 1970 *
258
259#. On the primary KDC, run ``kdb5_util use_mkey 1`` to ensure that a
260   master key activation list is present in the database.  This step
261   is unnecessary in release 1.11.4 or later, or if the database was
262   initially created with release 1.7 or later.
263
264#. On the primary KDC, run ``kdb5_util add_mkey -s`` to create a new
265   master key and write it to the stash file.  Enter a secure password
266   when prompted.  If this is the first time you are changing the
267   master key, the new key will have version 2.  The new master key
268   will not be used until you make it active.
269
270#. Propagate the database to all replica KDCs, either manually or by
271   waiting until the next scheduled propagation.  If you do not have
272   any replica KDCs, you can skip this and the next step.
273
274#. On each replica KDC, run ``kdb5_util list_mkeys`` to verify that
275   the new master key is present, and then ``kdb5_util stash`` to
276   write the new master key to the replica KDC's stash file.
277
278#. On the primary KDC, run ``kdb5_util use_mkey 2`` to begin using the
279   new master key.  Replace ``2`` with the version of the new master
280   key, as appropriate.  You can optionally specify a date for the new
281   master key to become active; by default, it will become active
282   immediately.  Prior to release 1.12, :ref:`kadmind(8)` must be
283   restarted for this change to take full effect.
284
285#. On the primary KDC, run ``kdb5_util update_princ_encryption``.
286   This command will iterate over the database and re-encrypt all keys
287   in the new master key.  If the database is large and uses DB2, the
288   primary KDC will become unavailable while this command runs, but
289   clients should fail over to replica KDCs (if any are present)
290   during this time period.  In release 1.13 and later, you can
291   instead run ``kdb5_util -x unlockiter update_princ_encryption`` to
292   use unlocked iteration; this variant will take longer, but will
293   keep the database available to the KDC and kadmind while it runs.
294
295#. Wait until the above changes have propagated to all replica KDCs
296   and until all running KDC and kadmind processes have serviced
297   requests using updated principal entries.
298
299#. On the primary KDC, run ``kdb5_util purge_mkeys`` to clean up the
300   old master key.
301
302
303.. _ops_on_ldap:
304
305Operations on the LDAP database
306-------------------------------
307
308The :ref:`kdb5_ldap_util(8)` command is the primary tool for
309administrating the Kerberos database when using the LDAP module.
310Creating an LDAP Kerberos database is describe in :ref:`conf_ldap`.
311
312To view a list of realms in the LDAP database, use the kdb5_ldap_util
313**list** command::
314
315    $ kdb5_ldap_util list
316    KRBTEST.COM
317
318To modify the attributes of a realm, use the kdb5_ldap_util **modify**
319command.  For example, to change the default realm's maximum ticket
320life::
321
322    $ kdb5_ldap_util modify -maxtktlife "10 hours"
323
324To display the attributes of a realm, use the kdb5_ldap_util **view**
325command::
326
327    $ kdb5_ldap_util view
328                   Realm Name: KRBTEST.COM
329          Maximum Ticket Life: 0 days 00:10:00
330
331To remove a realm from the LDAP database, destroying its contents, use
332the kdb5_ldap_util **destroy** command::
333
334    $ kdb5_ldap_util destroy
335    Deleting KDC database of 'KRBTEST.COM', are you sure?
336    (type 'yes' to confirm)? yes
337    OK, deleting database of 'KRBTEST.COM'...
338    ** Database of 'KRBTEST.COM' destroyed.
339
340
341Ticket Policy operations
342~~~~~~~~~~~~~~~~~~~~~~~~
343
344Unlike the DB2 and LMDB modules, the LDAP module supports ticket
345policy objects, which can be associated with principals to restrict
346maximum ticket lifetimes and set mandatory principal flags.  Ticket
347policy objects are distinct from the password policies described
348earlier on this page, and are chiefly managed through kdb5_ldap_util
349rather than kadmin.  To create a new ticket policy, use the
350kdb5_ldap_util **create_policy** command::
351
352    $ kdb5_ldap_util create_policy -maxrenewlife "2 days" users
353
354To associate a ticket policy with a principal, use the
355:ref:`kadmin(1)` **modify_principal** (or **add_principal**) command
356with the **-x tktpolicy=**\ *policy* option::
357
358    $ kadmin.local modprinc -x tktpolicy=users alice
359
360To remove a ticket policy reference from a principal, use the same
361command with an empty *policy*::
362
363    $ kadmin.local modprinc -x tktpolicy= alice
364
365To list the existing ticket policy objects, use the kdb5_ldap_util
366**list_policy** command::
367
368    $ kdb5_ldap_util list_policy
369    users
370
371To modify the attributes of a ticket policy object, use the
372kdb5_ldap_util **modify_policy** command::
373
374    $ kdb5_ldap_util modify_policy -allow_svr +requires_preauth users
375
376To view the attributes of a ticket policy object, use the
377kdb5_ldap_util **view_policy** command::
378
379    $ kdb5_ldap_util view_policy users
380                Ticket policy: users
381       Maximum renewable life: 2 days 00:00:00
382                 Ticket flags: REQUIRES_PRE_AUTH DISALLOW_SVR
383
384To destroy an ticket policy object, use the kdb5_ldap_util
385**destroy_policy** command::
386
387    $ kdb5_ldap_util destroy_policy users
388    This will delete the policy object 'users', are you sure?
389    (type 'yes' to confirm)? yes
390    ** policy object 'users' deleted.
391
392
393.. _xrealm_authn:
394
395Cross-realm authentication
396--------------------------
397
398In order for a KDC in one realm to authenticate Kerberos users in a
399different realm, it must share a key with the KDC in the other realm.
400In both databases, there must be krbtgt service principals for both realms.
401For example, if you need to do cross-realm authentication between the realms
402``ATHENA.MIT.EDU`` and ``EXAMPLE.COM``, you would need to add the
403principals ``krbtgt/EXAMPLE.COM@ATHENA.MIT.EDU`` and
404``krbtgt/ATHENA.MIT.EDU@EXAMPLE.COM`` to both databases.
405These principals must all have the same passwords, key version
406numbers, and encryption types; this may require explicitly setting
407the key version number with the **-kvno** option.
408
409In the ATHENA.MIT.EDU and EXAMPLE.COM cross-realm case, the administrators
410would run the following commands on the KDCs in both realms::
411
412    shell%: kadmin.local -e "aes256-cts:normal"
413    kadmin: addprinc -requires_preauth krbtgt/ATHENA.MIT.EDU@EXAMPLE.COM
414    Enter password for principal krbtgt/ATHENA.MIT.EDU@EXAMPLE.COM:
415    Re-enter password for principal krbtgt/ATHENA.MIT.EDU@EXAMPLE.COM:
416    kadmin: addprinc -requires_preauth krbtgt/EXAMPLE.COM@ATHENA.MIT.EDU
417    Enter password for principal krbtgt/EXAMPLE.COM@ATHENA.MIT.EDU:
418    Enter password for principal krbtgt/EXAMPLE.COM@ATHENA.MIT.EDU:
419    kadmin:
420
421.. note::
422
423          Even if most principals in a realm are generally created
424          with the **requires_preauth** flag enabled, this flag is not
425          desirable on cross-realm authentication keys because doing
426          so makes it impossible to disable preauthentication on a
427          service-by-service basis.  Disabling it as in the example
428          above is recommended.
429
430.. note::
431
432          It is very important that these principals have good
433          passwords.  MIT recommends that TGT principal passwords be
434          at least 26 characters of random ASCII text.
435
436
437.. _changing_krbtgt_key:
438
439Changing the krbtgt key
440-----------------------
441
442A Kerberos Ticket Granting Ticket (TGT) is a service ticket for the
443principal ``krbtgt/REALM``.  The key for this principal is created
444when the Kerberos database is initialized and need not be changed.
445However, it will only have the encryption types supported by the KDC
446at the time of the initial database creation.  To allow use of newer
447encryption types for the TGT, this key has to be changed.
448
449Changing this key using the normal :ref:`kadmin(1)`
450**change_password** command would invalidate any previously issued
451TGTs.  Therefore, when changing this key, normally one should use the
452**-keepold** flag to change_password to retain the previous key in the
453database as well as the new key.  For example::
454
455    kadmin: change_password -randkey -keepold krbtgt/ATHENA.MIT.EDU@ATHENA.MIT.EDU
456
457.. warning::
458
459             After issuing this command, the old key is still valid
460             and is still vulnerable to (for instance) brute force
461             attacks.  To completely retire an old key or encryption
462             type, run the kadmin **purgekeys** command to delete keys
463             with older kvnos, ideally first making sure that all
464             tickets issued with the old keys have expired.
465
466Only the first krbtgt key of the newest key version is used to encrypt
467ticket-granting tickets.  However, the set of encryption types present
468in the krbtgt keys is used by default to determine the session key
469types supported by the krbtgt service (see
470:ref:`session_key_selection`).  Because non-MIT Kerberos clients
471sometimes send a limited set of encryption types when making AS
472requests, it can be important for the krbtgt service to support
473multiple encryption types.  This can be accomplished by giving the
474krbtgt principal multiple keys, which is usually as simple as not
475specifying any **-e** option when changing the krbtgt key, or by
476setting the **session_enctypes** string attribute on the krbtgt
477principal (see :ref:`set_string`).
478
479Due to a bug in releases 1.8 through 1.13, renewed and forwarded
480tickets may not work if the original ticket was obtained prior to a
481krbtgt key change and the modified ticket is obtained afterwards.
482Upgrading the KDC to release 1.14 or later will correct this bug.
483
484
485.. _incr_db_prop:
486
487Incremental database propagation
488--------------------------------
489
490Overview
491~~~~~~~~
492
493At some very large sites, dumping and transmitting the database can
494take more time than is desirable for changes to propagate from the
495primary KDC to the replica KDCs.  The incremental propagation support
496added in the 1.7 release is intended to address this.
497
498With incremental propagation enabled, all programs on the primary KDC
499that change the database also write information about the changes to
500an "update log" file, maintained as a circular buffer of a certain
501size.  A process on each replica KDC connects to a service on the
502primary KDC (currently implemented in the :ref:`kadmind(8)` server) and
503periodically requests the changes that have been made since the last
504check.  By default, this check is done every two minutes.
505
506Incremental propagation uses the following entries in the per-realm
507data in the KDC config file (See :ref:`kdc.conf(5)`):
508
509====================== =============== ===========================================
510iprop_enable           *boolean*       If *true*, then incremental propagation is enabled, and (as noted below) normal kprop propagation is disabled. The default is *false*.
511iprop_master_ulogsize  *integer*       Indicates the number of entries that should be retained in the update log. The default is 1000; the maximum number is 2500.
512iprop_replica_poll     *time interval* Indicates how often the replica should poll the primary KDC for changes to the database. The default is two minutes.
513iprop_port             *integer*       Specifies the port number to be used for incremental propagation. This is required in both primary and replica configuration files.
514iprop_resync_timeout   *integer*       Specifies the number of seconds to wait for a full propagation to complete. This is optional on replica configurations.  Defaults to 300 seconds (5 minutes).
515iprop_logfile          *file name*     Specifies where the update log file for the realm database is to be stored. The default is to use the *database_name* entry from the realms section of the config file :ref:`kdc.conf(5)`, with *.ulog* appended. (NOTE: If database_name isn't specified in the realms section, perhaps because the LDAP database back end is being used, or the file name is specified in the *dbmodules* section, then the hard-coded default for *database_name* is used. Determination of the *iprop_logfile*  default value will not use values from the *dbmodules* section.)
516====================== =============== ===========================================
517
518Both primary and replica sides must have a principal named
519``kiprop/hostname`` (where *hostname* is the lowercase,
520fully-qualified, canonical name for the host) registered in the
521Kerberos database, and have keys for that principal stored in the
522default keytab file (|keytab|).  The ``kiprop/hostname`` principal may
523have been created automatically for the primary KDC, but it must
524always be created for replica KDCs.
525
526On the primary KDC side, the ``kiprop/hostname`` principal must be
527listed in the kadmind ACL file :ref:`kadm5.acl(5)`, and given the
528**p** privilege (see :ref:`privileges`).
529
530On the replica KDC side, :ref:`kpropd(8)` should be run.  When
531incremental propagation is enabled, it will connect to the kadmind on
532the primary KDC and start requesting updates.
533
534The normal kprop mechanism is disabled by the incremental propagation
535support.  However, if the replica has been unable to fetch changes
536from the primary KDC for too long (network problems, perhaps), the log
537on the primary may wrap around and overwrite some of the updates that
538the replica has not yet retrieved.  In this case, the replica will
539instruct the primary KDC to dump the current database out to a file
540and invoke a one-time kprop propagation, with special options to also
541convey the point in the update log at which the replica should resume
542fetching incremental updates.  Thus, all the keytab and ACL setup
543previously described for kprop propagation is still needed.
544
545If an environment has a large number of replicas, it may be desirable
546to arrange them in a hierarchy instead of having the primary serve
547updates to every replica.  To do this, run ``kadmind -proponly`` on
548each intermediate replica, and ``kpropd -A upstreamhostname`` on
549downstream replicas to direct each one to the appropriate upstream
550replica.
551
552There are several known restrictions in the current implementation:
553
554- The incremental update protocol does not transport changes to policy
555  objects.  Any policy changes on the primary will result in full
556  resyncs to all replicas.
557- The replica's KDB module must support locking; it cannot be using the
558  LDAP KDB module.
559- The primary and replica must be able to initiate TCP connections in
560  both directions, without an intervening NAT.
561
562
563Sun/MIT incremental propagation differences
564~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565
566Sun donated the original code for supporting incremental database
567propagation to MIT.  Some changes have been made in the MIT source
568tree that will be visible to administrators.  (These notes are based
569on Sun's patches.  Changes to Sun's implementation since then may not
570be reflected here.)
571
572The Sun config file support looks for ``sunw_dbprop_enable``,
573``sunw_dbprop_master_ulogsize``, and ``sunw_dbprop_slave_poll``.
574
575The incremental propagation service is implemented as an ONC RPC
576service.  In the Sun implementation, the service is registered with
577rpcbind (also known as portmapper) and the client looks up the port
578number to contact.  In the MIT implementation, where interaction with
579some modern versions of rpcbind doesn't always work well, the port
580number must be specified in the config file on both the primary and
581replica sides.
582
583The Sun implementation hard-codes pathnames in ``/var/krb5`` for the
584update log and the per-replica kprop dump files.  In the MIT
585implementation, the pathname for the update log is specified in the
586config file, and the per-replica dump files are stored in
587|kdcdir|\ ``/replica_datatrans_hostname``.
588