Skip to content

Commit 2c0968a

Browse files
authored
Merge pull request #71 from flatcar/kai/fallback-update-key
initrd-setup-root-after-ignition: Use update key for initrd sysext DL
2 parents 487ae88 + 6650fe4 commit 2c0968a

File tree

1 file changed

+27
-76
lines changed

1 file changed

+27
-76
lines changed

dracut/99setup-root/initrd-setup-root-after-ignition

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,30 @@ function usrcurl() {
1212
}
1313

1414
function download_and_verify() {
15-
# Downloads release artifact to /sysroot/$name and verifies $name.sig with gpg
15+
# Extracts release artifact to /sysroot/$final_name
1616
# Expects the env vars: FLATCAR_BOARD, VERSION
17-
local name="$1"
18-
# TODO: We should use update.release.flatcar-linux.net and then decode the payload
19-
local channel=""
20-
case $(echo "${VERSION}" | cut -d . -f 2) in
21-
0) channel="alpha" ;;
22-
1) channel="beta" ;;
23-
2) channel="stable" ;;
24-
3) channel="lts" ;;
25-
*) ;;
26-
esac
27-
local URLS=()
28-
if [ "${channel}" != "" ]; then
29-
URLS+=("https://${channel}.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/${name}")
17+
local final_name="$1"
18+
local name="${final_name/.raw/.gz}"
19+
URL="https://update.release.flatcar-linux.net/${FLATCAR_BOARD}/${VERSION}/${name}"
20+
# Check for scripts:sdk_container/src/third_party/coreos-overlay/coreos-base/coreos-au-key/files/developer-v1.pub.pem
21+
if [ "$(usrbin md5sum /sysroot/usr/share/update_engine/update-payload-key.pub.pem | cut -d " " -f 1)" = "7192addf4a7f890c0057d21653eff2ea" ]; then
22+
URL="https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/-usr}/${VERSION}/flatcar_test_update-${name}"
3023
fi
31-
URLS+=("https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/-usr}/${VERSION}/${name}")
24+
# TODO: Replace the below with invoking an ue-rs helper binary for downloading the payload
25+
# from the URL and write the unpacked, verified file to the final name.
3226
local COUNT=""
33-
local URL=""
34-
for URL in "${URLS[@]}" LAST; do
35-
if [ "${URL}" = LAST ]; then
36-
echo "Failed to download required sysext image ${name}" >&2
37-
exit 1 # Fail the boot
27+
# Workaround: Once curl starts and fails to resolve a DNS name (due to a race or temporary failure),
28+
# it sticks to it for each retry, making the retry pointless. Therefore, we first have to
29+
# add a curl waiter that does the DNS retry and won't be stuck (nor waste 30*60 seconds).
30+
for COUNT in $(usrbin seq 30); do
31+
if usrbin curl -fsSL --head "${URL}" > /dev/null; then
32+
break
3833
fi
39-
# Workaround: Once curl starts and fails to resolve a DNS name (due to a race or temporary failure),
40-
# it sticks to it for each retry, making the retry pointless. Therefore, we first have to
41-
# add a curl waiter that does the DNS retry and won't be stuck (nor waste 30*60 seconds).
42-
for COUNT in $(usrbin seq 30); do
43-
if usrbin curl -fsSL --head "${URL}" > /dev/null; then
44-
break
45-
fi
46-
sleep 1
47-
done
48-
usrcurl -o "/sysroot/${name}" "${URL}" || { rm -f "/sysroot/${name}" ; continue ; }
49-
usrcurl -o "/sysroot/${name}.sig" "${URL}.sig" || { rm -f "/sysroot/${name}.sig" ; continue ; }
50-
break
34+
sleep 1
5135
done
52-
local GPG_KEY=""
53-
local GPG_LONG_ID=""
54-
# Extract public key from flatcar-install
55-
GPG_KEY=$(tr '\n' '_' < /sysroot/usr/bin/flatcar-install | grep -Po 'GPG_KEY="\K.*?(?=")' | tr '_' '\n')
56-
GPG_LONG_ID=$(grep -Po '^GPG_LONG_ID="\K.*?(?=")' /sysroot/usr/bin/flatcar-install)
57-
export GNUPGHOME=/run/_gpg
58-
mkdir -p "${GNUPGHOME}"
59-
usrbin chmod 700 "${GNUPGHOME}"
60-
usrbin gpg --batch --quiet --import <<< "${GPG_KEY}"
61-
if ! usrbin gpg --batch --trusted-key "${GPG_LONG_ID}" --verify "/sysroot/${name}.sig" "/sysroot/${name}"; then
62-
rm -f "/sysroot/${name}.sig" "/sysroot/${name}"
63-
rm -rf "${GNUPGHOME}"
64-
echo "Failed to verify required sysext image ${name}" >&2
65-
exit 1 # Fail the boot
66-
fi
67-
rm "/sysroot/${name}.sig"
68-
rm -rf "${GNUPGHOME}"
36+
rm -f "/sysroot/${name}"
37+
usrcurl -o "/sysroot/${name}" "${URL}" || { rm -f "/sysroot/${name}" ; return 1 ; }
38+
usrbin unshare -m sh -c "mount --rbind /dev /sysroot/dev/ && mount -t proc /proc /sysroot/proc/ && PROTOPATH=/usr/share/update_engine/ chroot /sysroot /usr/share/update_engine/decode_payload /usr/share/update_engine/update-payload-key.pub.pem \"/${name}\" \"/${final_name}\"" || { rm -f "/sysroot/${final_name}" ; echo "Failing boot" >&2 ; exit 1; }
6939
true # Don't leak previous exit code as return code
7040
}
7141

@@ -82,7 +52,6 @@ OEMID=$({ grep -m 1 -o "^ID=.*" /sysroot/oem/oem-release || true ; } | cut -d =
8252

8353
# The active-oem-OEMID file gets created by the update-engine postinst action if both old and new /usr partitions have a sysext
8454
if [ "${OEMID}" != "" ] && [ -e "/sysroot/oem/sysext/active-oem-${OEMID}" ]; then
85-
INITIAL_MVP="/oem/sysext/oem-${OEMID}-initial.raw"
8655
SYSEXT_OEM_PART="/oem/sysext/oem-${OEMID}-${VERSION}.raw"
8756
SYSEXT_ROOT_PART="/etc/flatcar/oem-sysext/oem-${OEMID}-${VERSION}.raw"
8857
SYMLINK="/sysroot/etc/extensions/oem-${OEMID}.raw"
@@ -111,38 +80,19 @@ if [ "${OEMID}" != "" ] && [ -e "/sysroot/oem/sysext/active-oem-${OEMID}" ]; the
11180
echo "That failed, keeping it on root partition" >&2
11281
ACTIVE_OEM="${SYSEXT_ROOT_PART}"
11382
fi
114-
elif [ -e "/sysroot/${INITIAL_MVP}" ]; then
115-
# This is the initial MVP OEM sysext that is not bound to the OS version because
116-
# at that time update support was missing.
117-
# Like any other inactive sysext, it will be deleted by update-engine's post-inst action
118-
# when it's not needed (i.e., the active and new inactive both have a versioned sysext)
119-
ACTIVE_OEM="${INITIAL_MVP}"
12083
else
12184
echo "Did not find ${SYSEXT_OEM_PART} nor ${SYSEXT_ROOT_PART}, downloading" >&2
12285
systemctl start --quiet systemd-networkd systemd-resolved
12386
download_and_verify "oem-${OEMID}.raw"
124-
# TODO: This can be removed once we download the update payload from update.release.flatcar-linux.net
125-
# because it won't be the "initial" MVP sysext
126-
mkdir -p /run/_oem
127-
mount "/sysroot/oem-${OEMID}.raw" /run/_oem/
128-
if grep -q SYSEXT_LEVEL=1.0 "/run/_oem/usr/lib/extension-release.d/extension-release.oem-${OEMID}" ; then
129-
# The initial MVP OEM is only supported on the OEM partition
130-
ACTIVE_OEM="${INITIAL_MVP}"
131-
fi
132-
umount "/sysroot/oem-${OEMID}.raw"
13387
mkdir -p /sysroot/oem/sysext/
134-
if [ "${ACTIVE_OEM}" != "" ]; then
135-
mv "/sysroot/oem-${OEMID}.raw" "/sysroot${ACTIVE_OEM}"
88+
echo "Trying to place /sysroot/oem-${OEMID}.raw on OEM partition" >&2
89+
if mv "/sysroot/oem-${OEMID}.raw" "/sysroot${SYSEXT_OEM_PART}"; then
90+
ACTIVE_OEM="${SYSEXT_OEM_PART}"
13691
else
137-
echo "Trying to place /sysroot/oem-${OEMID}.raw on OEM partition" >&2
138-
if mv "/sysroot/oem-${OEMID}.raw" "/sysroot${SYSEXT_OEM_PART}"; then
139-
ACTIVE_OEM="${SYSEXT_OEM_PART}"
140-
else
141-
echo "That failed, moving it to right location on root partition" >&2
142-
mkdir -p /sysroot/etc/flatcar/oem-sysext/
143-
mv "/sysroot/oem-${OEMID}.raw" "/sysroot${SYSEXT_ROOT_PART}"
144-
ACTIVE_OEM="${SYSEXT_ROOT_PART}"
145-
fi
92+
echo "That failed, moving it to right location on root partition" >&2
93+
mkdir -p /sysroot/etc/flatcar/oem-sysext/
94+
mv "/sysroot/oem-${OEMID}.raw" "/sysroot${SYSEXT_ROOT_PART}"
95+
ACTIVE_OEM="${SYSEXT_ROOT_PART}"
14696
fi
14797
fi
14898
if [ "${ACTIVE_OEM}" != "" ] && [ -e "/sysroot/${ACTIVE_OEM}" ]; then
@@ -180,6 +130,7 @@ for NAME in $(grep -h -o '^[^#]*' /sysroot/etc/flatcar/enabled-sysext.conf /sysr
180130
ACTIVE_EXT="/etc/flatcar/sysext/flatcar-${NAME}-${VERSION}.raw"
181131
if [ ! -e "/sysroot/${ACTIVE_EXT}" ]; then
182132
echo "Did not find ${ACTIVE_EXT}" >&2
133+
systemctl start --quiet systemd-networkd systemd-resolved
183134
download_and_verify "flatcar-${NAME}.raw"
184135
mv "/sysroot/flatcar-${NAME}.raw" "/sysroot/${ACTIVE_EXT}"
185136
fi

0 commit comments

Comments
 (0)