From fbb910acc1b5ad2eac5e5374bb4b5a66e638abc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jake=20Buchholz=20G=C3=B6kt=C3=BCrk?= Date: Mon, 15 Jun 2026 16:26:44 -0700 Subject: [PATCH] fix error when non-root user tries to cache latest endpoint, also don't need to re-cache same endpoint --- CHANGELOG.md | 6 +++++- bin/imds | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d86305d..eccbff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 2026-06-XX - Tiny Cloud v3.3.3 +## 2026-06-15 - Tiny Cloud v3.3.3 * Support IPv6 and multiple endpoints [#68](https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud/-/work_items/68) @@ -9,6 +9,10 @@ routable. Fixes race condition between `dhcpcd` starting and attempting to reach IMDS before routes are resolved. +* Currently the most recent IMDS endpoint that worked is cached, but only if + **root** is running `imds`. We may consider keeping track of this per user + in the future + ## 2026-06-08 - Tiny Cloud v3.3.2 * Fixes an autodetect regression introduced in v3.3.1 diff --git a/bin/imds b/bin/imds index 177c21a..cae8877 100755 --- a/bin/imds +++ b/bin/imds @@ -120,7 +120,7 @@ _imds_has_route() { } _imds() { - local endpoint endpoints routed attempts=1 + local endpoint endpoints routed attempts=1 cached if [ "$IMDS_ENDPOINT_WAIT_ATTEMPTS" -le 0 ]; then endpoints="$(_imds_endpoints)" fi @@ -148,7 +148,8 @@ _imds() { wget --quiet --timeout 1 --output-document - \ --header "$(_imds_header)" \ "http://$endpoint/$IMDS_URI/$1$IMDS_QUERY" && { - echo "$endpoint" > "$IMDS_ENDPOINT_CACHE" + cached="$(cat "$IMDS_ENDPOINT_CACHE" 2>/dev/null)" || : + [ "$endpoint" = "$cached" ] || echo "$endpoint" 2>/dev/null > "$IMDS_ENDPOINT_CACHE" || : return 0 } done