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

RFC: Capabilities #185

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

RFC: Capabilities #185

wants to merge 49 commits into from

Conversation

mhaas
Copy link
Contributor

@mhaas mhaas commented Apr 3, 2015

I'm submitting a PR as a request for comments/review for capabilities (7) support.

The code drops all privileges except CAP_NET_ADMIN and CAP_NET_RAW and switches the effective user ID to a non-privileged user and group. specified in the config file.

On execvp or popen (e.g. calls to iptables), the code switches the effective UID back to 0. This is needed because there is no way for the child process to inherit these capabilites (1, 2).

This solution is not without problems, as (obviously) an attacker could go back to UID0 and place shell scripts in /etc/cron.d/ or use similar attack vectors. To avoid this problem, a chroot environment would be required. CAP_CHROOT is not permitted anymore, so breaking out would not be a problem.

mhaas added 22 commits March 15, 2015 20:54
Also protect capabilities with ifdefs
The new strategy is to use seteuid(), in which case we don't need to
care about the capabilities of child processes.
I made some wrong assumptions about execve() in a real-uid 0 context.
Only the file capabilities are all enabled, which still requires the
caller to have the appropriate capabilities. I will add a comment
clarifying the behaviour here.
Turns out I was mistaken about some things - I had accidentally
still ran iptables as root.

The current code now drops from UID0 to a non-privileged user
at startup. There are two occasions where the effective
user ID is set back to 0:

* in execute() in util.c
* in fw_iptables.c with a wrapper around popen
@acv
Copy link
Contributor

acv commented Apr 3, 2015

Somehow, it's always the non-cyassl build that fails. Looks to be a missing header maybe that gets brought in with cyassl. Try building it without cyassl.

@mhaas
Copy link
Contributor Author

mhaas commented Apr 3, 2015

No, the normal build does not respect CFLAGS=-Werror. For some reason.

@mhaas
Copy link
Contributor Author

mhaas commented Apr 3, 2015

Re your earlier comment:

Reload forks and then transfers the running state over the wdctl socket. If reload doesn't have the >privileges to call LIBCAP, it will will need to be able to detect this and do nothing.

This will also need a switch_to_root() call then. INHERITABLE is probably also not needed in the patch above.

@acv
Copy link
Contributor

acv commented Apr 3, 2015

Ahhhh, interesting about -Werror...

@acv
Copy link
Contributor

acv commented Apr 3, 2015

Something's weird with the logging. Otherwise, it seems to work.

caps = cap_get_proc();
debug(LOG_DEBUG, "Dropped caps, now: %s", cap_to_text(caps, NULL));
cap_free(caps);
caps = cap_get_proc();
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing a cap_free() after this cap_get_proc()

@acv
Copy link
Contributor

acv commented Apr 3, 2015

I'm done adding line comments throughout your patch ;-)

@mhaas
Copy link
Contributor Author

mhaas commented Apr 8, 2015

Finally got travis to play nice.

@mhaas
Copy link
Contributor Author

mhaas commented Jul 26, 2015

Updated so it can be merged.

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.

2 participants