Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache IMDS tokens per-user #1386

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions files/bin/imds
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function imdscurl() {
}

function get-token() {
local TOKEN_DIR=/tmp/imds-tokens
mkdir -p -m a+wrx $TOKEN_DIR
local TOKEN_DIR="/tmp/imds-tokens/$(whoami)"
mkdir -p -m 0600 $TOKEN_DIR

# cleanup expired tokens
local DELETED_TOKENS=0
Expand All @@ -71,8 +71,7 @@ function get-token() {
-X PUT \
"http://$IMDS_ENDPOINT/latest/api/token")
echo "$TOKEN" > "$TOKEN_DIR/$TOKEN_FILE"
# make sure any user can utilize (and clean up) these tokens
chmod a+rwx $TOKEN_DIR/$TOKEN_FILE
chmod 0600 "$TOKEN_DIR/$TOKEN_FILE"
log "🔑 Retrieved a fresh IMDS token that will expire in $IMDS_TOKEN_TTL_SECONDS seconds."
else
log "ℹ️ Using cached IMDS token that expires in $(($TOKEN_FILE - $CURRENT_TIME)) seconds."
Expand Down
2 changes: 1 addition & 1 deletion test/cases/imds-token-refresh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o pipefail

echo "--> Should refresh IMDS token on configured interval"
exit_code=0
TOKEN_DIR=/tmp/imds-tokens
TOKEN_DIR=/tmp/imds-tokens/$(whoami)
TTL=5
export IMDS_TOKEN_TTL_SECONDS=$TTL
export IMDS_DEBUG=true
Expand Down