coollabsio / coolify

An open-source & self-hostable Heroku / Netlify / Vercel alternative.
https://coolify.io
Apache License 2.0
34.98k stars 1.93k forks source link

[Bug]: Terminal Does not work on server using Cloudflare Tunnel #3656

Open ejscheepers opened 2 months ago

ejscheepers commented 2 months ago

Error Message and Logs

PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/host/usr/local/sbin:/host/usr/local/bin:/host/usr/sbin:/host/usr/bin:/host/sbin:/host/bin && docker exec -it ekg4w8gg0w00ksoog4kk8w8k-081615499702 sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n "$SHELL" ]; then exec $SHELL; else sh; fi' command -v clear >/dev/null 2>&1 && clear command-line line 0: invalid quotes

Steps to Reproduce

  1. Enable Cloudflare Tunnel on server and completed setup
  2. Everything works, I can add resources, build etc
  3. Try to use Coolify Terminal to access and get the error

    PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/host/usr/local/sbin:/host/usr/local/bin:/host/usr/sbin:/host/usr/bin:/host/sbin:/host/bin && docker exec -it ekg4w8gg0w00ksoog4kk8w8k-081615499702 sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n "$SHELL" ]; then exec $SHELL; else sh; fi' command -v clear >/dev/null 2>&1 && clear command-line line 0: invalid quotes Screenshot 2024-10-01 at 14 15 17

Example Repository URL

No response

Coolify Version

v4.0.0-beta.347

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Ubuntu 22.04.5 LTS

Additional Information

No response

djsisson commented 2 months ago

in your tunnel, did you point ot localhost 8000 (this wont work for terminal) or localhost 80 (this will work)

ejscheepers commented 2 months ago

In my tunnel I only point to localhost 22 as per the documentation: https://coolify.io/docs/knowledge-base/cloudflare/tunnels/#setup-cloudflared

Do I specifically need to add localhost 80 for the terminal?

djsisson commented 2 months ago

@ejscheepers the ssh is for ssh to vps, nothing to do with the website,

how are you accessing teh website?

ejscheepers commented 2 months ago

Yes I set up ssh to vps tunnel for Coolify to manage my server.

Now I want to use the terminal in Coolify Dashboard and then I get that error in the terminal in Coolify Dashboard.

It works for other servers that don’t use Cloudflare Tunnels though.

[image: Eugene Scheepers] http://eugenescheepers.com Eugene Scheepers Entrepreneur eugenescheepers.com

On October 1, 2024 at 4:30 PM, Darren Sisson @.***) wrote:

@ejscheepers https://github.com/ejscheepers the ssh is for ssh to vps, nothing to do with the website, how are you accessing teh website? — Reply to this email directly, view it on GitHub https://github.com/coollabsio/coolify/issues/3656#issuecomment-2386132986, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOVUN44OXDQPZTUHK6WFWTZZKWXRAVCNFSM6AAAAABPFODUB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBWGEZTEOJYGY . You are receiving this because you were mentioned.Message ID: @.***>

djsisson commented 2 months ago

@ejscheepers you jsut need to add a tunnel entry for the coolify website if it isnt already covered by a wildcard

e.g coolify domain.com http localhost 80

ejscheepers commented 2 months ago

Okay can I just clarify:

I self-host coolify on vps at servers.domain.com (this is completely separate from the server I am trying to access using Cloudflare Tunnels)

The server I am trying to access using Coolify terminal is at ssh.domain.com

It is currently set up like this with Cloudflare Tunnel:

ssh.domain.com ssh localhost 22

Do I need to add tunnel for ssh.domain.com:

ssh.domain.com http localhost 80

Or something else?

[image: Eugene Scheepers] http://eugenescheepers.com Eugene Scheepers Entrepreneur eugenescheepers.com

On October 1, 2024 at 4:36 PM, Darren Sisson @.***) wrote:

@ejscheepers https://github.com/ejscheepers you jsut need to add a tunnel entry for the coolify website if it isnt already covered by a wildcard e.g coolify domain.com http localhost 80 — Reply to this email directly, view it on GitHub https://github.com/coollabsio/coolify/issues/3656#issuecomment-2386162638, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOVUN23DQPCELPCLTQLM7DZZKXPBAVCNFSM6AAAAABPFODUB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBWGE3DENRTHA . You are receiving this because you were mentioned.Message ID: @.***>

djsisson commented 2 months ago

@ejscheepers

ok now it makes sense, you are only able to use the ssh domain using a cloudflared proxy command (this owuld usually be added to your ssh config)

there is currently no way to directly connect to a seperate server behind a tunnel from coolify

there are work arounds however

are both your servers on teh same private network? or can you put them on the same private network, then you would just ssh to the private ip

ideally the coolify image would come with the cloudflared binary builtin, but unfortunately it doesn't .

so the quick hack is on your coolify vps install cloudflared and setup a proxy command to ssh.domain.com then run ssh -L 0.0.0.0:222:localhost:22 sshproxyhost then in coolify you would connect to your server inside the tunnel at host.docker.internal with port 222

andrasbacsai commented 2 months ago

I will try to reproduce it. It is just simply cloudflared running (configured with Coolify) with or without DNS proxy set in CF?

ejscheepers commented 2 months ago

Yes, Cloudflared running (setup in Coolify, accessing websites works perfectly) and the CNAME record in CF is proxied.

[image: Eugene Scheepers] http://eugenescheepers.com Eugene Scheepers Entrepreneur eugenescheepers.com

On October 2, 2024 at 10:02 AM, Andras Bacsai @.***) wrote:

I will try to reproduce it. It is just simply cloudflared running (configured with Coolify) with or without DNS proxy set in CF? — Reply to this email directly, view it on GitHub https://github.com/coollabsio/coolify/issues/3656#issuecomment-2387860439, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOVUN4G6YVBSLSHGHSIPM3ZZOSCLAVCNFSM6AAAAABPFODUB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBXHA3DANBTHE . You are receiving this because you were mentioned.Message ID: @.***>

andrasbacsai commented 2 months ago

I can reproduce it, but I have no idea where it comes from. Probably because of the ProxyCommand of cloudflared tunnel. I will investigate and let you know.

djsisson commented 2 months ago

i never knew you included cloudflared....

so i jsut tested it manually running this in the coolify terminal

ssh -o ProxyCommand="cloudflared access ssh --hostname SSHHOSTNAME.com" -i /var/www/html/storage/app/ssh/ssh_key@KEYNAME

and it went straight to the terminal

so my i assume it is jsut related to quotes, either ' where should be " or other way around

nathanialhenniges commented 1 month ago

Is there any update on this as well it's still doing it. I even tired to change the env too

ERMINAL_PROTOCOL=wss TERMINAL_HOST=termctrl.example.com TERMINAL_PORT=443

djsisson commented 1 month ago

@nathanialhenniges what are you using for your subdomain in your tunnel? you only need to then use localhost 80 and have the subdomain match what you use in settings -> instance domain in coolify

nathanialhenniges commented 1 month ago

ssh.example.com

@nathanialhenniges what are you using for your subdomain in your tunnel? you only need to then use localhost 80 and have the subdomain match what you use in settings -> instance domain in coolify

ssh.example.com

djsisson commented 1 month ago

@nathanialhenniges can you clairfy which bit isnt working, you cant use the terminal in the website, or you cant connect to a remote server thats already behind a tunnel?

which bit are you stuck on

nathanialhenniges commented 1 month ago

@nathanialhenniges can you clairfy which bit isnt working, you cant use the terminal in the website, or you cant connect to a remote server thats already behind a tunnel?

which bit are you stuck on

the terminal on the website. Really want to be able to use it. timeout 7200

djsisson commented 1 month ago

@nathanialhenniges ok what do you have in your tunnel to access coolify website

nathanialhenniges commented 1 month ago

@nathanialhenniges ok what do you have in your tunnel to access coolify website

I use Cloudflare Tunnel

And I just set the env TERMINAL_HOST=ssh.example.com and it is trying something before it just always failed

WebSocket connection to 'wss://ctrl.example.com/terminal/ws' failed:

djsisson commented 1 month ago

@nathanialhenniges on your cf tunnel page... what are you using to access the website............. is it localhost : 8000 ??????

djsisson commented 1 month ago

@nathanialhenniges to be clear you do not nneed to set any env for this

just set this Image and then match the subdomain in instance settings Image thats it, then traefik will take care of the websockets for you

nathanialhenniges commented 1 month ago

Well I did not want to use traefik as am trying to save resources

nathanialhenniges commented 1 month ago

@nathanialhenniges on your cf tunnel page... what are you using to access the website............. is it localhost : 8000 ??????

Ya its connected to 8000

djsisson commented 1 month ago

@nathanialhenniges then add 2 more entries

same subdomain but add path

/app to be localhost:6001 /terminal/ws to be localhost:6002

nathanialhenniges commented 1 month ago

Image

djsisson commented 1 month ago

need to be same as coolify subdomain

djsisson commented 1 month ago

if youre doing it that way did u reinstall coolify? after chaning env

nathanialhenniges commented 1 month ago

if youre doing it that way did u reinstall coolify? after chaning env

I always run the install script again. I was just following the docs.

djsisson commented 1 month ago

ok but if u set terminal to be termctrl domain why did u set env to be something else? this is making more work for yourself than is needed

nathanialhenniges commented 1 month ago

https://coolify.io/docs/knowledge-base/cloudflare/tunnels#post-setup

nathanialhenniges commented 1 month ago

ok but if u set terminal to be termctrl domain why did u set env to be something else? this is making more work for yourself than is needed

I know. I could just have traefik handle all of it. But saving that little processing is nice.

djsisson commented 1 month ago

well what are you env for pusher and terminal right now

nathanialhenniges commented 1 month ago

Holy shit it worked now.

nathanialhenniges commented 1 month ago

Is it normal to not be able to connect to the containers? "command-line line 0: invalid quotes"

djsisson commented 1 month ago

@nathanialhenniges no, where is it trying to connect to?

nathanialhenniges commented 1 month ago

@nathanialhenniges no, where is it trying to connect to?

https://github.com/user-attachments/assets/2b698dae-7d43-47cc-89b6-addd8cab3032

djsisson commented 1 month ago

in your dev console,

nathanialhenniges commented 1 month ago

in your dev console,

Oh am sorry. Image It displays this in the websocket nothing really in the dev console other then chrome ext thing.

djsisson commented 1 month ago

yeah ProxyCommand needs to be inside double quotes so -o "ProxyCommand=....."

so im guessing terminal works but not for any servers behind ssh tunnel

what version are you on?

djsisson commented 1 month ago

i noticed all the functions in SshMultiplexingHelper have the cloudflared command inside singlequotes with the proxycommand part inside double, except the generateSshCommand where it is the other way around

so all functions are like this https://github.com/coollabsio/coolify/blob/5d62a46a16f252e6ece4d25fe56838e99883d91b/app/Helpers/SshMultiplexingHelper.php#L106

except generateSshCommand () https://github.com/coollabsio/coolify/blob/5d62a46a16f252e6ece4d25fe56838e99883d91b/app/Helpers/SshMultiplexingHelper.php#L136

not sure if that is the bug?

nathanialhenniges commented 1 month ago

yeah ProxyCommand needs to be inside double quotes so -o "ProxyCommand=....."

so im guessing terminal works but not for any servers behind ssh tunnel

what version are you on?

Whater ever the latest released one is 3 weeks ago.

Schmedu commented 1 month ago

I stumbled across the same issue 'command line line 0: invalid quotes', also with a server behind a cloudlfare tunnel, but I have the cloud solution.

SerjoA commented 1 month ago

i actually stumbled upon the same issue but when i switched to safari instead of chrome - the terminal worked for me this issue happened to me with previous laravel applications which used web sockets - as soon as i switched browsers it worked.

Schmedu commented 2 weeks ago

i actually stumbled upon the same issue but when i switched to safari instead of chrome - the terminal worked for me this issue happened to me with previous laravel applications which used web sockets - as soon as i switched browsers it worked.

Does not work for me.

@andrasbacsai are there any updates on this? I would really love to use the terminal over the web UI 😅

Tripolt commented 1 week ago

Same problem here ☝️