1@c $Id$ 2 3@node Setting up a realm, Applications, Building and Installing, Top 4 5@chapter Setting up a realm 6 7A 8@cindex realm 9realm is an administrative domain. The name of a Kerberos realm is 10usually the Internet domain name in uppercase. Call your realm the same 11as your Internet domain name if you do not have strong reasons for not 12doing so. It will make life easier for you and everyone else. 13 14@menu 15* Configuration file:: 16* Creating the database:: 17* Modifying the database:: 18* Checking the setup:: 19* keytabs:: 20* Serving Kerberos 4/524/kaserver:: 21* Remote administration:: 22* Password changing:: 23* Testing clients and servers:: 24* Slave Servers:: 25* Incremental propagation:: 26* Encryption types and salting:: 27* Credential cache server - KCM:: 28* Cross realm:: 29* Transit policy:: 30* Setting up DNS:: 31* Using LDAP to store the database:: 32* Providing Kerberos credentials to servers and programs:: 33* Setting up PK-INIT:: 34* Debugging Kerberos problems:: 35@end menu 36 37@node Configuration file, Creating the database, Setting up a realm, Setting up a realm 38@section Configuration file 39 40To setup a realm you will first have to create a configuration file: 41@file{/etc/krb5.conf}. The @file{krb5.conf} file can contain many 42configuration options, some of which are described here. 43 44There is a sample @file{krb5.conf} supplied with the distribution. 45 46The configuration file is a hierarchical structure consisting of 47sections, each containing a list of bindings (either variable 48assignments or subsections). A section starts with 49@samp{[@samp{section-name}]}. A binding consists of a left hand side, an equal sign 50(@samp{=}) and a right hand side (the left hand side tag must be 51separated from the equal sign with some whitespace). Subsections have a 52@samp{@{} as the first non-whitespace character after the equal sign. All 53other bindings are treated as variable assignments. The value of a 54variable extends to the end of the line. 55 56@example 57[section1] 58 a-subsection = @{ 59 var = value1 60 other-var = value with @{@} 61 sub-sub-section = @{ 62 var = 123 63 @} 64 @} 65 var = some other value 66[section2] 67 var = yet another value 68@end example 69 70In this manual, names of sections and bindings will be given as strings 71separated by slashes (@samp{/}). The @samp{other-var} variable will thus 72be @samp{section1/a-subsection/other-var}. 73 74For in-depth information about the contents of the configuration file, refer to 75the @file{krb5.conf} manual page. Some of the more important sections 76are briefly described here. 77 78The @samp{libdefaults} section contains a list of library configuration 79parameters, such as the default realm and the timeout for KDC 80responses. The @samp{realms} section contains information about specific 81realms, such as where they hide their KDC@. This section serves the same 82purpose as the Kerberos 4 @file{krb.conf} file, but can contain more 83information. Finally the @samp{domain_realm} section contains a list of 84mappings from domains to realms, equivalent to the Kerberos 4 85@file{krb.realms} file. 86 87To continue with the realm setup, you will have to create a configuration file, 88with contents similar to the following. 89 90@example 91[libdefaults] 92 default_realm = MY.REALM 93[realms] 94 MY.REALM = @{ 95 kdc = my.kdc my.slave.kdc 96 kdc = my.third.kdc 97 kdc = 130.237.237.17 98 kdc = [2001:6b0:1:ea::100]:88 99 @} 100[domain_realm] 101 .my.domain = MY.REALM 102 103@end example 104 105If you use a realm name equal to your domain name, you can omit the 106@samp{libdefaults}, and @samp{domain_realm}, sections. If you have a DNS 107SRV-record for your realm, or your Kerberos server has DNS CNAME 108@samp{kerberos.my.realm}, you can omit the @samp{realms} section too. 109 110@cindex KRB5_CONFIG 111If you want to use a different configuration file then the default you 112can point a file with the enviroment variable @samp{KRB5_CONFIG}. 113 114@example 115env KRB5_CONFIG=$HOME/etc/krb5.conf kinit user@@REALM 116@end example 117 118@node Creating the database, Modifying the database, Configuration file, Setting up a realm 119@section Creating the database 120 121The database library will look for the database in the directory 122@file{@value{dbdir}}, so you should probably create that directory. 123Make sure the directory has restrictive permissions. 124 125@example 126# mkdir /var/heimdal 127@end example 128 129The keys of all the principals are stored in the database. If you 130choose to, these can be encrypted with a master key. You do not have to 131remember this key (or password), but just to enter it once and it will 132be stored in a file (@file{/var/heimdal/m-key}). If you want to have a 133master key, run @samp{kstash} to create this master key: 134 135@example 136# kstash 137Master key: 138Verifying password - Master key: 139@end example 140 141If you want to generate a random master key you can use the 142@kbd{--random-key} flag to kstash. This will make sure you have a good key 143on which attackers can't do a dictionary attack. 144 145If you have a master key, make sure you make a backup of your master 146key file; without it backups of the database are of no use. 147 148To initialise the database use the @command{kadmin} program, with the 149@kbd{-l} option (to enable local database mode). First issue a 150@kbd{init MY.REALM} command. This will create the database and insert 151default principals for that realm. You can have more than one realm in 152one database, so @samp{init} does not destroy any old database. 153 154Before creating the database, @samp{init} will ask you some questions 155about maximum ticket lifetimes. 156 157After creating the database you should probably add yourself to it. You 158do this with the @samp{add} command. It takes as argument the name of a 159principal. The principal should contain a realm, so if you haven't set up 160a default realm, you will need to explicitly include the realm. 161 162@example 163# kadmin -l 164kadmin> init MY.REALM 165Realm max ticket life [unlimited]: 166Realm max renewable ticket life [unlimited]: 167kadmin> add me 168Max ticket life [unlimited]: 169Max renewable life [unlimited]: 170Attributes []: 171Password: 172Verifying password - Password: 173@end example 174 175Now start the KDC and try getting a ticket. 176 177@example 178# kdc & 179# kinit me 180me@@MY.REALMS's Password: 181# klist 182Credentials cache: /tmp/krb5cc_0 183 Principal: me@@MY.REALM 184 185 Issued Expires Principal 186Aug 25 07:25:55 Aug 25 17:25:55 krbtgt/MY.REALM@@MY.REALM 187@end example 188 189If you are curious you can use the @samp{dump} command to list all the 190entries in the database. It should look something similar to the 191following example (note that the entries here are truncated for 192typographical reasons): 193 194@smallexample 195kadmin> dump 196me@@MY.REALM 1:0:1:0b01d3cb7c293b57:-:0:7:8aec316b9d1629e3baf8 ... 197kadmin/admin@@MY.REALM 1:0:1:e5c8a2675b37a443:-:0:7:cb913ebf85 ... 198krbtgt/MY.REALM@@MY.REALM 1:0:1:52b53b61c875ce16:-:0:7:c8943be ... 199kadmin/changepw@@MY.REALM 1:0:1:f48c8af2b340e9fb:-:0:7:e3e6088 ... 200@end smallexample 201 202@node Modifying the database, Checking the setup, Creating the database, Setting up a realm 203@section Modifying the database 204 205All modifications of principals are done with with kadmin. 206 207A principal has several attributes and lifetimes associated with it. 208 209Principals are added, renamed, modified, and deleted with the kadmin 210commands @samp{add}, @samp{rename}, @samp{modify}, @samp{delete}. 211Both interactive editing and command line flags can be used (use --help 212to list the available options). 213 214There are different kinds of types for the fields in the database; 215attributes, absolute time times and relative times. 216 217@subsection Attributes 218 219When doing interactive editing, attributes are listed with @samp{?}. 220 221The attributes are given in a comma (@samp{,}) separated list. 222Attributes are removed from the list by prefixing them with @samp{-}. 223 224@smallexample 225kadmin> modify me 226Max ticket life [1 day]: 227Max renewable life [1 week]: 228Principal expiration time [never]: 229Password expiration time [never]: 230Attributes [disallow-renewable]: requires-pre-auth,-disallow-renewable 231kadmin> get me 232 Principal: me@@MY.REALM 233[...] 234 Attributes: requires-pre-auth 235@end smallexample 236 237@subsection Absolute times 238 239The format for absolute times are any of the following: 240 241@smallexample 242never 243now 244YYYY-mm-dd 245YYYY-mm-dd HH:MM:SS 246@end smallexample 247 248 249@subsection Relative times 250 251The format for relative times are any of the following combined: 252 253@smallexample 254N year 255M month 256O day 257P hour 258Q minute 259R second 260@end smallexample 261 262@c Describe more of kadmin commands here... 263 264@node Checking the setup, keytabs, Modifying the database, Setting up a realm 265@section Checking the setup 266 267There are two tools that can check the consistency of the Kerberos 268configuration file and the Kerberos database. 269 270The Kerberos configuration file is checked using 271@command{verify_krb5_conf}. The tool checks for common errors, but 272commonly there are several uncommon configuration entries that are 273never added to the tool and thus generates ``unknown entry'' warnings. 274This is usually nothing to worry about. 275 276The database check is built into the kadmin tool. It will check for 277common configuration error that will cause problems later. Common 278check are for existence and flags on important principals. The 279database check by run by the following command : 280 281@example 282kadmin -l check REALM.EXAMPLE.ORG 283@end example 284 285@node keytabs, Serving Kerberos 4/524/kaserver, Checking the setup, Setting up a realm 286@section keytabs 287 288To extract a service ticket from the database and put it in a keytab, you 289need to first create the principal in the database with @samp{add} 290(using the @kbd{--random-key} flag to get a random key) and then 291extract it with @samp{ext_keytab}. 292 293@example 294kadmin> add --random-key host/my.host.name 295Max ticket life [unlimited]: 296Max renewable life [unlimited]: 297Attributes []: 298kadmin> ext host/my.host.name 299kadmin> exit 300# ktutil list 301Version Type Principal 302 1 des-cbc-md5 host/my.host.name@@MY.REALM 303 1 des-cbc-md4 host/my.host.name@@MY.REALM 304 1 des-cbc-crc host/my.host.name@@MY.REALM 305 1 des3-cbc-sha1 host/my.host.name@@MY.REALM 306@end example 307 308@node Serving Kerberos 4/524/kaserver, Remote administration, keytabs, Setting up a realm 309@section Serving Kerberos 4/524/kaserver 310 311Heimdal can be configured to support 524, Kerberos 4 or kaserver. All 312these services are turned off by default. Kerberos 4 is always 313supported by the KDC, but the Kerberos 4 client support also depends 314on Kerberos 4 support having been included at compile-time, using 315@kbd{--with-krb4=dir}. 316 317@subsection 524 318 319524 is a service that allows the KDC to convert Kerberos 5 tickets to 320Kerberos 4 tickets for backward compatibility. See also Using 2b 321tokens with AFS in @xref{AFS}. 322 323524 can be turned on by adding this to the configuration file 324 325@example 326[kdc] 327 enable-524 = yes 328@end example 329 330@subsection Kerberos 4 331 332Kerberos 4 is the predecessor to to Kerberos 5. It only supports 333single DES@. You should only enable Kerberos 4 support if you have 334needs for compatibility with an installed base of Kerberos 4 335clients/servers. 336 337Kerberos 4 can be turned on by adding this to the configuration file 338 339@example 340[kdc] 341 enable-kerberos4 = yes 342@end example 343 344@subsection kaserver 345 346Kaserver is a Kerberos 4 that is used in AFS@. The protocol has some 347extra features over plain Kerberos 4, but like Kerberos 4, only uses 348single DES@. 349 350You should only enable Kaserver support if you have needs for 351compatibility with an installed base of AFS machines. 352 353Kaserver can be turned on by adding this to the configuration file 354 355@example 356[kdc] 357 enable-kaserver = yes 358@end example 359 360@node Remote administration, Password changing, Serving Kerberos 4/524/kaserver, Setting up a realm 361@section Remote administration 362 363The administration server, @command{kadmind}, can be started by 364@command{inetd} (which isn't recommended) or run as a normal daemon. If you 365want to start it from @command{inetd} you should add a line similar to the 366one below to your @file{/etc/inetd.conf}. 367 368@example 369kerberos-adm stream tcp nowait root /usr/heimdal/libexec/kadmind kadmind 370@end example 371 372You might need to add @samp{kerberos-adm} to your @file{/etc/services} 373as @samp{749/tcp}. 374 375Access to the administration server is controlled by an ACL file, 376(default @file{/var/heimdal/kadmind.acl}.) The file has the following 377syntax: 378@smallexample 379principal [priv1,priv2,...] [glob-pattern] 380@end smallexample 381 382The matching is from top to bottom for matching principals (and if given, 383glob-pattern). When there is a match, the access rights of that line are 384applied. 385 386The privileges you can assign to a principal are: @samp{add}, 387@samp{change-password} (or @samp{cpw} for short), @samp{delete}, 388@samp{get}, @samp{list}, and @samp{modify}, or the special privilege 389@samp{all}. All of these roughly correspond to the different commands 390in @command{kadmin}. 391 392If a @var{glob-pattern} is given on a line, it restricts the access 393rights for the principal to only apply for subjects that match the 394pattern. The patterns are of the same type as those used in shell 395globbing, see @url{none,,fnmatch(3)}. 396 397In the example below @samp{lha/admin} can change every principal in the 398database. @samp{jimmy/admin} can only modify principals that belong to 399the realm @samp{E.KTH.SE}. @samp{mille/admin} is working at the 400help desk, so he should only be able to change the passwords for single 401component principals (ordinary users). He will not be able to change any 402@samp{/admin} principal. 403 404@example 405lha/admin@@E.KTH.SE all 406jimmy/admin@@E.KTH.SE all *@@E.KTH.SE 407jimmy/admin@@E.KTH.SE all */*@@E.KTH.SE 408mille/admin@@E.KTH.SE change-password *@@E.KTH.SE 409@end example 410 411@node Password changing, Testing clients and servers, Remote administration, Setting up a realm 412@section Password changing 413 414To allow users to change their passwords, you should run @command{kpasswdd}. 415It is not run from @command{inetd}. 416 417You might need to add @samp{kpasswd} to your @file{/etc/services} as 418@samp{464/udp}. If your realm is not setup to use DNS, you might also 419need to add a @samp{kpasswd_server} entry to the realm configuration 420in @file{/etc/krb5.conf} on client machines: 421 422@example 423[realms] 424 MY.REALM = @{ 425 kdc = my.kdc my.slave.kdc 426 kpasswd_server = my.kdc 427 @} 428@end example 429 430@subsection Password quality assurance 431 432It is important that users have good passwords, both to make it harder 433to guess them and to avoid off-line attacks (although 434pre-authentication provides some defence against off-line attacks). 435To ensure that the users choose good passwords, you can enable 436password quality controls in @command{kpasswdd} and @command{kadmind}. 437The controls themselves are done in a shared library or an external 438program that is used by @command{kpasswdd}. To configure in these 439controls, add lines similar to the following to your 440@file{/etc/krb5.conf}: 441 442@example 443[password_quality] 444 policies = external-check builtin:minimum-length modulename:policyname 445 external_program = /bin/false 446 policy_libraries = @var{library1.so} @var{library2.so} 447@end example 448 449In @samp{[password_quality]policies} the module name is optional if 450the policy name is unique in all modules (members of 451@samp{policy_libraries}). All built-in policies can be qualified with 452a module name of @samp{builtin} to unambiguously specify the built-in 453policy and not a policy by the same name from a loaded module. 454 455The built-in policies are 456 457@itemize @bullet 458 459@item external-check 460 461Executes the program specified by @samp{[password_quality]external_program}. 462 463A number of key/value pairs are passed as input to the program, one per 464line, ending with the string @samp{end}. The key/value lines are of 465the form 466@example 467principal: @var{principal} 468new-password: @var{password} 469@end example 470where @var{password} is the password to check for the previous 471@var{principal}. 472 473If the external application approves the password, it should return 474@samp{APPROVED} on standard out and exit with exit code 0. If it 475doesn't approve the password, an one line error message explaining the 476problem should be returned on standard error and the application 477should exit with exit code 0. In case of a fatal error, the 478application should, if possible, print an error message on standard 479error and exit with a non-zero error code. 480 481@item minimum-length 482 483The minimum length password quality check reads the configuration file 484stanza @samp{[password_quality]min_length} and requires the password 485to be at least this length. 486 487@item character-class 488 489The character-class password quality check reads the configuration 490file stanza @samp{[password_quality]min_classes}. The policy requires 491the password to have characters from at least that many character 492classes. Default value if not given is 3. 493 494The four different characters classes are, uppercase, lowercase, 495number, special characters. 496 497@end itemize 498 499If you want to write your own shared object to check password 500policies, see the manual page @manpage{kadm5_pwcheck,3}. 501 502Code for a password quality checking function that uses the cracklib 503library can be found in @file{lib/kadm5/sample_password_check.c} in 504the source code distribution. It requires that the cracklib library 505be built with the patch available at 506@url{ftp://ftp.pdc.kth.se/pub/krb/src/cracklib.patch}. 507 508A sample policy external program is included in 509@file{lib/kadm5/check-cracklib.pl}. 510 511If no password quality checking function is configured, the only check 512performed is that the password is at least six characters long. 513 514To check the password policy settings, use the command 515@command{verify-password-quality} in @command{kadmin} program. The password 516verification is only performed locally, on the client. It may be 517convenient to set the environment variable @samp{KRB5_CONFIG} to point 518to a test version of @file{krb5.conf} while you're testing the 519@samp{[password_quality]} stanza that way. 520 521@node Testing clients and servers, Slave Servers, Password changing, Setting up a realm 522@section Testing clients and servers 523 524Now you should be able to run all the clients and servers. Refer to the 525appropriate man pages for information on how to use them. 526 527@node Slave Servers, Incremental propagation, Testing clients and servers, Setting up a realm 528@section Slave servers, Incremental propagation, Testing clients and servers, Setting up a realm 529 530It is desirable to have at least one backup (slave) server in case the 531master server fails. It is possible to have any number of such slave 532servers but more than three usually doesn't buy much more redundancy. 533 534All Kerberos servers for a realm must have the same database so that 535they present the same service to the users. The 536@pindex hprop 537@command{hprop} program, running on the master, will propagate the database 538to the slaves, running 539@pindex hpropd 540@command{hpropd} processes. 541 542Every slave needs a database directory, the master key (if it was used 543for the database) and a keytab with the principal 544@samp{hprop/@var{hostname}}. Add the principal with the 545@pindex ktutil 546@command{ktutil} command and start 547@pindex hpropd 548@command{hpropd}, as follows: 549 550@example 551slave# ktutil get -p foo/admin hprop/`hostname` 552slave# mkdir /var/heimdal 553slave# hpropd 554@end example 555 556The master will use the principal @samp{kadmin/hprop} to authenticate to 557the slaves. This principal should be added when running @kbd{kadmin -l 558init} but if you do not have it in your database for whatever reason, 559please add it with @kbd{kadmin -l add}. 560 561Then run 562@pindex hprop 563@code{hprop} on the master: 564 565@example 566master# hprop slave 567@end example 568 569This was just an hands-on example to make sure that everything was 570working properly. Doing it manually is of course the wrong way, and to 571automate this you will want to start 572@pindex hpropd 573@command{hpropd} from @command{inetd} on the slave(s) and regularly run 574@pindex hprop 575@command{hprop} on the master to regularly propagate the database. 576Starting the propagation once an hour from @command{cron} is probably a 577good idea. 578 579@node Incremental propagation, Encryption types and salting, Slave Servers, Setting up a realm 580@section Incremental propagation 581 582There is also a newer mechanism for 583doing incremental propagation in Heimdal. Instead of sending the whole 584database regularly, it sends the changes as they happen on the master to 585the slaves. The master keeps track of all the changes by assigning a 586version number to every change to the database. The slaves know which 587was the latest version they saw and in this way it can be determined if 588they are in sync or not. A log of all the changes is kept on the master, 589and when a slave is at an older version than the oldest one in the 590log, the whole database has to be sent. 591 592Protocol-wise, all the slaves connect to the master and as a greeting 593tell it the latest version that they have (@samp{IHAVE} message). The 594master then responds by sending all the changes between that version and 595the current version at the master (a series of @samp{FORYOU} messages) 596or the whole database in a @samp{TELLYOUEVERYTHING} message. There is 597also a keep-alive protocol that makes sure all slaves are up and running. 598 599In addition on listening on the network to get connection from new 600slaves, the ipropd-master also listens on a status unix 601socket. kadmind and kpasswdd both open that socket when a transation 602is done and written a notification to the socket. That cause 603ipropd-master to check for new version in the log file. As a fallback in 604case a notification is lost by the unix socket, the log file is 605checked after 30 seconds of no event. 606 607@subsection Configuring incremental propagation 608 609The program that runs on the master is @command{ipropd-master} and all 610clients run @command{ipropd-slave}. 611 612Create the file @file{/var/heimdal/slaves} on the master containing all 613the slaves that the database should be propagated to. Each line contains 614the full name of the principal (for example 615@samp{iprop/hemligare.foo.se@@FOO.SE}). 616 617You should already have @samp{iprop/tcp} defined as 2121, in your 618@file{/etc/services}. Otherwise, or if you need to use a different port 619for some peculiar reason, you can use the @kbd{--port} option. This is 620useful when you have multiple realms to distribute from one server. 621 622Then you need to create those principals that you added in the 623configuration file. Create one @samp{iprop/hostname} for the master and 624for every slave. 625 626 627@example 628master# /usr/heimdal/sbin/ktutil get iprop/`hostname` 629@end example 630 631@example 632slave# /usr/heimdal/sbin/ktutil get iprop/`hostname` 633@end example 634 635 636The next step is to start the @command{ipropd-master} process on the master 637server. The @command{ipropd-master} listens on the UNIX domain socket 638@file{/var/heimdal/signal} to know when changes have been made to the 639database so they can be propagated to the slaves. There is also a 640safety feature of testing the version number regularly (every 30 641seconds) to see if it has been modified by some means that do not raise 642this signal. Then, start @command{ipropd-slave} on all the slaves: 643 644@example 645master# /usr/heimdal/libexec/ipropd-master & 646slave# /usr/heimdal/libexec/ipropd-slave master & 647@end example 648 649To manage the iprop log file you should use the @command{iprop-log} 650command. With it you can dump, truncate and replay the logfile. 651 652@node Encryption types and salting, Credential cache server - KCM, Incremental propagation, Setting up a realm 653@section Encryption types and salting 654@cindex Salting 655@cindex Encryption types 656 657The encryption types that the KDC is going to assign by default is 658possible to change. Since the keys used for user authentication is 659salted the encryption types are described together with the salt 660strings. 661 662Salting is used to make it harder to pre-calculate all possible 663keys. Using a salt increases the search space to make it almost 664impossible to pre-calculate all keys. Salting is the process of mixing a 665public string (the salt) with the password, then sending it through an 666encryption type specific string-to-key function that will output the 667fixed size encryption key. 668 669In Kerberos 5 the salt is determined by the encryption type, except in 670some special cases. 671 672In @code{des} there is the Kerberos 4 salt 673(none at all) or the afs-salt (using the cell (realm in 674AFS lingo)). 675 676In @code{arcfour} (the encryption type that Microsoft Windows 2000 uses) 677there is no salt. This is to be compatible with NTLM keys in Windows 678NT 4. 679 680@code{[kadmin]default_keys} in @file{krb5.conf} controls 681what salting to use. 682 683The syntax of @code{[kadmin]default_keys} is 684@samp{[etype:]salt-type[:salt-string]}. @samp{etype} is the encryption 685type (des-cbc-crc, arcfour-hmac-md5, aes256-cts-hmac-sha1-96), 686@code{salt-type} is the type of salt (pw-salt or afs3-salt), and the 687salt-string is the string that will be used as salt (remember that if 688the salt is appended/prepended, the empty salt "" is the same thing as 689no salt at all). 690 691Common types of salting include 692 693@itemize @bullet 694@item @code{v4} (or @code{des:pw-salt:}) 695 696The Kerberos 4 salting is using no salt at all. Reason there is colon 697at the end of the salt string is that it makes the salt the empty 698string (same as no salt). 699 700@item @code{v5} (or @code{pw-salt}) 701 702@code{pw-salt} uses the default salt for each encryption type is 703specified for. If the encryption type @samp{etype} isn't given, all 704default encryption will be used. 705 706@item @code{afs3-salt} 707 708@code{afs3-salt} is the salt that is used with Transarc kaserver. It's 709the cell name appended to the password. 710 711@end itemize 712 713@node Credential cache server - KCM, Cross realm, Encryption types and salting, Setting up a realm 714@section Credential cache server - KCM 715@cindex KCM 716@cindex Credential cache server 717 718When KCM running is easy for users to switch between different 719kerberos principals using @file{kswitch} or built in support in 720application, like OpenSSH's GSSAPIClientIdentity. 721 722Other advantages are that there is the long term credentials are not 723written to disk and on reboot the credential is removed when kcm 724process stopps running. 725 726Configure the system startup script to start the kcm process, 727@file{/usr/heimdal/libexec/kcm} and then configure the system to use kcm in @file{krb5.conf}. 728 729@example 730[libdefaults] 731 default_cc_type = KCM 732@end example 733 734Now when you run @command{kinit} it doesn't overwrite your existing 735credentials but rather just add them to the set of 736credentials. @command{klist -l} lists the credentials and the star 737marks the default credential. 738 739@example 740$ kinit lha@@KTH.SE 741lha@@KTH.SE's Password: 742$ klist -l 743 Name Cache name Expires 744lha@@KTH.SE 0 Nov 22 23:09:40 * 745lha@@SU.SE Initial default ccache Nov 22 14:14:24 746@end example 747 748When switching between credentials you can use @command{kswitch}. 749 750@example 751$ kswitch -i 752 Principal 7531 lha@@KTH.SE 7542 lha@@SU.SE 755Select number: 2 756@end example 757 758After switching, a new set of credentials are used as default. 759 760@example 761$ klist -l 762 Name Cache name Expires 763lha@@SU.SE Initial default ccache Nov 22 14:14:24 * 764lha@@KTH.SE 0 Nov 22 23:09:40 765@end example 766 767Som applications, like openssh with Simon Wilkinsons patch applied, 768support specifiying that credential to use. The example below will 769login to the host computer.kth.se using lha@@KTH.SE (not the current 770default credential). 771 772@example 773$ ssh \ 774 -o GSSAPIAuthentication=yes \ 775 -o GSSAPIKeyExchange=yes \ 776 -o GSSAPIClientIdentity=lha@@KTH.SE \ 777 computer.kth.se 778@end example 779 780 781 782@node Cross realm, Transit policy, Credential cache server - KCM, Setting up a realm 783@section Cross realm 784@cindex Cross realm 785 786Suppose you reside in the realm @samp{MY.REALM}, how do you 787authenticate to a server in @samp{OTHER.REALM}? Having valid tickets in 788@samp{MY.REALM} allows you to communicate with Kerberised services in that 789realm. However, the computer in the other realm does not have a secret 790key shared with the Kerberos server in your realm. 791 792It is possible to share keys between two realms that trust each 793other. When a client program, such as @command{telnet} or @command{ssh}, 794finds that the other computer is in a different realm, it will try to 795get a ticket granting ticket for that other realm, but from the local 796Kerberos server. With that ticket granting ticket, it will then obtain 797service tickets from the Kerberos server in the other realm. 798 799For a two way trust between @samp{MY.REALM} and @samp{OTHER.REALM} 800add the following principals to each realm. The principals should be 801@samp{krbtgt/OTHER.REALM@@MY.REALM} and 802@samp{krbtgt/MY.REALM@@OTHER.REALM} in @samp{MY.REALM}, and 803@samp{krbtgt/MY.REALM@@OTHER.REALM} and 804@samp{krbtgt/OTHER.REALM@@MY.REALM}in @samp{OTHER.REALM}. 805 806In Kerberos 5 the trust can be configured to be one way. So that 807users from @samp{MY.REALM} can authenticate to services in 808@samp{OTHER.REALM}, but not the opposite. In the example above, the 809@samp{krbtgt/MY.REALM@@OTHER.REALM} then should be removed. 810 811The two principals must have the same key, key version number, and the 812same set of encryption types. Remember to transfer the two keys in a 813safe manner. 814 815@example 816vr$ klist 817Credentials cache: FILE:/tmp/krb5cc_913.console 818 Principal: lha@@E.KTH.SE 819 820 Issued Expires Principal 821May 3 13:55:52 May 3 23:55:54 krbtgt/E.KTH.SE@@E.KTH.SE 822 823vr$ telnet -l lha hummel.it.su.se 824Trying 2001:6b0:5:1095:250:fcff:fe24:dbf... 825Connected to hummel.it.su.se. 826Escape character is '^]'. 827Waiting for encryption to be negotiated... 828[ Trying mutual KERBEROS5 (host/hummel.it.su.se@@SU.SE)... ] 829[ Kerberos V5 accepts you as ``lha@@E.KTH.SE'' ] 830Encryption negotiated. 831Last login: Sat May 3 14:11:47 from vr.l.nxs.se 832hummel$ exit 833 834vr$ klist 835Credentials cache: FILE:/tmp/krb5cc_913.console 836 Principal: lha@@E.KTH.SE 837 838 Issued Expires Principal 839May 3 13:55:52 May 3 23:55:54 krbtgt/E.KTH.SE@@E.KTH.SE 840May 3 13:55:56 May 3 23:55:54 krbtgt/SU.SE@@E.KTH.SE 841May 3 14:10:54 May 3 23:55:54 host/hummel.it.su.se@@SU.SE 842 843@end example 844 845@node Transit policy, Setting up DNS, Cross realm, Setting up a realm 846@section Transit policy 847@cindex Transit policy 848 849Under some circumstances, you may not wish to set up direct 850cross-realm trust with every realm to which you wish to authenticate 851or from which you wish to accept authentications. Kerberos supports 852multi-hop cross-realm trust where a client principal in realm A 853authenticates to a service in realm C through a realm B with which 854both A and C have cross-realm trust relationships. In this situation, 855A and C need not set up cross-realm principals between each other. 856 857If you want to use cross-realm authentication through an intermediate 858realm, it must be explicitly allowed by either the KDCs for the realm 859to which the client is authenticating (in this case, realm C), or the 860server receiving the request. This is done in @file{krb5.conf} in the 861@code{[capaths]} section. 862 863In addition, the client in realm A need to be configured to know how 864to reach realm C via realm B. This can be done either on the client or 865via KDC configuration in the KDC for realm A. 866 867@subsection Allowing cross-realm transits 868 869When the ticket transits through a realm to another realm, the 870destination realm adds its peer to the "transited-realms" field in the 871ticket. The field is unordered, since there is no way to know if know 872if one of the transited-realms changed the order of the list. For the 873authentication to be accepted by the final destination realm, all of 874the transited realms must be listed as trusted in the @code{[capaths]} 875configuration, either in the KDC for the destination realm or on the 876server receiving the authentication. 877 878The syntax for @code{[capaths]} section is: 879 880@example 881[capaths] 882 CLIENT-REALM = @{ 883 SERVER-REALM = PERMITTED-CROSS-REALMS ... 884 @} 885@end example 886 887In the following example, the realm @code{STACKEN.KTH.SE} only has 888direct cross-realm set up with @code{KTH.SE}. @code{KTH.SE} has 889direct cross-realm set up with @code{STACKEN.KTH.SE} and @code{SU.SE}. 890@code{DSV.SU.SE} only has direct cross-realm set up with @code{SU.SE}. 891The goal is to allow principals in the @code{DSV.SU.SE} or 892@code{SU.SE} realms to authenticate to services in 893@code{STACKEN.KTH.SE}. This is done with the following 894@code{[capaths]} entry on either the server accepting authentication 895or on the KDC for @code{STACKEN.KTH.SE}. 896 897@example 898[capaths] 899 SU.SE = @{ 900 STACKEN.KTH.SE = KTH.SE 901 @} 902 DSV.SU.SE = @{ 903 STACKEN.KTH.SE = SU.SE KTH.SE 904 @} 905@end example 906 907The first entry allows cross-realm authentication from clients in 908@code{SU.SE} transiting through @code{KTH.SE} to 909@code{STACKEN.KTH.SE}. The second entry allows cross-realm 910authentication from clients in @code{DSV.SU.SE} transiting through 911both @code{SU.SE} and @code{KTH.SE} to @code{STACKEN.KTH.SE}. 912 913Be careful of which realm goes where; it's easy to put realms in the 914wrong place. The block is tagged with the client realm (the realm of 915the principal authenticating), and the realm before the equal sign is 916the final destination realm: the realm to which the client is 917authenticating. After the equal sign go all the realms that the 918client transits through. 919 920The order of the @code{PERMITTED-CROSS-REALMS} is not important when 921doing transit cross realm verification. 922 923@subsection Configuring client cross-realm transits 924 925The @code{[capaths]} section is also used for another purpose: to tell 926clients which realm to transit through to reach a realm with which 927their local realm does not have cross-realm trust. This can be done 928by either putting a @code{[capaths]} entry in the configuration of the 929client or by putting the entry in the configuration of the KDC for the 930client's local realm. In the latter case, the KDC will then hand back 931a referral to the client when the client requests a cross-realm ticket 932to the destination realm, telling the client to try to go through an 933intermediate realm. 934 935For client configuration, the order of @code{PERMITTED-CROSS-REALMS} 936is significant, since only the first realm in this section (after the 937equal sign) is used by the client. 938 939For example, again consider the @code{[capaths]} entry above for the 940case of a client in the @code{SU.SE} realm, and assume that the client 941or the @code{SU.SE} KDC has that @code{[capaths]} entry. If the 942client attempts to authenticate to a service in the 943@code{STACKEN.KTH.SE} realm, that entry says to first authenticate 944cross-realm to the @code{KTH.SE} realm (the first realm listed in the 945@code{PERMITTED-CROSS-REALMS} section), and then from there to 946@code{STACKEN.KTH.SE}. 947 948Each entry in @code{[capaths]} can only give the next hop, since only 949the first realm in @code{PERMITTED-CROSS-REALMS} is used. If, for 950instance, a client in @code{DSV.SU.SE} had a @code{[capaths]} 951configuration as above but without the first block for @code{SU.SE}, 952they would not be able to reach @code{STACKEN.KTH.SE}. They would get 953as far as @code{SU.SE} based on the @code{DSV.SU.SE} entry in 954@code{[capaths]} and then attempt to go directly from there to 955@code{STACKEN.KTH.SE} and get stuck (unless, of course, the 956@code{SU.SE} KDC had the additional entry required to tell the client 957to go through @code{KTH.SE}). 958 959@subsection Active Directory forest example 960 961One common place where a @code{[capaths]} configuration is desirable 962is with Windows Active Directory forests. One common Active Directory 963configuration is to have one top-level Active Directory realm but then 964divide systems, services, and users into child realms (perhaps based 965on organizational unit). One generally establishes cross-realm trust 966only with the top-level realm, and then uses transit policy to permit 967authentications to and from the child realms. 968 969For example, suppose an organization has a Heimdal realm 970@code{EXAMPLE.COM}, a Windows Active Directory realm 971@code{WIN.EXAMPLE.COM}, and then child Active Directory realms 972@code{ENGR.WIN.EXAMPLE.COM} and @code{SALES.WIN.EXAMPLE.COM}. The 973goal is to allow users in any of these realms to authenticate to 974services in any of these realms. The @code{EXAMPLE.COM} KDC (and 975possibly client) configuration should therefore contain a 976@code{[capaths]} section as follows: 977 978@example 979[capaths] 980 ENGR.WIN.EXAMPLE.COM = @{ 981 EXAMPLE.COM = WIN.EXAMPLE.COM 982 @} 983 SALES.WIN.EXAMPLE.COM = @{ 984 EXAMPLE.COM = WIN.EXAMPLE.COM 985 @} 986 EXAMPLE.COM = @{ 987 ENGR.WIN.EXAMPLE.COM = WIN.EXAMPLE.COM 988 SALES.WIN.EXAMPLE.COM = WIN.EXAMPLE.COM 989 @} 990@end example 991 992The first two blocks allow clients in the @code{ENGR.WIN.EXAMPLE.COM} 993and @code{SALES.WIN.EXAMPLE.COM} realms to authenticate to services in 994the @code{EXAMPLE.COM} realm. The third block tells the client (or 995tells the KDC to tell the client via referrals) to transit through 996@code{WIN.EXAMPLE.COM} to reach these realms. Both sides of the 997configuration are needed for bi-directional transited cross-realm 998authentication. 999 1000@c To test the cross realm configuration, use: 1001@c kmumble transit-check client server transit-realms ... 1002 1003@node Setting up DNS, Using LDAP to store the database, Transit policy, Setting up a realm 1004@section Setting up DNS 1005@cindex Setting up DNS 1006 1007@subsection Using DNS to find KDC 1008 1009If there is information about where to find the KDC or kadmind for a 1010realm in the @file{krb5.conf} for a realm, that information will be 1011preferred, and DNS will not be queried. 1012 1013Heimdal will try to use DNS to find the KDCs for a realm. First it 1014will try to find a @code{SRV} resource record (RR) for the realm. If no 1015SRV RRs are found, it will fall back to looking for an @code{A} RR for 1016a machine named kerberos.REALM, and then kerberos-1.REALM, etc 1017 1018Adding this information to DNS minimises the client configuration (in 1019the common case, resulting in no configuration needed) and allows the 1020system administrator to change the number of KDCs and on what machines 1021they are running without caring about clients. 1022 1023The downside of using DNS is that the client might be fooled to use the 1024wrong server if someone fakes DNS replies/data, but storing the IP 1025addresses of the KDC on all the clients makes it very hard to change 1026the infrastructure. 1027 1028An example of the configuration for the realm @code{EXAMPLE.COM}: 1029 1030@example 1031 1032$ORIGIN example.com. 1033_kerberos._tcp SRV 10 1 88 kerberos.example.com. 1034_kerberos._udp SRV 10 1 88 kerberos.example.com. 1035_kerberos._tcp SRV 10 1 88 kerberos-1.example.com. 1036_kerberos._udp SRV 10 1 88 kerberos-1.example.com. 1037_kpasswd._udp SRV 10 1 464 kerberos.example.com. 1038_kerberos-adm._tcp SRV 10 1 749 kerberos.example.com. 1039 1040@end example 1041 1042More information about DNS SRV resource records can be found in 1043RFC-2782 (A DNS RR for specifying the location of services (DNS SRV)). 1044 1045@subsection Using DNS to map hostname to Kerberos realm 1046 1047Heimdal also supports a way to lookup a realm from a hostname. This to 1048minimise configuration needed on clients. Using this has the drawback 1049that clients can be redirected by an attacker to realms within the 1050same cross realm trust and made to believe they are talking to the 1051right server (since Kerberos authentication will succeed). 1052 1053An example configuration that informs clients that for the realms 1054it.example.com and srv.example.com, they should use the realm 1055EXAMPLE.COM: 1056 1057@example 1058 1059$ORIGIN example.com. 1060_kerberos.it TXT "EXAMPLE.COM" 1061_kerberos.srv TXT "EXAMPLE.COM" 1062 1063@end example 1064 1065@node Using LDAP to store the database, Providing Kerberos credentials to servers and programs, Setting up DNS, Setting up a realm 1066@section Using LDAP to store the database 1067@cindex Using the LDAP backend 1068 1069This document describes how to install the LDAP backend for 1070Heimdal. Note that before attempting to configure such an 1071installation, you should be aware of the implications of storing 1072private information (such as users' keys) in a directory service 1073primarily designed for public information. Nonetheless, with a 1074suitable authorisation policy, it is possible to set this up in a 1075secure fashion. A knowledge of LDAP, Kerberos, and C is necessary to 1076install this backend. The HDB schema was devised by Leif Johansson. 1077 1078This assumes, OpenLDAP 2.3 or later. 1079 1080Requirements: 1081 1082@itemize @bullet 1083 1084@item 1085A current release of Heimdal, configured with 1086@code{--with-openldap=/usr/local} (adjust according to where you have 1087installed OpenLDAP). 1088 1089You can verify that you manage to configure LDAP support by running 1090@file{kdc --builtin-hdb}, and checking that @samp{ldap:} is one entry 1091in the list. 1092 1093Its also possible to configure the ldap backend as a shared module, 1094see option --hdb-openldap-module to configure. 1095 1096@item 1097Configure OpenLDAP with @kbd{--enable-local} to enable the local transport. 1098 1099@item 1100Add the hdb schema to the LDAP server, it's included in the source-tree 1101in @file{lib/hdb/hdb.schema}. Example from slapd.conf: 1102 1103@example 1104include /usr/local/etc/openldap/schema/hdb.schema 1105@end example 1106 1107@item 1108Configure the LDAP server ACLs to accept writes from clients over the 1109local transport. For example: 1110 1111@example 1112access to * 1113 by dn.exact="uid=heimdal,dc=services,dc=example,dc=com" write 1114 ... 1115 1116authz-regexp "gidNumber=.*\\\+uidNumber=0,cn=peercred,cn=external,cn=auth'' 1117 "uid=heimdal,dc=services,dc=example,dc=com" 1118 1119@end example 1120 1121The sasl-regexp is for mapping between the SASL/EXTERNAL and a user in 1122a tree. The user that the key is mapped to should be have a 1123krb5Principal aux object with krb5PrincipalName set so that the 1124``creator'' and ``modifier'' is right in @file{kadmin}. 1125 1126Another option is to create an admins group and add the dn to that 1127group. 1128 1129Since Heimdal talks to the LDAP server over a UNIX domain socket, and 1130uses external sasl authentication, it's not possible to require 1131security layer quality (ssf in cyrus-sasl lingo). So that requirement 1132has to be turned off in OpenLDAP @command{slapd} configuration file 1133@file{slapd.conf}. 1134 1135@example 1136sasl-secprops minssf=0 1137@end example 1138 1139@item 1140 1141Start @command{slapd} with the local listener (as well as the default TCP/IP 1142listener on port 389) as follows: 1143 1144@example 1145 slapd -h "ldapi:/// ldap:///" 1146@end example 1147 1148Note: These is a bug in @command{slapd} where it appears to corrupt the krb5Key 1149binary attribute on shutdown. This may be related to our use of the V3 1150schema definition syntax instead of the old UMich-style, V2 syntax. 1151 1152@item 1153You should specify the distinguished name under which your 1154principals will be stored in @file{krb5.conf}. Also you need to 1155enter the path to the kadmin acl file: 1156 1157 1158@example 1159[kdc] 1160 database = @{ 1161 dbname = ldap:ou=KerberosPrincipals,dc=example,dc=com 1162 hdb-ldap-structural-object = inetOrgPerson 1163 acl_file = /path/to/kadmind.acl 1164 mkey_file = /path/to/mkey 1165 @} 1166@end example 1167 1168@samp{mkey_file} can be excluded if you feel that you trust your ldap 1169directory to have the raw keys inside it. The 1170hdb-ldap-structural-object is not necessary if you do not need Samba 1171comatibility. 1172 1173 1174 1175@item 1176Once you have built Heimdal and started the LDAP server, run kadmin 1177(as usual) to initialise the database. Note that the instructions for 1178stashing a master key are as per any Heimdal installation. 1179 1180@example 1181kdc# kadmin -l 1182kadmin> init EXAMPLE.COM 1183Realm max ticket life [unlimited]: 1184Realm max renewable ticket life [unlimited]: 1185kadmin> add lukeh 1186Max ticket life [1 day]: 1187Max renewable life [1 week]: 1188Principal expiration time [never]: 1189Password expiration time [never]: 1190Attributes []: 1191lukeh@@EXAMPLE.COM's Password: 1192Verifying password - lukeh@@EXAMPLE.COM's Password: 1193kadmin> exit 1194@end example 1195 1196Verify that the principal database has indeed been stored in the 1197directory with the following command: 1198 1199@example 1200kdc# ldapsearch -L -h localhost -D cn=manager \ 1201 -w secret -b ou=KerberosPrincipals,dc=example,dc=com \ 1202 'objectclass=krb5KDCEntry' 1203@end example 1204 1205@item 1206Now consider adding indexes to the database to speed up the access, at 1207least theses should be added to slapd.conf. 1208 1209@example 1210index objectClass eq 1211index cn eq,sub,pres 1212index uid eq,sub,pres 1213index displayName eq,sub,pres 1214index krb5PrincipalName eq 1215@end example 1216 1217@end itemize 1218 1219@subsection smbk5pwd overlay 1220 1221The smbk5pwd overlay, updates the krb5Key and krb5KeyVersionNumber 1222appropriately when it receives an LDAP Password change Extended 1223Operation: 1224 1225@url{http://www.openldap.org/devel/cvsweb.cgi/contrib/slapd-modules/smbk5pwd/README?hideattic=1&sortbydate=0} 1226 1227@subsection Troubleshooting guide 1228 1229@url{https://sec.miljovern.no/bin/view/Info/TroubleshootingGuide} 1230 1231 1232@subsection Using Samba LDAP password database 1233@cindex Samba 1234 1235@c @node Using Samba LDAP password database, Providing Kerberos credentials to servers and programs, Using LDAP to store the database, Setting up a realm 1236@c @section Using Samba LDAP password database 1237 1238The Samba domain and the Kerberos realm can have different names since 1239arcfour's string to key functions principal/realm independent. So now 1240will be your first and only chance name your Kerberos realm without 1241needing to deal with old configuration files. 1242 1243First, you should set up Samba and get that working with LDAP backend. 1244 1245Now you can proceed as in @xref{Using LDAP to store the database}. 1246Heimdal will pick up the Samba LDAP entries if they are in the same 1247search space as the Kerberos entries. 1248 1249@node Providing Kerberos credentials to servers and programs, Setting up PK-INIT, Using LDAP to store the database, Setting up a realm 1250@section Providing Kerberos credentials to servers and programs 1251 1252Some services require Kerberos credentials when they start to make 1253connections to other services or need to use them when they have started. 1254 1255The easiest way to get tickets for a service is to store the key in a 1256keytab. Both ktutil get and kadmin ext can be used to get a 1257keytab. ktutil get is better in that way it changes the key/password 1258for the user. This is also the problem with ktutil. If ktutil is used 1259for the same service principal on several hosts, they keytab will only 1260be useful on the last host. In that case, run the extract command on 1261one host and then securely copy the keytab around to all other hosts 1262that need it. 1263 1264@example 1265host# ktutil -k /etc/krb5-service.keytab \ 1266 get -p lha/admin@@EXAMPLE.ORG service-principal@@EXAMPLE.ORG 1267lha/admin@@EXAMPLE.ORG's Password: 1268@end example 1269 1270To get a Kerberos credential file for the service, use kinit in the 1271@kbd{--keytab} mode. This will not ask for a password but instead fetch the 1272key from the keytab. 1273 1274@example 1275service@@host$ kinit --cache=/var/run/service_krb5_cache \ 1276 --keytab=/etc/krb5-service.keytab \ 1277 service-principal@@EXAMPLE.ORG 1278@end example 1279 1280Long running services might need credentials longer then the 1281expiration time of the tickets. kinit can run in a mode that refreshes 1282the tickets before they expire. This is useful for services that write 1283into AFS and other distributed file systems using Kerberos. To run the 1284long running script, just append the program and arguments (if any) 1285after the principal. kinit will stop refreshing credentials and remove 1286the credentials when the script-to-start-service exits. 1287 1288@example 1289service@@host$ kinit --cache=/var/run/service_krb5_cache \ 1290 --keytab=/etc/krb5-service.keytab \ 1291 service-principal@@EXAMPLE.ORG \ 1292 script-to-start-service argument1 argument2 1293@end example 1294 1295 1296@node Setting up PK-INIT, Debugging Kerberos problems, Providing Kerberos credentials to servers and programs, Setting up a realm 1297@section Setting up PK-INIT 1298 1299PK-INIT leverages an existing PKI (public key infrastructure), using 1300certificates to get the initial ticket (usually the krbtgt 1301ticket-granting ticket). 1302 1303To use PK-INIT you must first have a PKI. If you don't have one, it is 1304time to create it. You should first read the whole chapter of the 1305document to see the requirements imposed on the CA software. 1306 1307A mapping between the PKI certificate and what principals that 1308certificate is allowed to use must exist. There are several ways to do 1309this. The administrator can use a configuration file, store the 1310principal in the SubjectAltName extension of the certificate, or store 1311the mapping in the principals entry in the kerberos database. 1312 1313@section Certificates 1314 1315This section documents the requirements on the KDC and client 1316certificates and the format used in the id-pkinit-san OtherName 1317extention. 1318 1319@subsection KDC certificate 1320 1321The certificate for the KDC has serveral requirements. 1322 1323First, the certificate should have an Extended Key Usage (EKU) 1324id-pkkdcekuoid (1.3.6.1.5.2.3.5) set. Second, there must be a 1325subjectAltName otherName using OID id-pkinit-san (1.3.6.1.5.2.2) in 1326the type field and a DER encoded KRB5PrincipalName that matches the 1327name of the TGS of the target realm. Also, if the certificate has a 1328nameConstraints extention with a Generalname with dNSName or iPAdress, 1329it must match the hostname or adress of the KDC. 1330 1331The client is not required by the standard to check the server 1332certificate for this information if the client has external 1333information confirming which certificate the KDC is supposed to be 1334using. However, adding this information to the KDC certificate removes 1335the need to specially configure the client to recognize the KDC 1336certificate. 1337 1338Remember that if the client would accept any certificate as the KDC's 1339certificate, the client could be fooled into trusting something that 1340isn't a KDC and thus expose the user to giving away information (like 1341a password or other private information) that it is supposed to keep 1342secret. 1343 1344@subsection Client certificate 1345 1346The client certificate may need to have a EKU id-pkekuoid 1347(1.3.6.1.5.2.3.4) set depending on the certifiate on the KDC. 1348 1349It possible to store the principal (if allowed by the KDC) in the 1350certificate and thus delegate responsibility to do the mapping between 1351certificates and principals to the CA. 1352 1353This behavior is controlled by KDC configuration option: 1354 1355@example 1356[kdc] 1357 pkinit_principal_in_certificate = yes 1358@end example 1359 1360@subsubsection Using KRB5PrincipalName in id-pkinit-san 1361 1362The OtherName extention in the GeneralName is used to do the mapping 1363between certificate and principal. For the KDC certificate, this 1364stores the krbtgt principal name for that KDC. For the client 1365certificate, this stores the principal for which that certificate is 1366allowed to get tickets. 1367 1368The principal is stored in a SubjectAltName in the certificate using 1369OtherName. The OID in the type is id-pkinit-san. 1370 1371@example 1372id-pkinit-san OBJECT IDENTIFIER ::= @{ iso (1) org (3) dod (6) 1373internet (1) security (5) kerberosv5 (2) 2 @} 1374@end example 1375 1376The data part of the OtherName is filled with the following DER 1377encoded ASN.1 structure: 1378 1379@example 1380KRB5PrincipalName ::= SEQUENCE @{ 1381 realm [0] Realm, 1382 principalName [1] PrincipalName 1383@} 1384@end example 1385 1386where Realm and PrincipalName is defined by the Kerberos ASN.1 1387specification. 1388 1389@section Naming certificate using hx509 1390 1391hx509 is the X.509 software used in Heimdal to handle 1392certificates. hx509 supports several different syntaxes for specifying 1393certificate files or formats. Several formats may be used: PEM, 1394certificates embedded in PKCS#12 files, certificates embedded in 1395PKCS#11 devices, and raw DER encoded certificates. 1396 1397Those formats may be specified as follows: 1398 1399@table @asis 1400 1401@item DIR: 1402 1403DIR specifies a directory which contains certificates in the DER or 1404PEM format. 1405 1406The main feature of DIR is that the directory is read on demand when 1407iterating over certificates. This allows applications, in some 1408situations, to avoid having to store all certificates in memory. It's 1409very useful for tests that iterate over large numbers of certificates. 1410 1411The syntax is: 1412 1413@example 1414DIR:/path/to/der/files 1415@end example 1416 1417@item FILE: 1418 1419FILE: specifies a file that contains a certificate or private key. 1420The file can be either a PEM (openssl) file or a raw DER encoded 1421certificate. If it's a PEM file, it can contain several keys and 1422certificates and the code will try to match the private key and 1423certificate together. Multiple files may be specified, separated by 1424commas. 1425 1426It's useful to have one PEM file that contains all the trust anchors. 1427 1428The syntax is: 1429 1430@example 1431FILE:certificate.pem,private-key.key,other-cert.pem,.... 1432@end example 1433 1434@item PKCS11: 1435 1436PKCS11: is used to handle smartcards via PKCS#11 drivers, such as 1437soft-token, opensc, or muscle. The argument specifies a shared object 1438that implements the PKCS#11 API. The default is to use all slots on 1439the device/token. 1440 1441The syntax is: 1442 1443@example 1444PKCS11:shared-object.so 1445@end example 1446 1447@item PKCS12: 1448 1449PKCS12: is used to handle PKCS#12 files. PKCS#12 files commonly have 1450the extension pfx or p12. 1451 1452The syntax is: 1453 1454@example 1455PKCS12:/path/to/file.pfx 1456@end example 1457 1458@end table 1459 1460@section Configure the Kerberos software 1461 1462First configure the client's trust anchors and what parameters to 1463verify. See the subsections below for how to do that. Then, you can 1464use kinit to get yourself tickets. For example: 1465 1466@example 1467$ kinit -C FILE:$HOME/.certs/lha.crt,$HOME/.certs/lha.key lha@@EXAMPLE.ORG 1468Enter your private key passphrase: 1469: lha@@nutcracker ; klist 1470Credentials cache: FILE:/tmp/krb5cc_19100a 1471 Principal: lha@@EXAMPLE.ORG 1472 1473 Issued Expires Principal 1474Apr 20 02:08:08 Apr 20 12:08:08 krbtgt/EXAMPLE.ORG@@EXAMPLE.ORG 1475@end example 1476 1477Using PKCS#11 it can look like this instead: 1478 1479@example 1480$ kinit -C PKCS11:/usr/heimdal/lib/hx509.so lha@@EXAMPLE.ORG 1481PIN code for SoftToken (slot): 1482$ klist 1483Credentials cache: API:4 1484 Principal: lha@@EXAMPLE.ORG 1485 1486 Issued Expires Principal 1487Mar 26 23:40:10 Mar 27 09:40:10 krbtgt/EXAMPLE.ORG@@EXAMPLE.ORG 1488@end example 1489 1490TODO: Write about the KDC. 1491 1492@section Configure the client 1493 1494@example 1495[appdefaults] 1496 pkinit_anchors = FILE:/path/to/trust-anchors.pem 1497 1498[realms] 1499 EXAMPLE.COM = @{ 1500 pkinit_require_eku = true 1501 pkinit_require_krbtgt_otherName = true 1502 pkinit_win2k = no 1503 pkinit_win2k_require_binding = yes 1504 @} 1505 1506@end example 1507 1508@section Configure the KDC 1509 1510@example 1511[kdc] 1512 enable-pkinit = yes 1513 pkinit_identity = FILE:/secure/kdc.crt,/secure/kdc.key 1514 pkinit_anchors = FILE:/path/to/trust-anchors.pem 1515 pkinit_pool = PKCS12:/path/to/useful-intermediate-certs.pfx 1516 pkinit_pool = FILE:/path/to/other-useful-intermediate-certs.pem 1517 pkinit_allow_proxy_certificate = no 1518 pkinit_win2k_require_binding = yes 1519 pkinit_principal_in_certificate = no 1520@end example 1521 1522@subsection Using pki-mapping file 1523 1524Note that the file name is space sensitive. 1525 1526@example 1527# cat /var/heimdal/pki-mapping 1528# comments starts with # 1529lha@@EXAMPLE.ORG:C=SE,O=Stockholm universitet,CN=Love,UID=lha 1530lha@@EXAMPLE.ORG:CN=Love,UID=lha 1531@end example 1532 1533@subsection Using the Kerberos database 1534 1535@section Use hxtool to create certificates 1536 1537@subsection Generate certificates 1538 1539First, you need to generate a CA certificate. This example creates a 1540CA certificate that will be valid for 10 years. 1541 1542You need to change --subject in the command below to something 1543appropriate for your site. 1544 1545@example 1546hxtool issue-certificate \ 1547 --self-signed \ 1548 --issue-ca \ 1549 --generate-key=rsa \ 1550 --subject="CN=CA,DC=test,DC=h5l,DC=se" \ 1551 --lifetime=10years \ 1552 --certificate="FILE:ca.pem" 1553@end example 1554 1555The KDC needs to have a certificate, so generate a certificate of the 1556type ``pkinit-kdc'' and set the PK-INIT specifial SubjectAltName to the 1557name of the krbtgt of the realm. 1558 1559You need to change --subject and --pk-init-principal in the command 1560below to something appropriate for your site. 1561 1562@example 1563hxtool issue-certificate \ 1564 --ca-certificate=FILE:ca.pem \ 1565 --generate-key=rsa \ 1566 --type="pkinit-kdc" \ 1567 --pk-init-principal="krbtgt/TEST.H5L.SE@@TEST.H5L.SE" \ 1568 --subject="uid=kdc,DC=test,DC=h5l,DC=se" \ 1569 --certificate="FILE:kdc.pem" 1570@end example 1571 1572The users also needs to have certificates. For your first client, 1573generate a certificate of type ``pkinit-client''. The client doesn't 1574need to have the PK-INIT SubjectAltName set; you can have the Subject 1575DN in the ACL file (pki-mapping) instead. 1576 1577You need to change --subject and --pk-init-principal in the command 1578below to something appropriate for your site. You can omit 1579--pk-init-principal if you're going to use the ACL file instead. 1580 1581@example 1582hxtool issue-certificate \ 1583 --ca-certificate=FILE:ca.pem \ 1584 --generate-key=rsa \ 1585 --type="pkinit-client" \ 1586 --pk-init-principal="lha@@TEST.H5L.SE" \ 1587 --subject="uid=lha,DC=test,DC=h5l,DC=se" \ 1588 --certificate="FILE:user.pem" 1589@end example 1590 1591@subsection Validate the certificate 1592 1593hxtool also contains a tool that will validate certificates according 1594to rules from the PKIX document. These checks are not complete, but 1595they provide a good test of whether you got all of the basic bits 1596right in your certificates. 1597 1598@example 1599hxtool validate FILE:user.pem 1600@end example 1601 1602@section Use OpenSSL to create certificates 1603 1604This section tries to give the CA owners hints how to create 1605certificates using OpenSSL (or CA software based on OpenSSL). 1606 1607@subsection Using OpenSSL to create certificates with krb5PrincipalName 1608 1609To make OpenSSL create certificates with krb5PrincipalName, use an 1610@file{openssl.cnf} as described below. To see a complete example of 1611creating client and KDC certificates, see the test-data generation 1612script @file{lib/hx509/data/gen-req.sh} in the source-tree. The 1613certicates it creates are used to test the PK-INIT functionality in 1614@file{tests/kdc/check-kdc.in}. 1615 1616To use this example you have to use OpenSSL 0.9.8a or later. 1617 1618@example 1619 1620[user_certificate] 1621subjectAltName=otherName:1.3.6.1.5.2.2;SEQUENCE:princ_name 1622 1623[princ_name] 1624realm = EXP:0, GeneralString:MY.REALM 1625principal_name = EXP:1, SEQUENCE:principal_seq 1626 1627[principal_seq] 1628name_type = EXP:0, INTEGER:1 1629name_string = EXP:1, SEQUENCE:principals 1630 1631[principals] 1632princ1 = GeneralString:userid 1633 1634@end example 1635 1636Command usage: 1637 1638@example 1639openssl x509 -extensions user_certificate 1640openssl ca -extensions user_certificate 1641@end example 1642 1643 1644@c --- ms certificate 1645@c 1646@c [ new_oids ] 1647@c msCertificateTemplateName = 1.3.6.1.4.1.311.20.2 1648@c 1649@c 1650@c [ req_smartcard ] 1651@c keyUsage = digitalSignature, keyEncipherment 1652@c extendedKeyUsage = msSmartcardLogin, clientAuth 1653@c msCertificateTemplateName = ASN1:BMP:SmartcardLogon 1654@c subjectAltName = otherName:msUPN;UTF8:lukeh@dsg.padl.com 1655@c #subjectAltName = email:copy 1656 1657 1658@section Using PK-INIT with Windows 1659 1660@subsection Client configration 1661 1662Clients using a Windows KDC with PK-INIT need configuration since 1663windows uses pre-standard format and this can't be autodetected. 1664 1665The pkinit_win2k_require_binding option requires the reply for the KDC 1666to be of the new, secure, type that binds the request to 1667reply. Before, clients could fake the reply from the KDC. To use this 1668option you have to apply a fix from Microsoft. 1669 1670@example 1671[realms] 1672 MY.MS.REALM = @{ 1673 pkinit_win2k = yes 1674 pkinit_win2k_require_binding = no 1675 @} 1676@end example 1677 1678@subsection Certificates 1679 1680The client certificates need to have the extended keyusage ``Microsoft 1681Smartcardlogin'' (openssl has the OID shortname msSmartcardLogin). 1682 1683See Microsoft Knowledge Base Article - 281245 ``Guidelines for Enabling 1684Smart Card Logon with Third-Party Certification Authorities'' for a 1685more extensive description of how set setup an external CA so that it 1686includes all the information required to make a Windows KDC happy. 1687 1688@subsection Configure Windows 2000 CA 1689 1690To enable Microsoft Smartcardlogin for certificates in your Windows 16912000 CA, you want to look at Microsoft Knowledge Base Article - 313274 1692``HOW TO: Configure a Certification Authority to Issue Smart Card 1693Certificates in Windows''. 1694 1695@node Debugging Kerberos problems, , Setting up PK-INIT, Setting up a realm 1696@section Debugging Kerberos problems 1697 1698To debug Kerberos client and server problems you can enable debug 1699traceing by adding the following to @file{/etc/krb5,conf}. Note that the 1700trace logging is sparse at the moment, but will continue to improve. 1701 1702@example 1703[logging] 1704 libkrb5 = 0-/SYSLOG: 1705@end example 1706 1707 1708 1709 1710