-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhtgettoken.html
601 lines (401 loc) · 18.6 KB
/
htgettoken.html
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
<!-- Creator : groff version 1.22.2 -->
<!-- CreationDate: Thu Aug 17 12:51:42 2023 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>htgettoken</title>
</head>
<body>
<h1 align="center">htgettoken</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#OPTIONS">OPTIONS</a><br>
<a href="#ENVIRONMENT">ENVIRONMENT</a><br>
<a href="#EXAMPLES">EXAMPLES</a><br>
<a href="#EXIT VALUES">EXIT VALUES</a><br>
<a href="#AUTHOR">AUTHOR</a><br>
<a href="#COPYRIGHT">COPYRIGHT</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">htgettoken
− get OIDC bearer tokens by interacting with Hashicorp
vault</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>htgettoken</b>
[<i>OPTION</i>]...</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>htgettoken</b>
gets OIDC bearer tokens by interacting with a Hashicorp
vault server configured for retrieving and storing OIDC
refresh tokens. By default it attempts to authenticate first
using kerberos if it is available, next tries using
ssh-agent if it is available, and if neither enables reading
a bearer token then it uses OIDC authentication including
directing users to their web browsers to complete the
authentication. If that authentication is successful,
<b>htgettoken</b> accepts the refresh token (which is only
usable with the client secret known only to vault) and
stores it back into an oauth secrets path in vault. It then
reads back from the same secrets path to retrieve a bearer
access token and stores that in a file. A vault token is
also stored in a file so authentication doesn’t have
to be redone every time. By default the vault token lasts a
week.</p>
<h2>OPTIONS
<a name="OPTIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>−−version</b></p>
<p style="margin-left:22%;">Show the program’s
version number and exit.</p>
<p style="margin-left:11%;"><b>−h</b>, <b>−−help</b></p>
<p style="margin-left:22%;">Show a help message and
exit.</p>
<p style="margin-left:11%;"><b>−v</b>, <b>−−verbose</b></p>
<p style="margin-left:22%;">Show detailed progress reports
instead of the default concise reports. Reports are sent to
stdout unless <i>−−vaulttokenfile</i> is
/dev/stdout or <i>−−showbearerurl is enabled; in
those cases reports are sent to stderr.</i></p>
<p style="margin-left:11%;"><b>−d</b>, <b>−−debug</b></p>
<p style="margin-left:22%;">Shows debug reports. Implies
<i>−v</i>. Be aware that this writes a lot of
output.</p>
<p style="margin-left:11%;"><b>−q</b>, <b>−−quiet</b></p>
<p style="margin-left:22%;">Do not output any progress
reports or error messages.</p>
<p style="margin-left:11%;"><b>−s HostOrURL</b>, <b>−−optserver=HostOrURL</b></p>
<p style="margin-left:22%;">The server host name or URL
with default htgettoken options. If it is just a host name,
the URL read is</p>
<p style="margin-left:32%;">https://hostname/htgettokenopts.txt</p>
<p style="margin-left:22%;">otherwise the whole URL is
read. See also HTGETTOKENOPTS in the ENVIRONMENT section
below.</p>
<p style="margin-left:11%;"><b>−a HostOrURL</b>, <b>−−vaultserver=HostOrURL</b></p>
<p style="margin-left:22%;">The vault server name or URL.
If it is just a host name, the URL read is</p>
<p style="margin-left:32%;">https://hostname:8200</p>
<p style="margin-left:22%;">otherwise the whole URL is
used. This is the only required option.</p>
<p style="margin-left:11%;"><b>−−vaultalias=HostOrURL</b></p>
<p style="margin-left:22%;">The vault cluster name. This is
mainly useful for debugging, for example when multiple vault
servers in a cluster are serving the same name and the
address of a single server is supplied with
<i>−−vaultserver</i>. The
<i>−−vaultalias</i> is then used when
communicating with the name defined in the cluster, for
example for kerberos. Default is the same as
<i>−−vaultserver</i>.</p>
<p style="margin-left:11%;"><b>−−vaultcertname=Host</b></p>
<p style="margin-left:22%;">The vault https certficate
name. This is mainly useful when testing and the name in the
host certificate does not match the name used to access the
server. Default is the same as the host name part of
<i>−−vaultserver</i>.</p>
<p style="margin-left:11%;"><b>−i issuername</b>, <b>−−issuer=issuername</b></p>
<p style="margin-left:22%;">The name of the OIDC token
issuer, as configured in the vault server. The default
issuer name is "default".</p>
<p style="margin-left:11%;"><b>−r rolename</b>, <b>−−role=rolename</b></p>
<p style="margin-left:22%;">The name of the issuer role, as
configured in the vault server. The default role name is
"default". Different roles for the same issuer map
to different token scopes as configured in vault. </p>
<p style="margin-left:11%;"><b>−−nokerberos</b></p>
<p style="margin-left:22%;">Do not attempt to use kerberos
authentication.</p>
<p style="margin-left:11%;"><b>−−kerbpath=vaultpath</b></p>
<p style="margin-left:22%;">The path in vault for kerberos
authentication. The default is</p>
<p style="margin-left:32%;">auth/kerberos-%issuer_%role</p>
<p style="margin-left:11%;"><b>−−kerbprincipal=principal</b></p>
<p style="margin-left:22%;">Principal to use for kerberos
authentication. The principal has to be among those cached
on the current machine when a cache collection is available,
for example when $KRB5CCNAME begins with "DIR:".
The default is the currently selected principal. See the
<b>kswitch</b> command and the "-l" option of the
<b>klist</b> command for more information. </p>
<p style="margin-left:11%;"><b>−−nooidc</b></p>
<p style="margin-left:22%;">Do not attempt to do OIDC
authentication.</p>
<p style="margin-left:11%;"><b>−−oidcpath=vaultpath</b></p>
<p style="margin-left:22%;">The path in vault for doing
OIDC authentication. The default is</p>
<p style="margin-left:32%;">auth/oidc-%issuer/oidc</p>
<p style="margin-left:22%;">where %issuer is the value from
the <i>−−issuer</i> option. </p>
<p style="margin-left:11%;"><b>−−nossh</b></p>
<p style="margin-left:22%;">Do not attempt to do ssh-agent
authentication.</p>
<p style="margin-left:11%;"><b>−−sshpath=vaultpath</b></p>
<p style="margin-left:22%;">The path in vault for doing
ssh-agent authentication. The default is</p>
<p style="margin-left:32%;">auth/ssh </p>
<p style="margin-left:11%;"><b>−−registerssh</b></p>
<p style="margin-left:22%;">Register all public keys
available from <b>ssh-agent</b> with vault for future use.
This forces OIDC authentication even if a valid vault token
is already available and does the normal OIDC flow and then
registers the public keys before storing the vault token and
access token. Must be allowed in the configuration of the
vault server in order to work.</p>
<p style="margin-left:11%;"><b>−c path</b>, <b>−−configdir=path</b></p>
<p style="margin-left:22%;">The path to a directory to save
<b>htgettoken</b> configuration information.</p>
<p style="margin-left:11%;"><b>−−credkey=key</b></p>
<p style="margin-left:22%;">The key to use in the vault
secretpath (see next option) when accessing the bearer
token. Normally this is read from OIDC authentication and
automatically stored in a file to be used by later
invocations of <b>htgettoken</b>. The name of the file that
the key is stored in when <i>−−credkey</i> is
<b>not</b> specified on the command line is</p>
<p style="margin-left:32%;">%configdir/credkey-%issuer-%role</p>
<p style="margin-left:22%;">where each of the % variables
are replaced by the values of the corresponding options.</p>
<p style="margin-left:11%;"><b>−−secretpath=vaultpath</b></p>
<p style="margin-left:22%;">The path in vault for accessing
the bearer token. The default is</p>
<p style="margin-left:32%;">secret/oauth-%issuer/creds/%credkey:%role</p>
<p style="margin-left:22%;">where each of the % variables
are replaced by the values of the corresponding options.</p>
<p style="margin-left:11%;"><b>−−vaulttokenttl=time</b></p>
<p style="margin-left:22%;">The time for vault tokens to
live before they expire. The time is a number followed by
’s’ for seconds, ’m’ for minutes,
’h’ for hours, or ’d’ for days. The
maximum is determined by the vault configuration which is
typically ’28d’. The default is
’7d’.</p>
<p style="margin-left:11%;"><b>−−vaulttokenminttl=time</b></p>
<p style="margin-left:22%;">The minimum allowed time
remaining in the lifetime of an existing vault token before
it expires. If there is not enough time remaining it will
not be reused and a new one will be obtained instead. The
time is a number followed by ’s’ for seconds,
’m’ for minutes, ’h’ for hours, or
’d’ for days. Must be less than the value of
<i>−−vaulttokenttl</i>. The default is no
minimum.</p>
<p style="margin-left:11%;"><b>−−vaulttokenfile=path</b></p>
<p style="margin-left:22%;">The path to save vault tokens.
If the value of <i>−−vaultokenttl</i> is 1
million seconds or less (about 11.5 days), then the default
is</p>
<p style="margin-left:32%;">/tmp/vt_u%uid</p>
<p style="margin-left:22%;">otherwise it is /dev/stdout. If
the path contains %uid it is replaced with the current
effective user id. If the value of
<i>−−vaultokenttl</i> is greater than 1 million
seconds then the path is required to start with /dev/std or
/dev/fd in order to adhere to IGTF security policies
requiring user credentials that last longer than that to not
be stored unencrypted.</p>
<p style="margin-left:11%;"><b>−−vaulttokeninfile=path</b></p>
<p style="margin-left:22%;">The path to read vault tokens
from. Defaults to %vaulttokenfile which is replaced by the
value of the <i>−−vaulttokenfile</i> option. May
contain %uid which is replaced with the current effective
user id. If the path starts with /dev/std or /dev/fd then
the incoming vault token is exchanged for a new one with the
requested ttl (or the time remaining on the incoming token
if that is less). In this way a script can request a long
duration token, never store it on disk, and exchange it for
a shorter duration token by calling htgettoken again.</p>
<p style="margin-left:11%;"><b>−−showbearerurl</b></p>
<p style="margin-left:22%;">Print the full vault API bearer
token URL to stdout. This is intended for easy use by a
separate application that always has a valid vault token and
only needs to be able to get new bearer tokens and
doesn’t need the rest of the <b>htgettoken</b>
functionality.</p>
<p style="margin-left:11%;"><b>−−nobearertoken</b></p>
<p style="margin-left:22%;">Skip getting a bearer token;
only get a vault token.</p>
<p style="margin-left:11%;"><b>−o path</b>, <b>−−out=path</b></p>
<p style="margin-left:22%;">The path of the file used to
store the bearer token on the local machine. The default is
$BEARER_TOKEN_FILE. If that is not set but $XDG_RUNTIME_DIR
is set, then the default is</p>
<p style="margin-left:32%;">$XDG_RUNTIME_DIR/bt_u%uid</p>
<p style="margin-left:22%;">where %uid is the current
effective user id. <br>
If $XDG_RUNTIME_DIR is also not set, then the default is</p>
<p style="margin-left:32%;">/tmp/bt_u%uid</p>
<p style="margin-left:11%;"><b>−−minsecs=seconds</b></p>
<p style="margin-left:22%;">The minimum number of seconds
before a cached bearer token in vault expires in order to
reuse it instead of fetching a new one. This feature is
intended to reduce the load on token issuers while leaving
enough time for a token to still be usable. The default is
60.</p>
<p style="margin-left:11%;"><b>−−scopes=scopes</b></p>
<p style="margin-left:22%;">A comma- or space-separated
list of scopes to request for a bearer token. This should be
a subset of the scopes that come by default in the token. It
uses token exchange with the token issuer, and the result is
not cached in vault; instead, vault exchanges the cached
token for the new one.</p>
<p style="margin-left:11%;"><b>−−audience=audience</b></p>
<p style="margin-left:22%;">A comma- or space-separated
list of more restricted audiences for the token. Like the
<i>−−scopes</i> option, this uses token exchange
with the token issuer.</p>
<p style="margin-left:11%;"><b>−−cafile=file</b></p>
<p style="margin-left:22%;">The path to a file containing a
bundle of Certifying Authority (CA) certificates. These will
be used to verify the validity of https connections. The
default is</p>
<p style="margin-left:32%;">/etc/pki/tls/cert.pem</p>
<p style="margin-left:22%;">or, if that doesn’t
exist, the default is</p>
<p style="margin-left:32%;">/etc/ssl/certs/ca-certificates.crt</p>
<p style="margin-left:11%;"><b>−−capath=path</b></p>
<p style="margin-left:22%;">The path to a directory
containing Certifying Authority (CA) certificates. These
will be used in addition to the <i>−−cafile</i>
certificates to verify the validity of https connections.
The default is $X509_CERT_DIR if it is set, or otherwise the
default is</p>
<p style="margin-left:32%;">/etc/grid-security/certificates</p>
<p style="margin-left:11%;"><b>−−web-open-command=command</b></p>
<p style="margin-left:22%;">The command to run to open a
web URL. The default is no command if $SSH_CLIENT is set,
otherwise the default is <b>xdg-open</b>. If no command is
defined then the user will be prompted to open the URL
manually. See also the BROWSER environment variable
below.</p>
<h2>ENVIRONMENT
<a name="ENVIRONMENT"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The following
optional environment variables affect the operation of
<b>htgettoken</b>. <b><br>
BEARER_TOKEN_FILE</b></p>
<p style="margin-left:22%;">Default location for the bearer
token on the local disk. For more details see the
<i>−−outfile</i> option.</p>
<p style="margin-left:11%;"><b>BROWSER</b></p>
<p style="margin-left:22%;">Colon-separated list of web
browsers that <b>xdg-open</b> will attempt to invoke if it
is the selected web open command. The default is no browser
if the DISPLAY environment variable is not set; otherwise,
the default is a list of common web browsers as defined by
the xdg-open command, excluding those that are command-line
only.</p>
<p style="margin-left:11%;"><b>HTGETTOKENOPTS</b></p>
<p style="margin-left:22%;">Default options. These options
override any conflicting options from the optserver, but are
overridden by any conflicting options from the command
line.</p>
<p style="margin-left:11%;"><b>KRB5CCNAME</b></p>
<p style="margin-left:22%;">Location of a kerberos 5
credentials (ticket) cache.</p>
<p style="margin-left:11%;"><b>SSH_AUTH_SOCK</b></p>
<p style="margin-left:22%;">If set, points to a socket that
can be used to communicate with <b>ssh-agent</b>. This is
automatically created by <b>ssh-agent</b> and can be
automatically forwarded by <b>ssh</b> with a
"ForwardAgent=yes" option. To add a key to the
agent use <b>ssh-add</b>.</p>
<p style="margin-left:11%;"><b>SSH_CLIENT</b></p>
<p style="margin-left:22%;">If set, there is no default web
open command. If not set, the default web open command is
<b>xdg-open</b>.</p>
<p style="margin-left:11%;"><b>XDG_RUNTIME_DIR</b></p>
<p style="margin-left:22%;">Default directory for the
bearer token if $BEARER_TOKEN_FILE is not set. For more
details see the <i>−−outfile</i> option.</p>
<p style="margin-left:11%;"><b>X509_CERT_DIR</b></p>
<p style="margin-left:22%;">Default directory for CA
certificates. See also the <i>−−capath</i>
option.</p>
<h2>EXAMPLES
<a name="EXAMPLES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">To get a new
access token for an issuer called "dune" from a
vault server while showing all intermediate steps:</p>
<p style="margin-left:22%; margin-top: 1em">htgettoken -v
-a htvault.example.com -i dune</p>
<p style="margin-left:11%; margin-top: 1em">To read default
options from a server (which includes an issuer and vault
server and possibly other options) while choosing the
"prod" role:</p>
<p style="margin-left:22%; margin-top: 1em">htgettoken -s
htduneopts.fnal.gov -r prod</p>
<p style="margin-left:11%; margin-top: 1em">To always have
a default vault address:</p>
<p style="margin-left:22%; margin-top: 1em">export
HTGETTOKENOPTS="-a htvault.example.com"</p>
<h2>EXIT VALUES
<a name="EXIT VALUES"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em"><b>0</b></p></td>
<td width="10%"></td>
<td width="61%">
<p style="margin-top: 1em">Success</p></td>
<td width="17%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p><b>1</b></p></td>
<td width="10%"></td>
<td width="61%">
<p>All fatal errors other than usage errors</p></td>
<td width="17%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p><b>2</b></p></td>
<td width="10%"></td>
<td width="61%">
<p>Usage error</p></td>
<td width="17%">
</td></tr>
</table>
<h2>AUTHOR
<a name="AUTHOR"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Dave
Dykstra</p>
<h2>COPYRIGHT
<a name="COPYRIGHT"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Copyright
© 2020 Fermi National Accelerator Laboratory</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">htdecodetoken(1),
htdestroytoken(1), httokensh(1)</p>
<hr>
</body>
</html>