Skip to content

Commit ddbf4ce

Browse files
authored
Merge pull request #143 from DrDaveD/destroy-refresh
Add htgettoken --novaulttoken and htdestroytoken -f
2 parents 3bbb5f3 + d3129fa commit ddbf4ce

14 files changed

Lines changed: 192 additions & 64 deletions

File tree

htdestroytoken

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,67 @@
11
#!/bin/bash
22

3-
VERBOSE=true
4-
if [ "$1" = "-q" ]; then
5-
VERBOSE=false
6-
shift
7-
fi
3+
ME=htdestroytoken
84

9-
if [ $# != 0 ]; then
10-
echo "Usage: htdestroytoken [-q]" >&2
11-
echo "Removes bearer and vault tokens" >&2
12-
echo "-q means to do it silently" >&2
5+
usage()
6+
{
7+
echo "Usage: $ME [-h] [-q] [-f [htgettoken options]]"
8+
echo "Removes bearer and vault tokens if present"
9+
echo " -h prints this help message and exits"
10+
echo " -q do removals silently"
11+
echo " -f first force removal of refresh token from vault, if vault token is valid."
12+
echo " Runs htgettoken to find the vault path so requires sufficient htgettoken"
13+
echo " options on command line or in \$HTGETTOKENOPTS."
14+
echo "The location of the bearer token can be set by \$BEARER_TOKEN_FILE"
15+
echo " and the location of the vault token can be set by \$VAULT_TOKEN_FILE."
1316
exit 2
14-
fi
17+
} >&2
18+
19+
VERBOSE=true
20+
RMREFRESH=false
21+
HTGETOPTS=""
22+
for ARG; do
23+
case $ARG in
24+
-h) usage;;
25+
-q) VERBOSE=false; HTGETOPTS="$HTGETOPTS -q";;
26+
-f) RMREFRESH=true;;
27+
*) if $RMREFRESH; then
28+
HTGETOPTS="$HTGETOPTS $ARG"
29+
else
30+
usage
31+
fi;;
32+
esac
33+
done
1534

1635
# UID is a standard bash variable
36+
VTFILE="/tmp/vt_u$UID"
37+
if [ -n "$VAULT_TOKEN_FILE" ]; then
38+
VTFILE="$VAULT_TOKEN_FILE"
39+
HTGETOPTS="$HTGETOPTS --vaulttokenfile=$VTFILE"
40+
fi
41+
if $RMREFRESH && [ -f "$VTFILE" ]; then
42+
if ( [ -z "$HTGETOPTS" ] || [ "$HTGETOPTS" = "-q" ] ) \
43+
&& [ -z "$HTGETTOKENOPTS" ]; then
44+
echo "$ME: no htgettoken options were given" >&2
45+
usage
46+
fi
47+
BEARERURL="$(htgettoken $HTGETOPTS --novaulttoken --nobearertoken --showbearerurl)"
48+
if [ -z "$BEARERURL" ]; then
49+
echo "$ME: Unable to obtain vault URL to remove refresh token" >&2
50+
exit 3
51+
fi
52+
if $VERBOSE; then
53+
echo "Deleting refresh token"
54+
echo " at path $BEARERURL"
55+
fi
56+
# be careful to not let the vault token show up in a ps list; send to stdin
57+
if ! (echo -n "X-Vault-Token: ";cat $VTFILE) | \
58+
curl -q -f -m 5 -H @- -X DELETE "$BEARERURL"; then
59+
echo "$ME: Unable to delete refresh token" >&2
60+
exit 3
61+
fi
62+
fi
1763
TOKENFILE="${BEARER_TOKEN_FILE:-${XDG_RUNTIME_DIR:-/tmp}/bt_u$UID}"
18-
for FILE in $TOKENFILE /tmp/vt_u$UID*; do
64+
for FILE in $TOKENFILE ${VTFILE}; do
1965
if [ -f "$FILE" ]; then
2066
if $VERBOSE; then
2167
echo "Removing $FILE"

htdestroytoken.1

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,53 @@ htdestroytoken \- remove bearer and vault tokens
44

55
.SH SYNOPSIS
66
.B htdestroytoken
7-
[-q]
8-
7+
[-h] [-q] [-f [htgettoken options]]"
98
.SH DESCRIPTION
109
.B htdestroytoken
11-
removes a bearer token found by WLCG Bearer Token Discovery and also
12-
removes a vault token found in the default location used by
13-
.BR htgettoken.
14-
15-
Note that the vault server additionally caches bearer tokens, so the
16-
next time that
10+
by default removes a bearer token found by WLCG Bearer Token Discovery and
11+
also removes a vault token found either by the environment variable
12+
$VAULT_TOKEN_FILE or in the default location used by
13+
.BR htgettoken .
14+
.PP
15+
Note that the vault server additionally caches refresh tokens and bearer
16+
tokens, so this alone does not completely clear them. The
17+
.I -f
18+
option (described below) can remove the refresh token to force a new
19+
oidc authentication.
20+
If that is not used and
21+
.B htgettoken
22+
is subsequently run and gets a new vault token with one of the non-oidc
23+
authentication methods, it is possible that the same bearer token might
24+
be returned from the vault cache unless a new one is forced to be
25+
retrieved with an
1726
.B htgettoken
18-
is run the same bearer token might be returned unless a new one is
19-
forced to be retrieved with either oidc authentication or with an
20-
htgettoken
2127
.I \-\-minsecs
2228
option.
2329

2430
.SH OPTIONS
2531
The following options are recognized:
2632
.PP
2733
.TP
28-
.BR \-q
29-
Do removals silently
34+
.B \-h
35+
Show help message.
36+
.TP
37+
.B \-q
38+
Do removals silently.
39+
.TP
40+
.B \-f [htgettoken options]
41+
Force a removal of the refresh token in vault before removal of the
42+
vault token, if the vault token is valid. This runs
43+
.B htgettoken
44+
to locate the path in vault to remove, so sufficient options to locate
45+
that path such as
46+
.IR \-a ,
47+
.I \-i
48+
and possibly
49+
.I \-r
50+
need to either be passed on the rest of the command line or in the
51+
$HTGETTOKENOPTS environment variable.
52+
If this option is given and the removal of the refresh token fails,
53+
the command will exit and not remove the vault or bearer tokens.
3054

3155
.SH AUTHOR
3256
Dave Dykstra

htdestroytoken.html

Lines changed: 46 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htgettoken.1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ The name of the issuer role, as configured in the vault server. The
9494
default role name is "default". Different roles for the same issuer
9595
map to different token scopes as configured in vault.
9696
.TP
97-
.BR \ \-\-nokerberos
97+
.BR \-\-nokerberos
9898
Do not attempt to use kerberos authentication.
9999
.TP
100100
.BR \-\-kerbpath=vaultpath
@@ -115,7 +115,7 @@ command and the "-l" option of the
115115
.B klist
116116
command for more information.
117117
.TP
118-
.BR \ \-\-nooidc
118+
.BR \-\-nooidc
119119
Do not attempt to do OIDC authentication.
120120
.TP
121121
.BR \-\-oidcpath=vaultpath
@@ -129,7 +129,7 @@ where %issuer is the value from the
129129
option.
130130
.RE
131131
.TP
132-
.BR \ \-\-nossh
132+
.BR \-\-nossh
133133
Do not attempt to do ssh-agent authentication.
134134
.TP
135135
.BR \-\-sshpath=vaultpath
@@ -140,7 +140,7 @@ auth/ssh
140140
.RE
141141
.RE
142142
.TP
143-
.BR \ \-\-registerssh
143+
.BR \-\-registerssh
144144
Register all public keys available from
145145
.B ssh-agent
146146
with vault for future use. This forces OIDC authentication even if a
@@ -149,6 +149,12 @@ then registers the public keys before storing the vault token and access
149149
token. Must be allowed in the configuration of the vault server in
150150
order to work.
151151
.TP
152+
.BR \-\-novaulttoken
153+
Disable all authentication methods that get vault tokens.
154+
Currently this equivalent to
155+
.IR \-\-nooidc\ \-\-nokerberos\ \-\-nossh .
156+
.BR
157+
.TP
152158
.BR \-c\ path , \ \-\-configdir=path
153159
The path to a directory to save
154160
.B htgettoken
@@ -238,7 +244,7 @@ Skip getting a bearer token. Always gets a vault token except in
238244
combination with
239245
.BR \-\-showbearerurl .
240246
.TP
241-
.BR \-o\ path , \ \-\-out=path
247+
.BR \-o\ path , \ \-\-outfile=path
242248
The path of the file used to store the bearer token on the local
243249
machine. The default is $BEARER_TOKEN_FILE. If that is not set
244250
but $XDG_RUNTIME_DIR is set, then the default is

htgettoken.html

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htgettoken.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ rm -rf $RPM_BUILD_ROOT
7474

7575

7676
%changelog
77+
# - Add htdestroytoken -f option to force a removal of a refresh token in
78+
# vault.
79+
# - Add htgettoken --novaulttoken option as an alias for --noiodc, --nossh,
80+
# and --nokerberos.
7781
# - Again fix --showbearerurl to work in combination with --nobearertoken.
78-
# That was fixed in 1.17 but broken in 1.21 and 2.0.
82+
# That was fixed in 1.17 but broke in 1.21 and 2.0.
7983

8084
* Fri Jun 20 2025 Dave Dykstra <dwd@fnal.gov> 2.4-1
8185
- Add the new -s and -f options to the htdecodetoken usage summary.

0 commit comments

Comments
 (0)