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

Propogate capabilities to child process #179

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

Conversation

ewildgoose
Copy link

This is not ready to commit, but just an idea I wanted to share.

Capabilities aren't shared with processes started via execve, unless you specifically manipulate the inherited capabilities before and then request the ambient capabilities to be raised

The motivation is that it's sometimes useful to be able to have erlang run commands with elevated capabilities, rather than jumping through sudo (one reason for this is that sudo is quite slow on my platform, adding around 30ms to every call, which for multiple calls is unreasonably slow). An example might be calling "ipset", normally this requires root permissions, but can be run as a non priv user if given cap_net_admin capabilities.

So on my embedded box I am marking the erlexec binary with appropriate capabilities, and these can then be passed to the binary we want to run

I suspect to complete this you might want to make the inheritance of the capabilities optional?

Note also, I think, but haven't tested, that this will work as expected with change in effective UID? There are some pitfalls though as capabilities get dropped when changing uid, so I might need to split the code and read the caps before changing uid? Unsure?

However, what's your opinion? Is this useful upstream?

@saleyn
Copy link
Owner

saleyn commented Aug 29, 2024

This is a good idea, but I would like to have the inheritance optional. I.e. introduce an option:
{capabilities, all | [capability()]}
where capability() would name the capabilities you'd like inherited, and all would inherit all that are granted to the parent.

Also please add test cases, and update the README.md with an example.

@ewildgoose
Copy link
Author

ewildgoose commented Aug 30, 2024

Thanks for the encouragement!

I'm really an Elixir developer, I'll ponder the changes needed to the erlang side, but I suspect I will need help to make this happen. I'm happy for you to close this if you have no interest to run with it? I think I was proposing it as a proof of concept to see if you would volunteer to adopt it.

Thanks for the interest anyway!

@saleyn
Copy link
Owner

saleyn commented Sep 1, 2024

I'm happy to provide some guidance, though have very limitted time. I fixed your PR by adding error handling.

@saleyn
Copy link
Owner

saleyn commented Sep 2, 2024

I did some enhancements by adding the ability to pass capabilites to the child process. What's left is to add the ability to set capabilities on the exec-port (i.e. pass the desired inheritable capabilities to the exec-port executable, so that child processes could set them).

@saleyn
Copy link
Owner

saleyn commented Sep 4, 2024

@ewildgoose, if you have time to implement passing the capabilities to exec-port that it should set on startup, and test the functionaity I added that would be great. I am going to be pretty busy for the next few weeks, and may not get to it soon.

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