Skip to content

Commit 8c885a2

Browse files
authored
Merge pull request #144 from DrDaveD/httokensh-htgettokenopts
Fix httokensh to honor HTGETTOKENOPTS and not pass on --vaultmintokenttl
2 parents ddbf4ce + d2f7a29 commit 8c885a2

4 files changed

Lines changed: 59 additions & 10 deletions

File tree

htgettoken.spec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ rm -rf $RPM_BUILD_ROOT
8080
# and --nokerberos.
8181
# - Again fix --showbearerurl to work in combination with --nobearertoken.
8282
# That was fixed in 1.17 but broke in 1.21 and 2.0.
83+
# - Fix httokensh to pay attention to htgettoken options in $HTGETTOKENOPTS.
84+
# - Fix httokensh to correctly locate the log file if a -o or --outfile
85+
# is given, instead of writing to ".log" in the current directory.
86+
# - Fix httokensh to not pass on a --vaulttokenminttl option to the background
87+
# htgettoken command, to make the vault token last as long as possible since
88+
# it doesn't get renewed.
8389

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

httokensh

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,44 @@ GOTSEP=false
3030
MINSECS=60
3131
GOTVERBOSE=false
3232
GOTOUTFILE=false
33+
OUTFILE=""
3334
GOTVTFILE=false
3435
GOTVTTTL=false
36+
# look at HTGETTOKENOPTS in addition to those options on the command line
37+
# but don't explicitly pass them again to htgettoken
38+
HTGETSEP="--HTSEP--"
39+
set -- $HTGETTOKENOPTS $HTGETSEP "$@"
40+
DONEHTGETTOKENOPTS=false
3541
for ARG; do
3642
if $GOTSEP; then
3743
COMMANDARGS+=("$ARG")
44+
elif $GOTOUTFILE; then
45+
OUTFILE="$ARG"
46+
GOTOUTFILE=false
47+
if $DONEHTGETTOKENOPTS; then
48+
HTGETTOKENARGS+=("$ARG")
49+
fi
50+
elif [ "$ARG" = "$HTGETSEP" ]; then
51+
DONEHTGETTOKENOPTS=true
3852
elif [ "$ARG" = "--" ]; then
3953
GOTSEP=true
4054
else
41-
HTGETTOKENARGS+=("$ARG")
55+
if $DONEHTGETTOKENOPTS; then
56+
HTGETTOKENARGS+=("$ARG")
57+
fi
4258
case "$ARG" in
4359
--minsecs=*)
4460
MINSECS="${ARG/--minsecs=/}"
4561
;;
4662
-v|--verbose)
4763
GOTVERBOSE=true
4864
;;
49-
-o|--outfile=*)
65+
-o)
5066
GOTOUTFILE=true
5167
;;
68+
--outfile=*)
69+
OUTFILE="${ARG/--outfile=/}"
70+
;;
5271
--vaulttokenfile=*)
5372
GOTVTFILE=true
5473
;;
@@ -73,12 +92,16 @@ if [ ${#COMMANDARGS[@]} = 0 ]; then
7392
COMMANDARGS=("$SHELL")
7493
fi
7594

76-
if [ -z "$BEARER_TOKEN_FILE" ] && ! $GOTOUTFILE; then
77-
BTFILE="bt_u$(id -u).sh-$$"
78-
if [ -n "$XDG_RUNTIME_DIR" ]; then
79-
BEARER_TOKEN_FILE=$XDG_RUNTIME_DIR/$BTFILE
95+
if [ -z "$BEARER_TOKEN_FILE" ]; then
96+
if [ -n "$OUTFILE" ]; then
97+
BEARER_TOKEN_FILE="$OUTFILE"
8098
else
81-
BEARER_TOKEN_FILE=/tmp/$BTFILE
99+
BTFILE="bt_u$(id -u).sh-$$"
100+
if [ -n "$XDG_RUNTIME_DIR" ]; then
101+
BEARER_TOKEN_FILE=$XDG_RUNTIME_DIR/$BTFILE
102+
else
103+
BEARER_TOKEN_FILE=/tmp/$BTFILE
104+
fi
82105
fi
83106
export BEARER_TOKEN_FILE
84107
fi
@@ -123,6 +146,19 @@ gettoken()
123146
# beyond the minsecs, so reduce the minimum to just 1 second
124147
gettoken "not running command" 1
125148

149+
# Remove any --vaulttokenminttl option so the background renewal
150+
# gets to be as long as possible
151+
if [[ "$HTGETTOKENOPTS" = *--vaulttokenminttl* ]]; then
152+
HTGETTOKENOPTS="$(echo "$HTGETTOKENOPTS"|sed 's/--vaulttokenminttl=[^ ]*//')"
153+
fi
154+
NEWARGS=()
155+
for ARG in "${HTGETTOKENARGS[@]}"; do
156+
if [[ "$ARG" != --vaulttokenminttl* ]]; then
157+
NEWARGS+=("$ARG")
158+
fi
159+
done
160+
HTGETTOKENARGS=("${NEWARGS[@]}")
161+
126162
# make sure the logged info is verbose for easier diagnosis
127163
if ! $GOTVERBOSE; then
128164
HTGETTOKENARGS+=("-v")

httokensh.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ htgettoken options provided then
4141
.I \-\-vaulttokenminttl=6d
4242
will be automatically added to ensure there are at least 6 days remaining
4343
on the vault token.
44+
The vault token will not be renewed when it expires, so
45+
.B httokensh
46+
is limited to being run for 6 days; it is intended only for interactive
47+
use.
4448

4549
The access token will be renewed just under
4650
.I \-\-minsecs

httokensh.html

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

0 commit comments

Comments
 (0)