coollabsio / coolify

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

[Bug]: When the SSH key is set for a non root user the installation fails #2945

Open peaklabs-dev opened 4 months ago

peaklabs-dev commented 4 months ago

Description

I have my server running with a user named test (not root) and when I install coolify using the manual install and create a key like this:


sudo ssh-keygen -f /data/coolify/ssh/keys/id.USERNAME@host.docker.internal -t ed25519 -N '' -C USERNAME@coolify

I get this error when inspecting the container: docker logs coolify

Brought to you by serversideup.net
--------------------------------------------------------------------

To support Server Side Up projects visit:
https://serversideup.net/sponsor
-------------------------------------
GID/UID
-------------------------------------

User uid:    9999
User gid:    9999
-------------------------------------

πŸ”“ SSL_MODE has been DISABLED, setting the web server to work in HTTP only...
πŸƒβ€β™‚οΈ Checking for Laravel automations...
πŸ” Linking the storage...

   ERROR  The [public/storage] link already exists.

   INFO  Nothing to migrate.

[25-Jul-2024 20:12:14] NOTICE: fpm is running, pid 99
[25-Jul-2024 20:12:14] NOTICE: ready to handle connections
[25-Jul-2024 20:12:14] NOTICE: systemd monitor interval set to 10000ms

   INFO  Seeding database.

Running in self-hosted mode.
Checking localhost key.
No SSH key found for the Coolify host machine (localhost).
Please generate one and save it in /data/coolify/ssh/keys/id.root@host.docker.internal
Then try to install again.
s6-rc: warning: unable to start service init-seeder: command exited 1
/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.
prog: fatal: stopping the container.
[25-Jul-2024 20:12:15] NOTICE: Terminating ...
[25-Jul-2024 20:12:15] NOTICE: exiting, bye-bye!

The Problem is the key needs to be called root@host.docker.internal and not USERNAME@host.docker.internal and afterwards in coolify I have to change the username anyway but this case should be handled correctly. Otherwise I have to switch keys and user in coolify and always create tow ssh keys one for my actual user which works for the connection and one for root just to get coolify to install.

Minimal Reproduction (if possible, example repository)

  1. Install Coolify manually from https://coolify.io/docs/installation#manually.
  2. Use a sudo user that is not root and then add an ssh key for it Installation, it will fail if there is no root@ ssh key and only a username@... ssh key!

Exception or Error

No response

Version

v318

Cloud?

LaurenceJJones commented 4 months ago

Just to add some debugging as I am also interested in this, the seeder function is only looking for this key and if it cannot find it will fail

https://github.com/coollabsio/coolify/blob/f76d45b8262fb1da03846ae01ba81c51d79efe08/database/seeders/ProductionSeeder.php#L71-L72

Seems there are multiple pit falls, as since we assume the key is for root it also is hard coded to use "root" when logging in.

https://github.com/coollabsio/coolify/blob/f76d45b8262fb1da03846ae01ba81c51d79efe08/database/seeders/ProductionSeeder.php#L97

You could just symlink the file to the file coolify expects, but the issue above will trigger as it expects root as user.

peaklabs-dev commented 4 months ago

Yes, there really needs to be a way to set the username before deployment and root should not be hardcoded as we can change the username in the UI after the fact and also add the users ssh key via the UI. Fix idea: Maybe create an environment variable like COOLIFY_OWNER that we can set in the .env file during deployment and specify as a flag with the install script so that coolify uses this variable instead of the hardcoded root and for SSH keys, it may not check for a user, just use the available key, or ask during installation which key to use if there are multiple.

Bilge commented 3 weeks ago

Maybe related to #4245.