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

make it possible to run occ as root #33545

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

make it possible to run occ as root #33545

wants to merge 3 commits into from

Conversation

karlitschek
Copy link
Member

@karlitschek karlitschek commented Aug 15, 2022

make it possible to run as root

To do

  • Start non privileged child process
  • Handle exit codes
  • Handle STDIN/STDOUT/STDERR streams

@karlitschek
Copy link
Member Author

@PVince81 PVince81 added the 3. to review Waiting for reviews label Aug 15, 2022
@PVince81 PVince81 added this to the Nextcloud 25 milestone Aug 15, 2022
occ Outdated
Comment on lines 11 to 13
if (posix_getuid() == 0){
$command = implode (' ', $argv);
echo(shell_exec('sudo -u www-data '.$command));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (posix_getuid() == 0){
$command = implode (' ', $argv);
echo(shell_exec('sudo -u www-data '.$command));
if (posix_getuid() === 0) {
$command = implode (' ', $argv);
echo shell_exec('sudo -u www-data ' . $command);

return code is being killed

Copy link
Member

Choose a reason for hiding this comment

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

occ Outdated
Comment on lines 11 to 13
if (posix_getuid() == 0){
$command = implode (' ', $argv);
echo(shell_exec('sudo -u www-data '.$command));
Copy link
Member

Choose a reason for hiding this comment

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

occ Outdated
// make it possible to run as root
if (posix_getuid() == 0){
$command = implode (' ', $argv);
echo(shell_exec('sudo -u www-data '.$command));
Copy link
Member

Choose a reason for hiding this comment

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

www-data might not be the default user name for the HTTP server though, mostly only Debian-based systems use that. RedHat-based systems or ArchLinux use an user named http by default.

Also, does this forwards environment variables?

Copy link
Member

Choose a reason for hiding this comment

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

what we do in other places is read the user name from the config file, basically the owner of "config/config.php" and use that to check if the correct user is being used

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense unless config_is_read_only is used, then the config file owner could be something irrelevant such as root, as long as the http server user has read access.

Copy link
Member

Choose a reason for hiding this comment

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

Well in worst case you can not use the root shortcut then and need to manually sudo -u yourwebserver-user occ ?

@skjnldsv skjnldsv mentioned this pull request Aug 18, 2022
This was referenced Aug 24, 2022
This was referenced Sep 6, 2022
@skjnldsv skjnldsv mentioned this pull request Sep 15, 2022
This was referenced Sep 20, 2022
@blizzz blizzz modified the milestones: Nextcloud 25, Nextcloud 26 Sep 22, 2022
@blizzz blizzz mentioned this pull request Feb 1, 2023
@skjnldsv skjnldsv mentioned this pull request Feb 23, 2023
@blizzz blizzz mentioned this pull request Mar 7, 2023
@blizzz blizzz modified the milestones: Nextcloud 26, Nextcloud 27 Mar 9, 2023
This was referenced May 3, 2023
@skjnldsv skjnldsv removed this from the Nextcloud 27 milestone May 9, 2023
@blizzz blizzz added this to the Nextcloud 29 milestone Nov 23, 2023
This was referenced Mar 12, 2024
@Altahrim Altahrim mentioned this pull request Mar 20, 2024
@AndyScherzinger AndyScherzinger removed this from the Nextcloud 29 milestone Mar 22, 2024
@AndyScherzinger
Copy link
Member

@karlitschek I believe we can close this PR since it was originally planned/needed as a pre-requisite for Nc Guard, right?

make it possible to run as root

Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
@susnux susnux added this to the Nextcloud 30 milestone Apr 18, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Jul 27, 2024
This was referenced Jul 30, 2024
This was referenced Aug 5, 2024
@AndyScherzinger AndyScherzinger removed this from the Nextcloud 30 milestone Aug 7, 2024
@skjnldsv skjnldsv closed this Aug 14, 2024
@karlitschek

This comment was marked as resolved.

@karlitschek karlitschek reopened this Aug 14, 2024
@skjnldsv

This comment was marked as resolved.

@ChristophWurst
Copy link
Member

Finding the right user is doable from config.php ownership guessing.

The tricky part is STDIN/STDOUT/STDERR handling. Neither with shell_exec nor proc_open I was able to connect the parent process pipes with the child process. shell_exec makes the parent block when occ asks for input (e.g. when you make a typo or when it needs confirmation).

I've pushed some fixes that make this work on a non-Debian system too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress feature: occ stale Ticket or PR with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants