1

In package managers like pacman and apt, the root check is hard coded into source using guid checks. Why is this?

A non privileged user can compile a program - let's say chromium browser - from source into a pseudo root (within the user directory) and run it. The user can even download a pre-compiled binary and run it. Why not just let the user use package managers to directly install the software into the pseudo root (within the users home directory) without privilege escalation?

IMO package managers should require sudo only when writing files to a dir owned by root. like /bin or /etc.

Please let me know if there is some security issue that I'm overlooking.

Note: A bit of research shows that there indeed are alternate package managers for user space. Package management without the need of root permission https://askubuntu.com/questions/339 Non-Root Package Managers

My question still is - why native package managers do not support such a use case - would have been a more elegant implementation.

Sway
  • 113

2 Answers2

4

Package managers need to run as root because what they do affects all users.

IMO package managers should require sudo only when writing files to a dir owned by root. like /bin or /etc.

They also require root access to manage the database of installed packages.

A package manager that installs software under a user's home directory doesn't need to run as root.

Why don't most package managers let you install programs under your home directory? Because dependency management is hard. Most people underestimate this, in my experience. When software is installed system-wide, there's only one group of dependencies to consider. When you mix system-wide software (at least the libraries needed to run the package manager!) and user-only software, dependencies get a lot harder to manage.

0

Package manager is a powerful tool to repair&destroy system.

It's easier to ask root privilege once when check all actions for permission.

Sild
  • 325
  • When run as a user, the executable will not be able to modify any root level files anyway. similar to behavior of other programs like rm. as I see it, in the hands of a non-root user, package manager cannot screw up a system any more than rm can. – Sway May 31 '16 at 14:40
  • apt not force for sudo promt. As I remember, it is only pacman ( and yourt ?) feature. Are you sure pacman ask for sudo if you run smthing like apt-cache search? Maybe it's just developer solution to prevent misunderstanding after executing of dangerous application. – Sild May 31 '16 at 15:17
  • 1
    Certain operations (like query without install) are allowed without sudo. but install in both are hard coded to require root when installing even to a users home directory. – Sway May 31 '16 at 15:22
  • If you install a package by manager, except extraction of binary files you will write some metadata to package-manager database. This action require for sudo too. – Sild May 31 '16 at 15:25
  • At least in the case of pacman, when used with --root (alternate root) parameter, the database path will resolve to a path in the alternate root. the metadata will go here.. – Sway May 31 '16 at 15:36