fix(install): keep operator SSH keys that mention coolify

On a fresh install, install.sh removed every authorized_keys line that
contained "coolify", including unrelated operator keys such as one
commented "coolify-disposable". Remove only lines whose comment is
exactly "coolify", the comment of the installer's own key.

Closes #12278

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-10-23 22:20:05 +02:00
co-authored by Claude Opus 5.5
parent da462c9f9a
commit 54c930d8dd
4 changed files with 41 additions and 3 deletions
+2 -1
View File
@@ -1006,7 +1006,8 @@ if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then
test -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub && rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify
chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal
sed -i "/coolify/d" ~/.ssh/authorized_keys
# Remove only the key from a previous install (generated with the comment "coolify"), not other keys that contain "coolify"
sed -i -E "/[[:space:]]coolify[[:space:]]*$/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >>~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub
fi
+2 -1
View File
@@ -1006,7 +1006,8 @@ if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then
test -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub && rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify
chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal
sed -i "/coolify/d" ~/.ssh/authorized_keys
# Remove only the key from a previous install (generated with the comment "coolify"), not other keys that contain "coolify"
sed -i -E "/[[:space:]]coolify[[:space:]]*$/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >>~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub
fi
+1 -1
View File
@@ -242,7 +242,7 @@ delete_vm "$VM_NAME"
mkdir -p "$IMAGE_DIR"
if [ ! -f "$SSH_KEY" ]; then
# The comment must not contain "coolify": install.sh removes such lines from authorized_keys.
# Do not use the comment "coolify": install.sh removes authorized_keys lines with exactly that comment.
ssh-keygen -q -t ed25519 -N '' -C restore-test-vm -f "$SSH_KEY"
fi
@@ -0,0 +1,36 @@
<?php
use Symfony\Component\Process\Process;
it('removes only the previous Coolify key from authorized_keys', function (string $path) {
$script = file_get_contents(dirname(__DIR__, 2).'/'.$path);
preg_match('/^\s*(sed -i .*~\/\.ssh\/authorized_keys)$/m', $script, $matches);
expect($matches)->toHaveKey(1);
$home = sys_get_temp_dir().'/coolify-install-keys-'.bin2hex(random_bytes(4));
mkdir($home.'/.ssh', 0700, true);
file_put_contents($home.'/.ssh/authorized_keys', implode("\n", [
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOperatorKey coolify-disposable',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOperatorKey operator-lab',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHostKey root@coolify',
'no-pty ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOptions deploy@coolify.example.com',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOldCoolifyKey coolify',
'',
]));
$process = new Process(['bash', '-c', $matches[1]], null, ['HOME' => $home]);
$process->mustRun();
expect(file_get_contents($home.'/.ssh/authorized_keys'))->toBe(implode("\n", [
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOperatorKey coolify-disposable',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOperatorKey operator-lab',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHostKey root@coolify',
'no-pty ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOptions deploy@coolify.example.com',
'',
]));
exec('rm -rf '.escapeshellarg($home));
})->with([
'stable install script' => ['scripts/install.sh'],
'nightly install script' => ['other/nightly/install.sh'],
]);