Skip to content

Commit 75f266f

Browse files
committed
fix: cloudflare tunnel with new multiplexing feature
1 parent 90fd0eb commit 75f266f

File tree

9 files changed

+21
-11
lines changed

9 files changed

+21
-11
lines changed

.env.development.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ APP_KEY=
66
APP_URL=http://localhost
77
APP_PORT=8000
88
APP_DEBUG=true
9-
MUX_ENABLED=false
9+
SSH_MUX_ENABLED=false
1010

1111
# PostgreSQL Database Configuration
1212
DB_DATABASE=coolify

app/Livewire/Boarding/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function installServer()
282282
public function validateServer()
283283
{
284284
try {
285-
config()->set('coolify.mux_enabled', false);
285+
config()->set('constants.ssh.mux_enabled', false);
286286

287287
// EC2 does not have `uptime` command, lol
288288
instant_remote_process(['ls /'], $this->createdServer, true);

app/Models/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ public function isSwarmWorker()
967967

968968
public function validateConnection()
969969
{
970-
config()->set('coolify.mux_enabled', false);
970+
config()->set('constants.ssh.mux_enabled', false);
971971

972972
$server = Server::find($this->id);
973973
if (! $server) {

bootstrap/helpers/proxy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ function generate_default_proxy_configuration(Server $server)
137137
'external' => true,
138138
];
139139
});
140+
// TODO: This should not be null on new servers, but it is.
141+
ray($proxy_type);
140142
if ($proxy_type === ProxyTypes::TRAEFIK->value) {
141143
$labels = [
142144
'traefik.enable=true',

bootstrap/helpers/remoteProcess.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ function generateSshCommand(Server $server, string $command)
166166
// Check if multiplexing is enabled
167167
$muxEnabled = config('constants.ssh.mux_enabled', true);
168168
// ray('SSH Multiplexing Enabled:', $muxEnabled)->blue();
169-
170169
if ($muxEnabled) {
171170
// Always use multiplexing when enabled
172171
$muxSocket = "/var/www/html/storage/app/ssh/mux/{$server->muxFilename()}";
@@ -212,7 +211,11 @@ function ensureMultiplexedConnection(Server $server)
212211
}
213212

214213
$muxSocket = "/var/www/html/storage/app/ssh/mux/{$server->muxFilename()}";
215-
$checkCommand = "ssh -O check -o ControlPath=$muxSocket {$server->user}@{$server->ip} 2>/dev/null";
214+
$checkCommand = "ssh -O check -o ControlPath=$muxSocket ";
215+
if (data_get($server, 'settings.is_cloudflare_tunnel')) {
216+
$checkCommand .= '-o ProxyCommand="/usr/local/bin/cloudflared access ssh --hostname %h" ';
217+
}
218+
$checkCommand .= " {$server->user}@{$server->ip}";
216219

217220
$process = Process::run($checkCommand);
218221

@@ -233,8 +236,12 @@ function ensureMultiplexedConnection(Server $server)
233236
$serverInterval = config('constants.ssh.server_interval');
234237
$muxPersistTime = config('constants.ssh.mux_persist_time');
235238

236-
$establishCommand = "ssh -fNM -o ControlMaster=auto -o ControlPath=$muxSocket -o ControlPersist={$muxPersistTime} "
237-
."-i {$privateKeyLocation} "
239+
$establishCommand = "ssh -fNM -o ControlMaster=auto -o ControlPath=$muxSocket -o ControlPersist={$muxPersistTime} ";
240+
241+
if (data_get($server, 'settings.is_cloudflare_tunnel')) {
242+
$establishCommand .= '-o ProxyCommand="/usr/local/bin/cloudflared access ssh --hostname %h" ';
243+
}
244+
$establishCommand .= "-i {$privateKeyLocation} "
238245
.'-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
239246
.'-o PasswordAuthentication=no '
240247
."-o ConnectTimeout=$connectionTimeout "
@@ -305,7 +312,7 @@ function instant_remote_process(Collection|array $command, Server $server, bool
305312
$end_time = microtime(true);
306313

307314
$execution_time = ($end_time - $start_time) * 1000; // Convert to milliseconds
308-
// ray('SSH command execution time:', $execution_time.' ms')->orange();
315+
ray('SSH command execution time:', $execution_time.' ms')->orange();
309316

310317
$output = trim($process->output());
311318
$exitCode = $process->exitCode();

config/constants.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
'contact' => 'https://coolify.io/docs/contact',
77
],
88
'ssh' => [
9-
'mux_enabled' => env('SSH_MUX_ENABLED', true),
9+
// Using MUX
10+
'mux_enabled' => env('MUX_ENABLED', env('SSH_MUX_ENABLED', true), true),
1011
'mux_persist_time' => env('SSH_MUX_PERSIST_TIME', '1h'),
1112
'connection_timeout' => 10,
1213
'server_interval' => 20,

config/coolify.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
'self_hosted' => env('SELF_HOSTED', true),
88
'waitlist' => env('WAITLIST', false),
99
'license_url' => 'https://licenses.coollabs.io',
10-
'mux_enabled' => env('MUX_ENABLED', true),
1110
'dev_webhook' => env('SERVEO_URL'),
1211
'is_windows_docker_desktop' => env('IS_WINDOWS_DOCKER_DESKTOP', false),
1312
'base_config_path' => env('BASE_CONFIG_PATH', '/data/coolify'),

docker-compose.prod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ services:
4848
- PUSHER_APP_SECRET
4949
- AUTOUPDATE
5050
- SELF_HOSTED
51+
- SSH_MUX_ENABLED
5152
- SSH_MUX_PERSIST_TIME
5253
- FEEDBACK_DISCORD_WEBHOOK
5354
- WAITLIST

docker-compose.windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
- PUSHER_APP_SECRET
4646
- AUTOUPDATE=true
4747
- SELF_HOSTED=true
48-
- MUX_ENABLED=false
48+
- SSH_MUX_ENABLED=false
4949
- IS_WINDOWS_DOCKER_DESKTOP=true
5050
ports:
5151
- "${APP_PORT:-8000}:80"

0 commit comments

Comments
 (0)