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
|
=for stopwords
-abhiLstvx aklog AFS OpenSSH PAG HUP ALRM KRB5CCNAME AKLOG kstart afslog
Allbery Bense designator krenew Ctrl-C SIGHUP backoff FSFAP
SPDX-License-Identifier kafs keyring libkeyutils
=head1 NAME
krenew - Renew a Kerberos ticket
=head1 SYNOPSIS
B<krenew> [B<-abhiLstvx>] [B<-c> I<child pid file>] [B<-H> I<minutes>]
[B<-K> I<minutes>] [B<-k> I<ticket cache>] [B<-p> I<pid file>]
[I<command> ...]
=head1 DESCRIPTION
B<krenew> renews an existing renewable ticket. When run without any
arguments, it just attempts to renew the existing ticket-granting ticket
in the current ticket cache, equivalent to C<kinit -R>, but it can
optionally run a program like B<aklog> to refresh AFS tokens, can run as a
daemon and wake up periodically to renew the ticket cache, or can run a
specified command and keep renewing the ticket cache until the command
finishes (or renewal is no longer possible). If a command is specified,
B<krenew> by default wakes up every 60 minutes (1 hour) to check the
ticket cache.
If a command is given, B<krenew> makes a copy of the ticket cache and
creates a private ticket cache just for that command, thus isolating it
from later destruction of the original ticket cache. This allows krenew
to maintain authentication for a command even if, for example, the user
running the command logs out and OpenSSH destroys their original ticket
cache.
If a command is given, it 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 C<--> on the
command line before the beginning of the command to tell B<krenew> to not
parse those options as its own.
If B<krenew> is built with setpag() support and AFS tokens are requested
with the B<-t> option, it will put the command in a separate PAG before
obtaining AFS tokens so that they don't interfere with other processes on
the system.
When running a command, B<krenew> 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<krenew> will then exit.) This allows B<krenew> 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<krenew> receives an ALRM signal, it immediately refreshes
the ticket cache regardless of whether it is in danger of expiring.
=head1 OPTIONS
=over 4
=item B<-a>
When run with either the B<-K> flag or a command, always renew tickets
each time B<krenew> wakes up. Without this option, B<krenew> will only
try to renew a ticket as often as necessary to prevent the ticket from
expiring. With this option, B<krenew> 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<krenew> is using. For example, if another program is
automatically renewing a ticket more frequently than B<krenew>, then
B<krenew> 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<krenew> will also never renew AFS tokens, even if the B<-t> option was
given, since B<krenew> only renews AFS tokens after it successfully renews
a ticket. If this option is specified in such a situation, B<krenew> 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<krenew> will be running. B<krenew> will not background
itself until after it does the initial ticket renewal, 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<krenew> 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.
Use of this flag on Mac OS X without specifying a file-based ticket cache
by either using B<-k> or setting KRB5CCNAME will probably not do what you
want. Ticket caches on Mac OS X are, by default, per-session and with
B<-b> B<krenew> will detach itself from your existing ticket cache.
Instead, to renew the default ticket cache on Mac OS X, try something
like:
(krenew -K 60 &)
to run B<krenew> in the background but within the current session.
When using this option, consider also using B<-L> to report B<krenew>
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<krenew> 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<-H> I<minutes>
Only renew the ticket if it has a remaining lifetime of less than
I<minutes> minutes. If either the ticket already has a sufficiently long
remaining lifetime or renewal was successful, run the command (if one was
specified) or exit immediately with status 0 (if none was). Otherwise,
try to renew the ticket so that it will have a remaining lifetime of at
least I<minutes>, exit with an error if unsuccessful, and then run the
command, if any.
If B<-H> is used with B<-K>, B<krenew> will not exit immediately.
Instead, the specified remaining lifetime will replace the default value
of two minutes, meaning that B<krenew> 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>
Ignore errors in renewing the ticket and keep running. Normally,
B<krenew> exits as soon as the ticket cache either disappears or the
tickets run out of renewable lifetime. If this flag is given, it will
complain about the failure to standard error (unless B<-b> was given) but
continue running, waking up to try again after the next check interval
(see B<-K>). This is useful if some other process may recreate an expired
ticket cache and B<krenew> should stay around and act on that recreated
ticket cache once it's present.
If the initial ticket cache renew fails, B<krenew> will retry the renewal
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 cache renewal succeeds.
This flag is only useful in daemon mode or when a command was given.
=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 before the next scheduled check, and
renews the 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 that doesn't cause
B<krenew> to exit, 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.
=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<krenew> to terminate when run with B<-i> 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<-p> I<pid file>
Save the process ID (PID) of the running B<krenew> 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<krenew> daemon.
Note that, when used with B<-b> the PID file is written out after
B<krenew> 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<-s>
Normally, when B<krenew> exits abnormally while running a command (if, for
example, the ticket's renewable lifetime has expired), it leaves the
command running. If B<-s> is given, it will send a SIGHUP signal to the
command before exiting. This can be useful if it's pointless for the
command to keep running without Kerberos tickets.
=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<krenew> 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<krenew> has been built with AFS setpag() support and AFS is
available, B<krenew> will create a new PAG before running the external
program.
Otherwise, if either B<krenew> was not built with AFS setpag() support or
AFS is not available, but the Linux kafs module is available and B<krenew>
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<krenew> will run the external
program without doing any credential isolation, which may also affect the
credentials of the invoking process.
=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<krenew> keeps running even if it fails to
renew the ticket cache as long as the ticket cache still exists and
appears to be renewable. It tries again at the next check interval. With
this option, B<krenew> will instead exit.
=back
=head1 EXIT STATUS
The program normally exits with status 0 if it successfully renews a
ticket. If B<krenew> runs aklog or some other program B<krenew> returns
the exit status of that program if it exits normally. If the program
exits abnormally due to a signal, B<krenew> will exit with a status of 128
plus the signal number. (This matches the behavior of B<bash>.).
=head1 EXAMPLES
Renew the current ticket-granting ticket.
krenew
Wake up every ten minutes and check to see if the ticket cache needs
renewing. If it does, re-run B<aklog> as well.
krenew -K 10 -t
Run the program F</usr/local/bin/compute-job> in the background, checking
every hour to see if the ticket needs to be renewed (the default). Put
the PID of the B<krenew> job in F</var/run/compute.pid>. Obtain a new AFS
token each time the ticket has to be renewed.
krenew -b -t -p /var/run/compute.pid /usr/local/bin/compute-job
If you wanted to pass options to F</usr/local/bin/compute-job>, putting a
C<--> argument before it would be necessary to keep B<krenew> from
interpreting those options as its own.
If you want to redirect output to a file that requires authentication to
write to, you will need to do that redirection in a sub-shell. In other
words, the following command:
krenew -t compute-job > /afs/local/data/output
won't work if /afs/local/data/output requires an AFS token to write to.
The job, while running, will have an AFS token, but the output redirection
is done in the parent shell and doesn't benefit from B<krenew>. The above
should instead be written as:
krenew -t -- sh -c 'compute-job > /afs/local/data/output'
With this command, the shell doing the redirection will also be run under
B<krenew> and have the benefit of the AFS token it obtains.
=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<krenew>.
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<krenew> will use the environment variable KRB5CCNAME to determine
the location of the the ticket granting ticket. If 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.
=head1 AUTHORS
B<krenew> was written by Russ Allbery <eagle@eyrie.org>. It was based
heavily on B<k5start> by Booker C. Bense, which in turn was based on the
k4start code written by Robert Morgan.
=head1 COPYRIGHT AND LICENSE
Copyright 2015, 2021 Russ Allbery <eagle@eyrie.org>
Copyright 2006, 2008-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
k5start(1), kinit(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
|