Skip to content

Commit 3483f59

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 f78857f commit 3483f59

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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/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)