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

Run brew commands as regular user when lynis is invoked as root #1564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Neved4
Copy link

@Neved4 Neved4 commented Oct 21, 2024

Fixes #382, related #1273.

Instead of running Homebrew as the root user, this change runs it as a normal user, which is the intended use case for Homebrew. After the change, the command is run a non-root user context, which seems a way to effectively drop privileges.

This prevents raising the error:

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

Note: the function could have a different descriptive name, refactored to be more compact, etc. See:

RunBrewAsUser() {
    { "$(id -u)" && sudo -u "$SUDO_USER" brew "$@"; } || brew "$@"
}

Security

Thanks to brew's safeguards this might not be exploitable, but including the following for reference.

MITRE's CWE-250 is related to this change:

CWE ID CWE Title Description
CWE-250 Execution with Unnecessary Privileges The software runs with more privileges than necessary, which can lead to security vulnerabilities.

This change follows REF-76 by dropping the privileges as soon as possible, as in:

Run your code using the lowest privileges that are required to accomplish the necessary tasks.
Wrap and centralize this functionality if possible, and isolate the privileged code as much as possible from other code.
Raise privileges as late as possible, and drop them as soon as possible to avoid CWE-271.

Source: CWE-250: Execution with Unnecessary Privileges.

@Neved4 Neved4 changed the title Run brew commands as regular user when Lynis is invoked as root Run brew commands as regular user when lynis is invoked as root Oct 21, 2024
@wileyhy
Copy link

wileyhy commented Oct 22, 2024 via email

@wileyhy
Copy link

wileyhy commented Oct 22, 2024

Have I gotten anything wrong in this reply? It's been kind of a weird day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lynis needs to drop privilleges to support homebrew on MacOSX
2 participants