fix(ssl): remove caCert even if it is a folder by accident

This commit is contained in:
peaklabs-dev
2025-02-07 18:28:58 +01:00
parent 6a52f51851
commit 836006798f
3 changed files with 9 additions and 11 deletions

View File

@@ -20,10 +20,10 @@ class InstallDocker
throw new \Exception('Server OS type is not supported for automated installation. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://coolify.io/docs/installation#manually">documentation</a>.'); throw new \Exception('Server OS type is not supported for automated installation. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://coolify.io/docs/installation#manually">documentation</a>.');
} }
if (! SslCertificate::where('server_id', $server->id)->exists()) { if (! SslCertificate::where('server_id', $server->server_id)->where('is_ca_certificate', true)->exists()) {
$serverCert = SslHelper::generateSslCertificate( $serverCert = SslHelper::generateSslCertificate(
commonName: 'Coolify CA Certificate', commonName: 'Coolify CA Certificate',
serverId: $server->id, serverId: $server->server_id,
isCaCertificate: true, isCaCertificate: true,
validityDays: 15 * 365 validityDays: 15 * 365
); );
@@ -33,6 +33,7 @@ class InstallDocker
"mkdir -p $caCertPath", "mkdir -p $caCertPath",
"chown -R 9999:root $caCertPath", "chown -R 9999:root $caCertPath",
"chmod -R 700 $caCertPath", "chmod -R 700 $caCertPath",
"rm -rf $caCertPath/coolify-ca.crt",
"echo '{$serverCert->ssl_certificate}' > $caCertPath/coolify-ca.crt", "echo '{$serverCert->ssl_certificate}' > $caCertPath/coolify-ca.crt",
"chmod 644 $caCertPath/coolify-ca.crt", "chmod 644 $caCertPath/coolify-ca.crt",
]); ]);

View File

@@ -49,10 +49,7 @@ class Advanced extends Component
public function loadCaCertificate() public function loadCaCertificate()
{ {
$this->caCertificate = SslCertificate::where('server_id', $this->server->id) $this->caCertificate = SslCertificate::where('server_id', $this->server->server_id)->where('is_ca_certificate', true)->first();
->where('resource_type', null)
->where('resource_id', null)
->first();
if ($this->caCertificate) { if ($this->caCertificate) {
$this->certificateContent = $this->caCertificate->ssl_certificate; $this->certificateContent = $this->caCertificate->ssl_certificate;
@@ -129,7 +126,7 @@ class Advanced extends Component
"mkdir -p $caCertPath", "mkdir -p $caCertPath",
"chown -R 9999:root $caCertPath", "chown -R 9999:root $caCertPath",
"chmod -R 700 $caCertPath", "chmod -R 700 $caCertPath",
"rm -f $caCertPath/coolify-ca.crt", "rm -rf $caCertPath/coolify-ca.crt",
"echo '{$this->certificateContent}' > $caCertPath/coolify-ca.crt", "echo '{$this->certificateContent}' > $caCertPath/coolify-ca.crt",
"chmod 644 $caCertPath/coolify-ca.crt", "chmod 644 $caCertPath/coolify-ca.crt",
]); ]);

View File

@@ -13,9 +13,9 @@ class CaSslCertSeeder extends Seeder
{ {
Server::chunk(200, function ($servers) { Server::chunk(200, function ($servers) {
foreach ($servers as $server) { foreach ($servers as $server) {
$existingCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first(); $existingCaCert = SslCertificate::where('server_id', $server->server_id)->where('is_ca_certificate', true)->first();
if (! $existingCert) { if (! $existingCaCert) {
$caCert = SslHelper::generateSslCertificate( $caCert = SslHelper::generateSslCertificate(
commonName: 'Coolify CA Certificate', commonName: 'Coolify CA Certificate',
serverId: $server->id, serverId: $server->id,
@@ -23,7 +23,7 @@ class CaSslCertSeeder extends Seeder
validityDays: 15 * 365 validityDays: 15 * 365
); );
} else { } else {
$caCert = $existingCert; $caCert = $existingCaCert;
} }
$caCertPath = config('constants.coolify.base_config_path').'/ssl/'; $caCertPath = config('constants.coolify.base_config_path').'/ssl/';
@@ -31,7 +31,7 @@ class CaSslCertSeeder extends Seeder
"mkdir -p $caCertPath", "mkdir -p $caCertPath",
"chown -R 9999:root $caCertPath", "chown -R 9999:root $caCertPath",
"chmod -R 700 $caCertPath", "chmod -R 700 $caCertPath",
"rm -f $caCertPath/coolify-ca.crt", "rm -rf $caCertPath/coolify-ca.crt",
"echo '{$caCert->ssl_certificate}' > $caCertPath/coolify-ca.crt", "echo '{$caCert->ssl_certificate}' > $caCertPath/coolify-ca.crt",
"chmod 644 $caCertPath/coolify-ca.crt", "chmod 644 $caCertPath/coolify-ca.crt",
]); ]);