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

nextcloud-occ: replace sudo with su #114966

Closed
wants to merge 1 commit into from
Closed

Conversation

eyJhb
Copy link
Member

@eyJhb eyJhb commented Mar 3, 2021

Motivation for this change

Systems that have 100% replaced sudo with doas would not work with the script as is.
This script just needs to be run as root, and then it would work just fine.

@adisbladis for the patch, just posting this here.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@aanderse
Copy link
Member

aanderse commented Mar 3, 2021

This script just needs to be run as root, and then it would work just fine.

That statement doesn't sound true to me at all... but I haven't actually checked. It seems like there would be a ton of implications if you run this as another user than currently intended...

@eyJhb
Copy link
Member Author

eyJhb commented Mar 3, 2021 via email

@aanderse
Copy link
Member

aanderse commented Mar 3, 2021

@eyJhb Sorry I misread that! LGTM 👍

@adisbladis
Copy link
Member

Reading the expression again I finally realised what this is for:
occ is added to environment.systemPackages and this is mean for being able to run occ from the shell while running it as the correct user.

Hard-coding sudo as the privilege dropping method isn't very friendly and whether this is even going to work or not highly depends on your sudo setup.
sudo isn't even the only privilege escalation/dropping method, there is also doas for example and this module implicitly depends on sudo being present which isn't always the case.

The current sudo-based approach will implicitly require root access for a majority of setups while changing the privilege dropping would make that explicit and require a user to call sudo occ.

I think changing this to su makes more sense as it makes less assumptions about the surrounding system, but it should have a changelog entry.

if [[ "$USER" != nextcloud ]]; then
sudo='exec /run/wrappers/bin/sudo -u nextcloud --preserve-env=NEXTCLOUD_CONFIG_DIR --preserve-env=OC_PASS'
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably needs a different approach: su doesn't take --preserve-env, so this would need to be --preserve-environment but you might not want the entire environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have changed this, and currently su will perserve the env.
Seeing as this is being run by systemd services, etc. most of the time it should be OK.

I don't think there should be any issues with doing this.
I will check later/tomorrow and see how it works.

Are there any objections to this?

@Ma27
Copy link
Member

Ma27 commented Sep 7, 2021

I agree with @lukegb here.

@eyJhb
Copy link
Member Author

eyJhb commented Apr 5, 2022

Closing, might pick up in the future, but not needed as of now.

@eyJhb eyJhb closed this Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants