Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run hbbr and hbbs not as root #365

Open
Kurgan- opened this issue Feb 4, 2024 · 5 comments
Open

Run hbbr and hbbs not as root #365

Kurgan- opened this issue Feb 4, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@Kurgan-
Copy link

Kurgan- commented Feb 4, 2024

I have just installed the debian packages rustdesk-server-hbbr_1.1.10-3_amd64.deb and rustdesk-server-hbbs_1.1.10-3_amd64.deb on a Debian 11 vm.

Everything works flawlessly, but I have seen that the executables are run as the root user.

I'd like to have them run as a dedicated non privileged user instead of root.

Since the program does not make use (at least by default) of lower ports, even a normal user can run it without issues.

I have modified the systemd units to make it run with a "rustdesk" user and group I have created, I have chowned the /var/log/rustdesk and /var/lib/rustdesk directories (and their contents) and indeed the server works fine without being root.

This allows for a little better security overall in case of some RCE flaw in hbbr and hbbs.

@Kurgan- Kurgan- added the enhancement New feature or request label Feb 4, 2024
@paspo
Copy link
Contributor

paspo commented Feb 4, 2024

Good idea!
Can you share your work with the community by creating a PR with your modification?

@Kurgan-
Copy link
Author

Kurgan- commented Feb 4, 2024

I'm not familiar with github so I'll have to study on how to make it.

@paspo
Copy link
Contributor

paspo commented Feb 4, 2024

Systemd units are here: hbbr and hbbs

You should also consider user creation when the package is installed. some docs

@JulianAtkins
Copy link

Running as root is a horrible idea.

You can easily run hbbr and hbbs as normal users. You can even use my super awesome systemd service, make sure to modify the user/group and paths.

In this case I created a normal user:
useradd -m hbb

Uncompressed rustdesk archive under
/home/hbb

Which created the subdirectory amd64 from the archive as:
/home/hbb/amd64

Then created two systemd services:

[Unit]
Description=HBBR Service
Requires=systemd-modules-load.service
After=systemd-modules-load.service

[Service]
Type=simple
Restart=on-failure
User=hbb
Group=hbb
WorkingDirectory=/home/hbb/amd64
ExecStart=/home/hbb/amd64/hbbr
StandardOutput=append:/home/hbb/amd64/relayserver.log
StandardError=append:/home/hbb/amd64/relayserver.error

[Install]
WantedBy=multi-user.target
[Unit]
Description=HBBS Service
Requires=systemd-modules-load.service
After=systemd-modules-load.service

[Service]
Type=simple
Restart=on-failure
User=hbb
Group=hbb
WorkingDirectory=/home/hbb/amd64
ExecStart=/home/hbb/amd64/hbbs
StandardOutput=append:/home/hbb/amd64/signalserver.log
StandardError=append:/home/hbb/amd64/signalserver.error

[Install]
WantedBy=multi-user.target

Finally, if you are using Alma, Rocky or Oracle Linux (derivatives of RHEL) then you also need to give some extra permissions to SELinux, here is the SELinux module with the required permissions:


module hbb 1.3;

require {
	type init_t;
	type user_home_t;
	class file { ioctl append create execute execute_no_trans lock map open read write };
}

#============= init_t ==============

allow init_t user_home_t:file { execute execute_no_trans lock map open read write };
allow init_t user_home_t:file create;
allow init_t user_home_t:file append;
allow init_t user_home_t:file ioctl;

I hope this helps others get more secure and NEVER run as root !!! woot !!!

@rustdesk
Copy link
Owner

rustdesk commented Feb 16, 2024

BTW, if you run with pm2, it is not root either. I never run hbbs/hbbr as root.

https://rustdesk.com/docs/en/self-host/rustdesk-server-oss/install/#option-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants