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

task: add check if install.sh was run with root privileges #3069

Closed
wants to merge 5 commits into from

Conversation

LvckyAPI
Copy link
Contributor

@LvckyAPI LvckyAPI commented May 21, 2024

Story

Currently, it's possible to run the install.sh without root privileges.
This could cause misunderstandings if errors are thrown while running the script without root.

I added a check, if the script was run with root privileges.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link
Collaborator

@aldy505 aldy505 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against this. In fact, I would recommend this since regular Docker installation requires higher privileges than regular Linux user. But, what should we do with people that don't have root access and currently are running sentry self-hosted normally? Should we add additional environment variable or a CLI flag that states they're aware about what they're doing?

So, it would be something like:

./install.sh --explicit-no-root-access
# or
EXPLICIT_NO_ROOT_ACCESS=true ./install.sh

install.sh Outdated Show resolved Hide resolved
@BYK
Copy link
Member

BYK commented May 21, 2024

I'd just print a warning. I don't recall root being required from the old times 😅 If it is required we should also note in the docs too.

@LvckyAPI
Copy link
Contributor Author

LvckyAPI commented May 21, 2024

I'd just print a warning. I don't recall root being required from the old times 😅 If it is required we should also note in the docs too.

but in the most cases the installation fails if you don't run the script with root
For example today in Discord: https://discord.com/channels/621778831602221064/1242216895327899808

I think the idea from @aldy505 with the additional parameter or environment variable is great

@BYK
Copy link
Member

BYK commented May 21, 2024

Okay, turns out we do say you should use sudo here: https://github.com/getsentry/self-hosted?tab=readme-ov-file#using-linux

I'm +1 to the idea where we stop unless specifically overriden by a flag or env variable. The stopping can be a prompt too btw (you should be using sudo, are you sure you wanna continue?). Finally don't forget the CI env variable handling as mentioned earlier.

@LvckyAPI
Copy link
Contributor Author

Okay, turns out we do say you should use sudo here: https://github.com/getsentry/self-hosted?tab=readme-ov-file#using-linux

I'm +1 to the idea where we stop unless specifically overriden by a flag or env variable. The stopping can be a prompt too btw (you should be using sudo, are you sure you wanna continue?). Finally don't forget the CI env variable handling as mentioned earlier.

the idea with the prompt is great too

@LvckyAPI
Copy link
Contributor Author

I've added a check, if the environment variable CI is set to true, and I added a user prompt to ignor this warning

@LvckyAPI LvckyAPI requested a review from aldy505 May 21, 2024 10:15
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.01%. Comparing base (6032d98) to head (4bb32c2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3069   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files           3        3           
  Lines         203      203           
=======================================
  Hits          201      201           
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

install.sh Outdated Show resolved Hide resolved
Copy link
Collaborator

@aminvakil aminvakil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are running self-hosted without sudo without any problem, also git grep sudo does not show any command which needs sudo, although once it has run install.sh with sudo, it probably needs to get run with sudo next times as well, but sudo is not needed AFAICS.

Okay, turns out we do say you should use sudo here: https://github.com/getsentry/self-hosted?tab=readme-ov-file#using-linux

@BYK This just states that if you are using an environment variable and sudo together, put sudo before environment setting.

@LvckyAPI
Copy link
Contributor Author

LvckyAPI commented May 21, 2024

We are running self-hosted without sudo without any problem

For example: There is a new script https://github.com/getsentry/self-hosted/blob/master/install/update-docker-volume-permissions.sh#L9 which is updating permissions, and this won't work without root privileges or Permissions to this Folder.

@hubertdeng123
Copy link
Member

Root is not required to run the install script.

but in the most cases the installation fails if you don't run the script with root
For example today in Discord: https://discord.com/channels/621778831602221064/1242216895327899808

There should've been a warning printed out during the install script that the docker volume permissions were not updated properly. I believe that is the only part of the install script that may fail if permissions are not granted to the user. Is that what your install was also failing on @LvckyAPI?

@LvckyAPI
Copy link
Contributor Author

Is that what your install was also failing on @LvckyAPI?

Yeah, on every three instances that we run.

Before that we could run the install script relatively easily even without root, but not since then. And since it's documented everywhere that you should use sudo I thought, so that you don't spend ages looking for the problem and opening a ticket again and again, just force sudo and everything will work.

install.sh Outdated Show resolved Hide resolved
echo "You should be using sudo, are you sure you want to continue? [y/n]"
read -r answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "Continuing without sudo. This might cause issues later on."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of adding something along the lines of "You should know what you're doing as this might cause issues later on". But that might sound a bit demeaning for some people.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, into line 16?

Copy link
Collaborator

@aldy505 aldy505 May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but I don't think that's the proper wording 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to know what you're doing, because this could cause issues later on. ?

@aminvakil
Copy link
Collaborator

We are running self-hosted without sudo without any problem

For example: There is a new script https://github.com/getsentry/self-hosted/blob/master/install/update-docker-volume-permissions.sh#L9 which is updating permissions, and this won't work without root privileges or Permissions to this Folder.

@LvckyAPI You should be in docker group user to be able to run docker containers, create docker volumes, and so on.

Then you should be able to change docker volume permissions as well.

I would prefer to use "It's recommended to use.." rather than "You should be using.."

@aldy505 On the contrary we should not recommend to use root IMO. you should be in docker group to use docker anyway, and you will be fine with that to make all changes in docker containers, volumes, and so on.

Root is not required to run the install script.

but in the most cases the installation fails if you don't run the script with root
For example today in Discord: https://discord.com/channels/621778831602221064/1242216895327899808

There should've been a warning printed out during the install script that the docker volume permissions were not updated properly. I believe that is the only part of the install script that may fail if permissions are not granted to the user. Is that what your install was also failing on @LvckyAPI?

@hubertdeng123 I think we should run a container with root user, mounting this volumes, and change permissions with that container, instead of using root user on host.

@aldy505
Copy link
Collaborator

aldy505 commented May 27, 2024

I would prefer to use "It's recommended to use.." rather than "You should be using.."

@aldy505 On the contrary we should not recommend to use root IMO. you should be in docker group to use docker anyway, and you will be fine with that to make all changes in docker containers, volumes, and so on.

I'm thinking of having self-hosted as something that would be easier to set up for new people coming in. That's the reason on why I prefer that way. Stating to run sudo ./install.sh on the frontpage would also (hopefully) says that "you shouldn't really use rootless Docker on this one".

Root is not required to run the install script.

but in the most cases the installation fails if you don't run the script with root
For example today in Discord: https://discord.com/channels/621778831602221064/1242216895327899808

There should've been a warning printed out during the install script that the docker volume permissions were not updated properly. I believe that is the only part of the install script that may fail if permissions are not granted to the user. Is that what your install was also failing on @LvckyAPI?

@hubertdeng123 I think we should run a container with root user, mounting this volumes, and change permissions with that container, instead of using root user on host.

+1 I'd like to see this too.

@BYK
Copy link
Member

BYK commented May 27, 2024

I'm with @aminvakil here:

@hubertdeng123 I think we should run a container with root user, mounting this volumes, and change permissions with that container, instead of using root user on host

Much better solution and avoid the need for sudo, which is always a good thing.

@hubertdeng123
Copy link
Member

@hubertdeng123 I think we should run a container with root user, mounting this volumes, and change permissions with that container, instead of using root user on host

This does sound like a better approach, I can make a PR for this

@hubertdeng123
Copy link
Member

#3084 should fix this, so we don't need to run install script with root privileges

@LvckyAPI LvckyAPI closed this May 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants