fix(ssh): handle chmod failures gracefully and simplify key management

- Log warnings instead of silently failing when chmod 0600 fails
- Remove redundant refresh() call before SSH key validation
- Remove storeInFileSystem() call from updatePrivateKey() transaction
- Remove @unlink() of lock file after filesystem store
- Refactor unit tests to use real temp disk and anonymous class stub
  instead of reflection-only checks
This commit is contained in:
Andras Bacsai
2026-03-16 21:27:10 +01:00
parent 9976645c25
commit 6325e41aec
3 changed files with 155 additions and 138 deletions
+5 -4
View File
@@ -209,8 +209,6 @@ class SshMultiplexingHelper
private static function validateSshKey(PrivateKey $privateKey): void
{
$privateKey->refresh();
$keyLocation = $privateKey->getKeyLocation();
$filename = "ssh_key@{$privateKey->uuid}";
$disk = Storage::disk('ssh-keys');
@@ -236,8 +234,11 @@ class SshMultiplexingHelper
// Ensure correct permissions (SSH requires 0600)
if (file_exists($keyLocation)) {
$currentPerms = fileperms($keyLocation) & 0777;
if ($currentPerms !== 0600) {
chmod($keyLocation, 0600);
if ($currentPerms !== 0600 && ! chmod($keyLocation, 0600)) {
Log::warning('Failed to set SSH key file permissions to 0600', [
'key_uuid' => $privateKey->uuid,
'path' => $keyLocation,
]);
}
}
}