Skip to content

Commit fdbcb8f

Browse files
cursoragentruflin
andcommitted
install.sh: verify Composer installer checksum and merge daemon.json
Address PR review feedback: - Verify the downloaded Composer installer against the official installer.sig sha384 signature before executing it, to guard against a tampered or MITM'd download in automated setup. - Merge only the storage-driver key into /etc/docker/daemon.json instead of overwriting the whole file, preserving any pre-existing daemon configuration and keeping the step idempotent. Co-authored-by: Nicolas Ruflin <ruflin@users.noreply.github.com>
1 parent d04133f commit fdbcb8f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

.cursor/install.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ $APT_INSTALL \
3636

3737
echo "==> Installing Composer"
3838
if ! command -v composer >/dev/null 2>&1; then
39+
# Verify the installer against the official signature before running it
40+
# (guards against a tampered/MITM'd download).
3941
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"
42+
expected_checksum="$(php -r "copy('https://composer.github.io/installer.sig', 'php://stdout');")"
43+
actual_checksum="$(php -r "echo hash_file('sha384', '/tmp/composer-setup.php');")"
44+
if [ "$expected_checksum" != "$actual_checksum" ]; then
45+
echo "ERROR: invalid Composer installer checksum" >&2
46+
rm -f /tmp/composer-setup.php
47+
exit 1
48+
fi
4049
php /tmp/composer-setup.php --quiet --install-dir=/tmp --filename=composer.phar
4150
sudo mv /tmp/composer.phar /usr/local/bin/composer
4251
rm -f /tmp/composer-setup.php
@@ -56,10 +65,13 @@ sudo usermod -aG docker "$(id -un)" || true
5665

5766
echo "==> Configuring Docker daemon for the nested-container VM (fuse-overlayfs)"
5867
# The default overlayfs/overlay2 driver cannot mount inside this VM; fuse-overlayfs
59-
# is the supported nested-container storage driver.
68+
# is the supported nested-container storage driver. Merge just the storage-driver
69+
# key so any pre-existing daemon config (registry mirrors, log options, ...) is
70+
# preserved; only restart the daemon when the driver actually changes.
6071
sudo mkdir -p /etc/docker
61-
if [ ! -f /etc/docker/daemon.json ] || ! grep -q fuse-overlayfs /etc/docker/daemon.json; then
62-
echo '{ "storage-driver": "fuse-overlayfs" }' | sudo tee /etc/docker/daemon.json >/dev/null
72+
current_driver="$(sudo php -r '$f="/etc/docker/daemon.json"; $c=is_file($f)&&""!==trim((string) @file_get_contents($f))?json_decode((string) file_get_contents($f), true):[]; echo \is_array($c)&&isset($c["storage-driver"])?$c["storage-driver"]:"";' 2>/dev/null || true)"
73+
if [ "$current_driver" != "fuse-overlayfs" ]; then
74+
sudo php -r '$f="/etc/docker/daemon.json"; $c=is_file($f)&&""!==trim((string) @file_get_contents($f))?json_decode((string) file_get_contents($f), true):[]; if(!\is_array($c)){$c=[];} $c["storage-driver"]="fuse-overlayfs"; file_put_contents($f, json_encode($c, \JSON_PRETTY_PRINT|\JSON_UNESCAPED_SLASHES)."\n");'
6375
sudo service docker restart || sudo service docker start || true
6476
fi
6577
sudo service docker start || true

0 commit comments

Comments
 (0)