File: k5start.pod

package info (click to toggle)
kstart 4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,884 kB
  • sloc: ansic: 5,937; sh: 4,785; perl: 2,130; makefile: 142
file content (496 lines) | stat: -rw-r--r-- 21,099 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
=for stopwords
-abFhLnPqstvx keytab username kinit LDAP aklog HUP ALRM KRB5CCNAME AFS PAG
init AKLOG kstart krenew afslog Bense Allbery Navid Golpayegani
forwardable proxiable designator Ctrl-C backoff FSFAP
SPDX-License-Identifier kafs keyring libkeyutils

=head1 NAME

k5start - Obtain and optionally keep active a Kerberos ticket

=head1 SYNOPSIS

B<k5start> [B<-abFhLnPqstvx>] [B<-c> I<child pid file>] [B<-f> I<keytab>]
    [B<-g> I<group>] [B<-H> I<minutes>] [B<-I> I<service instance>]
    [B<-i> I<client instance>] [B<-K> I<minutes>] [B<-k> I<ticket cache>]
    [B<-l> I<time string>] [B<-m> I<mode>] [B<-o> I<owner>]
    [B<-p> I<pid file>] [B<-r> I<service realm>] [B<-S> I<service name>]
    [B<-u> I<client principal>] [I<principal> [I<command> ...]]

B<k5start> B<-U> B<-f> I<keytab> [B<-abFhLnPqstvx>] [B<-c> I<child pid file>]
    [B<-g> I<group>] [B<-H> I<minutes>] [B<-I> I<service instance>]
    [B<-K> I<minutes>] [B<-k> I<ticket cache>] [B<-l> I<time string>]
    [B<-m> I<mode>] [B<-o> I<owner>] [B<-p> I<pid file>]
    [B<-r> I<service realm>] [B<-S> I<service name>] [I<command> ...]

=head1 DESCRIPTION

B<k5start> obtains and caches an initial Kerberos ticket-granting ticket
for a principal.  B<k5start> can be used as an alternative to B<kinit>,
but it is primarily intended to be used by programs that want to use a
keytab to obtain Kerberos credentials, such as a web server that needs to
authenticate to another service such as an LDAP server.

Normally, the principal for which to give tickets should be specified as
the first argument.  I<principal> may be either just a principal name
(including the optional instance) or a full principal and realm string.
The B<-u> and B<-i> options can be used as an alternative mechanism for
specifying the principal, but generally aren't as convenient.  If no
principal is given as either the first argument or the argument to the
B<-u> option, the client principal defaults to the Unix username of the
user running B<k5start> in the default local realm.

Optionally, a command may be given on the command line of B<k5start>.  If
so, that command is run after Kerberos authentication (and running
B<aklog> if desired), with the appropriate environment variables set to
point it to the right ticket cache.  B<k5start> will then continue
running, waking up periodically to refresh credentials slightly before
they would expire, until the command completes.  (The frequency with which
it wakes up to refresh credentials can still be controlled with the B<-K>
option.)  To run in this mode, the principal must either be specified as a
regular command-line argument or via the B<-U> option; the B<-u> and B<-i>
options may not be used.  Also, a keytab must be specified with B<-f> to
run a specific command.

The command will not be run using the shell, so if you want to use shell
metacharacters in the command with their special meaning, give C<sh -c
I<command>> as the command to run and quote I<command>.

If the command contains command-line options (like C<-c>), put -- on the
command line before the beginning of the command to tell B<k5start> to not
parse those options as its own.

When running a command, B<k5start> propagates HUP, TERM, INT, and QUIT
signals to the child process and does not exit when those signals are
received.  (If the propagated signal causes the child process to exit,
B<k5start> will then exit.)  This allows B<k5start> to react properly when
run under a command supervision system such as runit(8) or svscan(8) that
uses signals to control supervised commands, and to run interactive
commands that should receive Ctrl-C.

If a running B<k5start> receives an ALRM signal, it immediately refreshes
the ticket cache regardless of whether it is in danger of expiring.

If B<k5start> is run with a command or the B<-K> flag and the B<-x> flag
is not given, it will keep trying even if the initial authentication
fails.  It will retry the initial authentication immediately and then with
exponential backoff to once per minute, and keep trying until
authentication succeeds or it is killed.  The command, if any, will not be
started until authentication succeeds.

=head1 OPTIONS

=over 4

=item B<-a>

When run with either the B<-K> flag or a command, always renew tickets
each time B<k5start> wakes up.  Without this option, B<k5start> will only
try to renew a ticket as often as necessary to prevent the ticket from
expiring.  With this option, B<k5start> will renew tickets according to
the interval specified with the B<-K> flag.

This behavior probably should have been the default behavior of B<-K>.
The default was not changed to avoid changes for existing users, but for
new applications, consider always using B<-a> with B<-K>.

This option is important if another program is manipulating the ticket
cache that B<k5start> is using.  For example, if another program is
automatically renewing a ticket more frequently than B<k5start>, then
B<k5start> will never see a ticket that is close to expiring and will
therefore, by default, never try to renew the ticket.  This means that
B<k5start> will also never renew AFS tokens, even if the B<-t> option was
given, since B<k5start> only renews AFS tokens after it successfully
renews a ticket.  If this option is specified in such a situation,
B<k5start> will renew its ticket every time it checks the ticket, so AFS
tokens will be renewed.

This argument is only valid in combination with either B<-K> or a command
to run.

=item B<-b>

After starting, detach from the controlling terminal and run in the
background.  This option only makes sense in combination with B<-K> or a
command that B<k5start> will be running and can only be used if a keytab
is specified with F<-f>.  B<k5start> will not background itself until
after it has tried authenticating once, so that any initial errors will
be reported, but it will then redirect output to F</dev/null> and no
subsequent errors will be reported.

If this flag is given, B<k5start> will also change directories to C</>.
All paths (such as to a command to run or a PID file) should therefore be
given as absolute, not relative, paths.

If used in conjunction with a command to run, that command will also run
in the background and will also have its input and output redirected to
F</dev/null>.  It will have to report any errors via some other mechanism
for the errors to be seen.

Note that on Mac OS X, the default ticket cache type is per-session and
using the B<-b> flag will disassociate B<k5start> from the existing ticket
cache.  When using B<-b> in conjunction with B<-K> on Mac OS X, you
probably also want to use the B<-k> flag to specify a ticket cache file
and force the use of a file cache.

When using this option, consider also using B<-L> to report B<k5start>
errors to syslog.

=item B<-c> I<child pid file>

Save the process ID (PID) of the child process into I<child pid file>.
I<child pid file> is created if it doesn't exist and overwritten if it
does exist.  This option is only allowed when a command was given on the
command line and is most useful in conjunction with B<-b> to allow
management of the running child process.

Note that, when used with B<-b>, the PID file is written out after
B<k5start> is backgrounded and changes its working directory to F</>, so
relative paths for the PID file will be relative to F</> (probably not
what you want).

=item B<-F>

Do not get forwardable tickets even if the local configuration says to get
forwardable tickets by default.  Without this flag, B<k5start> does
whatever the library default is.

=item B<-f> I<keytab>

Authenticate using the keytab I<keytab> rather than asking for a
password.  A key for the client principal must be present in I<keytab>.

=item B<-g> I<group>

After creating the ticket cache, change its group ownership to I<group>,
which may be either the name of a group or a numeric group ID.  Ticket
caches are created with C<0600> permissions by default, so this will have
no useful effect unless used with B<-m>.

=item B<-H> I<minutes>

Check for a happy ticket, defined as one that has a remaining lifetime of
at least I<minutes> minutes.  If such a ticket is found, do not attempt
authentication.  Instead, just run the command (if one was specified) or
exit immediately with status 0 (if none was).  Otherwise, try to obtain a
new ticket and then run the command, if any.

If B<-H> is used with B<-t>, the external program will always be run even
if a ticket with a sufficient remaining lifetime was found.

If B<-H> is used with B<-K>, B<k5start> will not exit immediately.
Instead, the specified remaining lifetime will replace the default value
of two minutes, meaning that B<k5start> will ensure, each time it wakes
up, that the ticket has a remaining lifetime of the I<minutes> argument.
This is an alternative to B<-a> to ensure that tickets always have a
certain minimal amount of lifetime remaining.

=item B<-h>

Display a usage message and exit.

=item B<-I> I<service instance>

The instance portion of the service principal.  The default is the default
realm of the machine.  Note that unlike the client principal, a
non-default service principal must be specified with B<-I> and B<-S>; one
cannot provide the instance portion as part of the argument to B<-S>.

=item B<-i> I<client instance>

Specifies the instance portion of the principal.  This option doesn't make
sense except in combination with B<-u>.  Note that the instance can be
specified as part of I<username> through the normal convention of
appending a slash and then the instance, so one never has to use this
option.

=item B<-K> I<minutes>

Run in daemon mode to keep a ticket alive indefinitely.  The program
reawakens after I<minutes> minutes, checks if the ticket will expire
before or less than two minutes after the next scheduled check, and gets a
new ticket if needed.  (In other words, it ensures that the ticket will
always have a remaining lifetime of at least two minutes.)  If the B<-H>
flag is also given, the lifetime specified by it replaces the two minute
default.

If this option is not given but a command was given on the command line,
the default interval is 60 minutes (1 hour).

If an error occurs in refreshing the ticket cache, the wake-up interval
will be shortened to one minute and the operation retried at that interval
for as long as the error persists.

=item B<-k> I<ticket cache>

Use I<ticket cache> as the ticket cache rather than the contents of the
environment variable KRB5CCNAME or the library default.  I<ticket cache>
may be any ticket cache identifier recognized by the underlying Kerberos
libraries.  This generally supports a path to a file, with or without a
leading C<FILE:> string, but may also support other ticket cache types.

If any of B<-o>, B<-g>, or B<-m> are given, I<ticket cache> must be either
a simple path to a file or start with C<FILE:> or C<WRFILE:>.

=item B<-L>

Report messages to syslog as well as to standard output or standard error.
All messages will be logged with facility LOG_DAEMON.  Regular messages
that are displayed on standard output are logged with level LOG_NOTICE.
Errors that don't cause B<k5start> to terminate are logged with level
LOG_WARNING.  Fatal errors are logged with level LOG_ERR.

This is useful when debugging problems in combination with B<-b>.

=item B<-l> I<time string>

Set the ticket lifetime.  I<time string> should be in a format recognized
by the Kerberos libraries for specifying times, such as C<10h> (ten hours)
or C<10m> (ten minutes).  Known units are C<s>, C<m>, C<h>, and C<d>.  For
more information, see kinit(1).

=item B<-m> I<mode>

After creating the ticket cache, change its file permissions to I<mode>,
which must be a file mode in octal (C<640> or C<444>, for example).

Setting a I<mode> that does not allow B<k5start> to read or write to the
ticket cache will cause B<k5start> to fail and exit when using the B<-K>
option or running a command.

=item B<-n>

Ignored, present for option compatibility with the now-obsolete
B<k4start>.

=item B<-o> I<owner>

After creating the ticket cache, change its ownership to I<owner>, which
may be either the name of a user or a numeric user ID.  If I<owner> is
the name of a user and B<-g> was not also given, also change the group
ownership of the ticket cache to the default group for that user.

=item B<-P>

Do not get proxiable tickets even if the local configuration says to get
proxiable tickets by default.  Without this flag, B<k5start> does whatever
the library default is.

=item B<-p> I<pid file>

Save the process ID (PID) of the running B<k5start> process into I<pid
file>.  I<pid file> is created if it doesn't exist and overwritten if it
does exist.  This option is most useful in conjunction with B<-b> to allow
management of the running B<k5start> daemon.

Note that, when used with B<-b> the PID file is written out after
B<k5start> is backgrounded and changes its working directory to F</>, so
relative paths for the PID file will be relative to F</> (probably not
what you want).

=item B<-q>

Quiet.  Suppresses the printing of the initial banner message saying what
Kerberos principal tickets are being obtained for, and also suppresses the
password prompt when the B<-s> option is given.

=item B<-r> I<service realm>

The realm for the service principal.  This defaults to the default local
realm.

=item B<-S> I<service name>

Specifies the principal for which B<k5start> is getting a service ticket.
The default value is C<krbtgt>, to obtain a ticket-granting ticket.  This
option (along with B<-I>) may be used if one only needs access to a single
service.  Note that unlike the client principal, a non-default service
principal must be specified with both B<-S> and B<-I>; one cannot provide
the instance portion as part of the argument to B<-S>.

=item B<-s>

Read the password from standard input.  This bypasses the normal password
prompt, which means echo isn't suppressed and input isn't forced to be
from the controlling terminal.  Most uses of this option are a security
risk.  You normally want to use a keytab and the B<-f> option instead.

=item B<-t>

Run an external program after getting a ticket.  The intended use of this
is to run B<aklog> to get a token.  If the environment variable AKLOG (or
KINIT_PROG for backward compatibility) is set, it overrides the
compiled-in default.

If a command was given on the command line, B<k5start> will attempt to
isolate the AFS credentials for that command from the invoking process.
There are two possible ways in which this is done.

First, if B<k5start> has been built with AFS setpag() support and AFS is
available, B<k5start> will create a new PAG before running the external
program.

Otherwise, if either B<k5start> was not built with AFS setpag() support or
AFS is not available, but the Linux kafs module is available and
B<k5start> was built with libkeyutils support, it will create a new
session keyring and link it to the current user keyring before running the
external program.

If neither of these conditions are true, B<k5start> will run the external
program without doing any credential isolation, which may also affect the
credentials of the invoking process.

=item B<-U>

Rather than requiring the authentication principal be given on the command
line, read it from the keytab specified with B<-f>.  The principal will be
taken from the first entry in the keytab.  B<-f> must be specified if this
option is used.

When B<-U> is given, B<k5start> will not expect a principal name to be
given on the command line, and any arguments after the options will be
taken as a command to run.

=item B<-u> I<client principal>

This specifies the principal to obtain credentials as.  The entire
principal may be specified here, or alternatively just the first portion
may be specified with this flag and the instance specified with B<-i>.

Note that there's normally no reason to use this flag rather than simply
giving the principal on the command line as the first regular argument.

=item B<-v>

Be verbose.  This will print out a bit of additional information about
what is being attempted and what the results are.

=item B<-x>

Exit immediately on any error.  Normally, when running a command or when
run with the B<-K> option, B<k5start> keeps running even if it fails to
refresh the ticket cache and will try again at the next check interval.
With this option, B<k5start> will instead exit.

=back

=head1 EXIT STATUS

The program exits with status 0 if it successfully gets a ticket or has a
happy ticket (see B<-H>).  If B<k5start> runs aklog or some other program
B<k5start> returns the exit status of that program if it exits normally.
If the program exits abnormally due to a signal, B<k5start> will exit with
a status of 128 plus the signal number.  (This matches the behavior of
B<bash>.)

=head1 EXAMPLE

Use the F</etc/krb5.keytab> keytab to obtain a ticket granting ticket for
the principal host/example.com, putting the ticket cache in
F</tmp/service.tkt>.  The lifetime is 10 hours and the program wakes up
every 10 minutes to check if the ticket is about to expire.

    k5start -k /tmp/service.tkt -f /etc/krb5.keytab -K 10 -l 10h \
        host/example.com

Do the same, but using the default ticket cache and run the command
F</usr/local/bin/auth-backup>.  B<k5start> will continue running until the
command finishes.  If the initial authentication fails, keep trying, and
don't start the command until it succeeds.  This could be used during
system startup for a command that must have valid tickets before starting,
and tolerates having B<k5start> start before the network is completely set
up.

    k5start -f /etc/krb5.keytab -K 10 -l 10h host/example.com \
        /usr/local/bin/auth-backup

Shows the permissions of the temporary cache file created by B<k5start>:

    k5start -f /etc/krb5.keytab host/example.com \
        -- sh -c 'ls -l $KRB5CCNAME'

Notice the C<--> before the command to keep B<k5start> from parsing the
C<-c> as its own option.

Do the same thing, but determine the principal from the keytab:

    k5start -f /etc/krb5.keytab -U -- sh -c 'ls -l $KRB5CCNAME'

Note that no principal is given before the command.

Starts B<k5start> as a daemon using the Debian B<start-stop-daemon>
management program.  This is the sort of line that one could put into a
Debian init script:

    start-stop-daemon --start --pidfile /var/run/k5start.pid \
        --exec /usr/local/bin/k5start -- -b -p /var/run/k5start.pid \
        -f /etc/krb5.keytab host/example.com

This uses F</var/run/k5start.pid> as the PID file and obtains
host/example.com tickets from the system keytab file.  B<k5start> would
then be stopped with:

    start-stop-daemon --stop --pidfile /var/run/k5start.pid
    rm -f /var/run/k5start.pid

This code could be added to an init script for Apache, for example, to
start a B<k5start> process alongside Apache to manage its Kerberos
credentials.

=head1 ENVIRONMENT

If the environment variable AKLOG is set, its value will be used as the
program to run with B<-t> rather than the default complied into
B<k5start>.  If AKLOG is not set and KINIT_PROG is set, its value will be
used instead.  KINIT_PROG is honored for backward compatibility but its
use is not recommended due to its confusing name.

If no ticket file (with B<-k>) or command is specified on the command
line, B<k5start> will use the environment variable KRB5CCNAME to determine
the location of the the ticket granting ticket.  If either a command is
specified or the B<-k> option is used, KRB5CCNAME will be set to point to
the ticket file before running the B<aklog> program or any command given
on the command line.

=head1 FILES

The default ticket cache is determined by the underlying Kerberos
libraries.  The default path for aklog is determined at build time, and
will normally be whichever of B<aklog> or B<afslog> is found in the user's
path.

If a command is specified and B<-k> was not given, B<k5start> will create
a temporary ticket cache file of the form C</tmp/krb5cc_%d_%s> where %d is
the UID B<k5start> is running as and %s is a random string.

=head1 AUTHORS

B<k5start> was based on the k4start code written by Robert Morgan.  It was
ported to Kerberos v5 by Booker C. Bense.  Additional cleanup and current
maintenance are done by Russ Allbery <eagle@eyrie.org>.

Implementations of B<-b> and B<-p> and the example for a Debian init
script are based on code contributed by Navid Golpayegani.

=head1 COPYRIGHT AND LICENSE

Copyright 2015, 2021 Russ Allbery <eagle@eyrie.org>

Copyright 2002, 2004-2012, 2014 The Board of Trustees of the Leland
Stanford Junior University

Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice and
this notice are preserved.  This file is offered as-is, without any
warranty.

SPDX-License-Identifier: FSFAP

=head1 SEE ALSO

kinit(1), krenew(1)

This program is part of kstart.  The current version is available from its
web site at L<https://www.eyrie.org/~eagle/software/kstart/>.

=cut