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

Merged
merged 1 commit into from
Feb 27, 2025
Merged

make it possible to run occ as root #33545

merged 1 commit into from
Feb 27, 2025

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
@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 Aug 7, 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.

@skjnldsv skjnldsv added this to the Nextcloud 32 milestone Jan 30, 2025
@susnux
Copy link
Contributor

susnux commented Feb 27, 2025

@ChristophWurst I pushed a commit which should resolve this.
Basically lets do it like every other program on Linux and just use setuid and setgid to make the current process owned by the config.php user.

Also there is no need for a fallback, because if there is no fileowner of the config, then console.php will fail because it checks that the current user is the fileowner...

@susnux susnux added 3. to review Waiting for reviews and removed 2. developing Work in progress stale Ticket or PR with no recent activity labels Feb 27, 2025
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

Tested and works. Very nice solution, @susnux 👏

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Files belong to my own user. Works fine here with:

  • php occ
  • sudo php occ
  • sudo -u nickvergessen php occ

So sounds good to me

@nickvergessen
Copy link
Member

I will then squash it and we can merge + backport it, looks straight forward enough :-O

Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux merged commit 8f28fa2 into master Feb 27, 2025
121 checks passed
@susnux susnux deleted the occ-as-root branch February 27, 2025 21:21
@nickvergessen
Copy link
Member

/backport to stable31

@nickvergessen
Copy link
Member

/backport to stable30

@karlitschek
Copy link
Member Author

Wohoooo. Feeling like a community contributor now 😀

@karlitschek
Copy link
Member Author

Ok. Nothing of my code is left. Bit still cool 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews feature: occ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants