Skip to content

Commit 4f8c689

Browse files
committed
ci: generate SSH key after downloading artifacts
Generate SSH key after downloading artifacts, and add it to the rootfs. This avoids having an SSH key hardcoded in the rootfs. Downside is that we have to rebuild the rootfs, but that is fast. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent d0e6027 commit 4f8c689

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

.buildkite/pipeline_cross.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
instances_x86_64 = ["c5n.metal", "m5n.metal", "m6i.metal", "m6a.metal"]
2222
instances_aarch64 = ["m7g.metal"]
2323
commands = [
24+
# we run 0 tests for the side effect of downloading the artifacts. We
25+
# should convert create_snapshot_artifact to a proper test/
26+
"./tools/devtool test -- integration_tests/performance/test_benchmarks.py",
2427
"./tools/devtool -y sh ./tools/create_snapshot_artifact/main.py",
2528
"mkdir -pv snapshots/{instance}_{kv}",
2629
"sudo chown -Rc $USER: snapshot_artifacts",

resources/rebuild.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ EOF
7070
# TBD what abt /etc/hosts?
7171
echo | tee $rootfs/etc/resolv.conf
7272

73-
# Generate key for ssh access from host
74-
if [ ! -s id_rsa ]; then
75-
ssh-keygen -f id_rsa -N ""
76-
fi
77-
install -d -m 0600 "$rootfs/root/.ssh/"
78-
cp id_rsa.pub "$rootfs/root/.ssh/authorized_keys"
79-
id_rsa=$OUTPUT_DIR/$ROOTFS_NAME.id_rsa
80-
cp id_rsa $id_rsa
81-
8273
rootfs_img="$OUTPUT_DIR/$ROOTFS_NAME.squashfs"
8374
mv $rootfs/root/manifest $OUTPUT_DIR/$ROOTFS_NAME.manifest
8475
mksquashfs $rootfs $rootfs_img -all-root -noappend -comp zstd

tools/devtool

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ ensure_ci_artifacts() {
542542
mkdir -pv $ARTIFACTS
543543
aws s3 sync --no-sign-request "$S3_URL" "$ARTIFACTS"
544544
# fix permissions
545-
find "$ARTIFACTS" -type f -name "*.id_rsa" |xargs chmod -c 400
546545
find "$ARTIFACTS/firecracker" -type f |xargs chmod -c 755
547546
fi
548547
}

tools/test.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,32 @@ if [ -f $CGROUP/cgroup.controllers -a -e $CGROUP/cgroup.type ]; then
3131
> $CGROUP/cgroup.subtree_control
3232
fi
3333

34+
say "Fixing CI artifacts"
3435
cd build/img/$(uname -m)
36+
# Generate key for ssh access from host
37+
if [ ! -s id_rsa ]; then
38+
ssh-keygen -f id_rsa -N ""
39+
fi
3540
for SQUASHFS in *.squashfs; do
41+
RSA=$(basename $SQUASHFS .squashfs).id_rsa
3642
EXT4=$(basename $SQUASHFS .squashfs).ext4
43+
[ -s $SQUASHFS.orig ] && continue
44+
unsquashfs $SQUASHFS
45+
mkdir -pv squashfs-root/root/.ssh
46+
# copy the SSH key into the rootfs
47+
if [ ! -s $RSA ]; then
48+
# append SSH key to the squashfs image
49+
cp -v id_rsa.pub squashfs-root/root/.ssh/authorized_keys
50+
cp -v id_rsa $RSA
51+
fi
52+
# re-squash
53+
mv -v $SQUASHFS $SQUASHFS.orig
54+
mksquashfs squashfs-root $SQUASHFS -all-root -noappend -comp zstd
55+
3756
# Create rw ext4 image from ro squashfs
3857
[ -f $EXT4 ] && continue
3958
say "Converting $SQUASHFS to $EXT4"
4059
truncate -s 400M $EXT4
41-
unsquashfs $SQUASHFS
4260
mkfs.ext4 -F $EXT4 -d squashfs-root
4361
rm -rf squashfs-root
4462
done

0 commit comments

Comments
 (0)