Skip to content

Commit a69595f

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 50060ac commit a69595f

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
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",

docs/getting-started.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ latest=$(wget "http://spec.ccfc.min.s3.amazonaws.com/?prefix=firecracker-ci/v1.1
106106
wget "https://s3.amazonaws.com/spec.ccfc.min/${latest}"
107107

108108
# Download a rootfs
109-
wget "https://s3.amazonaws.com/spec.ccfc.min/firecracker-ci/v1.10/${ARCH}/ubuntu-24.04.ext4"
110-
111-
# Download the ssh key for the rootfs
112-
wget "https://s3.amazonaws.com/spec.ccfc.min/firecracker-ci/v1.10/${ARCH}/ubuntu-24.04.id_rsa"
113-
114-
# Set user read permission on the ssh key
115-
chmod 400 ./ubuntu-24.04.id_rsa
109+
wget -O ubuntu-24.04.squashfs.upstream "https://s3.amazonaws.com/spec.ccfc.min/firecracker-ci/v1.10/${ARCH}/ubuntu-24.04.squashfs"
110+
111+
# Create an ssh key for the rootfs
112+
unsquashfs ubuntu-24.04.squashfs.upstream
113+
ssh-keygen -f id_rsa -N ""
114+
cp -v id_rsa.pub squashfs-root/root/.ssh/authorized_keys
115+
mv -v id_rsa ./ubuntu-24.04.id_rsa
116+
# re-squash
117+
mksquashfs squashfs-root ubuntu-24.04.squashfs -all-root -noappend -comp zstd
116118
```
117119

118120
### Getting a Firecracker Binary

resources/rebuild.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,13 @@ 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
8576
rm -rf $rootfs
8677
for bin in fast_page_fault_helper fillmem init readmem; do
8778
rm $PWD/overlay/usr/local/bin/$bin
8879
done
89-
rm -f id_rsa{,.pub}
9080
rm -f nohup.out
9181
}
9282

tools/setup-ci-artifacts.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,32 @@ cd build/img/$(uname -m)
1414
say "Fix executable permissions"
1515
find "firecracker" -type f |xargs chmod -c 755
1616

17-
say "Fix RSA key permissions"
18-
find . -type f -name "*.id_rsa" |xargs chmod -c 400
17+
say "Generate SSH key to connect from host"
18+
if [ ! -s id_rsa ]; then
19+
ssh-keygen -f id_rsa -N ""
20+
fi
1921

2022
for SQUASHFS in *.squashfs; do
23+
say "Include SSH key in $SQUASHFS"
24+
RSA=$(basename $SQUASHFS .squashfs).id_rsa
2125
EXT4=$(basename $SQUASHFS .squashfs).ext4
26+
[ -s $SQUASHFS.orig ] && continue
27+
unsquashfs $SQUASHFS
28+
mkdir -pv squashfs-root/root/.ssh
29+
# copy the SSH key into the rootfs
30+
if [ ! -s $RSA ]; then
31+
# append SSH key to the squashfs image
32+
cp -v id_rsa.pub squashfs-root/root/.ssh/authorized_keys
33+
cp -v id_rsa $RSA
34+
fi
35+
# re-squash
36+
mv -v $SQUASHFS $SQUASHFS.orig
37+
mksquashfs squashfs-root $SQUASHFS -all-root -noappend -comp zstd
2238

2339
# Create rw ext4 image from ro squashfs
2440
[ -f $EXT4 ] && continue
2541
say "Converting $SQUASHFS to $EXT4"
2642
truncate -s 400M $EXT4
27-
unsquashfs $SQUASHFS
2843
mkfs.ext4 -F $EXT4 -d squashfs-root
2944
rm -rf squashfs-root
3045
done

0 commit comments

Comments
 (0)