{"record":{"id":"b80bea36376fcbf3","repo":"coollabsio/coolify","slug":"ssh-key-file-content-verification-failed-keyloc","errorCode":null,"errorMessage":"SSH key file content verification failed: {$keyLocation}","messagePattern":"SSH key file content verification failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/Models/PrivateKey.php","lineNumber":240,"sourceCode":"                throw new \\Exception(\"Failed to acquire lock for SSH key: {$keyLocation}\");\n            }\n\n            // Attempt to store the private key\n            $success = $disk->put($filename, $this->private_key);\n\n            if (! $success) {\n                throw new \\Exception(\"Failed to write SSH key to filesystem. Check disk space and permissions for: {$keyLocation}\");\n            }\n\n            // Verify the file was actually created and has content\n            if (! $disk->exists($filename)) {\n                throw new \\Exception(\"SSH key file was not created: {$keyLocation}\");\n            }\n\n            $storedContent = $disk->get($filename);\n            if (empty($storedContent) || $storedContent !== $this->private_key) {\n                $disk->delete($filename); // Clean up the bad file\n                throw new \\Exception(\"SSH key file content verification failed: {$keyLocation}\");\n            }\n\n            // Ensure correct permissions for SSH (0600 required)\n            if (file_exists($keyLocation) && ! chmod($keyLocation, 0600)) {\n                Log::warning('Failed to set SSH key file permissions to 0600', [\n                    'key_uuid' => $this->uuid,\n                    'path' => $keyLocation,\n                ]);\n            }\n\n            return $keyLocation;\n        } finally {\n            flock($lockHandle, LOCK_UN);\n            fclose($lockHandle);\n        }\n    }\n\n    public static function deleteFromStorage(self $privateKey)","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Models/PrivateKey.php#L222-L258","documentation":"Thrown by PrivateKey::storeInFileSystem() (app/Models/PrivateKey.php:240). After put() and exists() succeed, the routine reads the file back and compares it byte-for-byte with $this->private_key. A mismatch (or empty read) means the file on disk does not equal what was just written under an exclusive lock — indicating concurrent writers bypassing the lock (e.g. a process writing the same ssh_key@{uuid} path directly), disk corruption, or storage layer caching (network/FUSE). The bad file is deleted before throwing, so no corrupt key is left behind.","triggerScenarios":"Two workers storing different key material under the same uuid simultaneously; a host-side process modifying files in /data/coolify/ssh; silently corrupting network storage; a model whose private_key attribute changed between put and the read-back.","commonSituations":"Duplicate Coolify control planes sharing one data dir; scripts editing key files on the host; flaky NFS/FUSE caching returning stale content on immediate re-read.","solutions":["Verify only one Coolify instance/worker writes to this ssh-keys storage; split data dirs per instance.","Move storage off network filesystems to local disk (the read-back compare assumes coherent local IO).","Retry the save — the corrupt file was already deleted by the guard."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $privateKey->storeInFileSystem();\n} catch (\\Exception $e) {\n    if (str_contains($e->getMessage(), 'content verification failed')) {\n        // corrupt file was auto-deleted; rule out concurrent writers (second instance / host scripts), then retry\n    }\n    throw $e;\n}","preventionTips":["Run exactly one Coolify control plane per data directory — the byte-compare guard catches dueling writers.","Never edit ssh_key@* files on the host; let the model own the full write/verify cycle."],"tags":["coolify","ssh-key","file-storage","concurrency","data-integrity"],"backgroundTag":"file-write-verification-failed","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}