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

Adds OpenBSD's pledge() #5560

Closed

Conversation

chris-huxtable
Copy link
Contributor

Adds OpenBSD's pledge function.

"The current process is forced into a restricted-service operating mode. A few subsets are available, roughly described as computation, memory management, read-write operations on file descriptors, opening of files, networking. In general, these modes were selected by studying the operation of many programs using libc and other such interfaces, and setting promises or execpromises."

@chris-huxtable chris-huxtable changed the title Adds pledge() Adds OpenBSD's pledge() Jan 9, 2018
@ysbaddaden
Copy link
Contributor

Provided LibC bindings are minimal to satisfy the core and stdlib. pledge is OpenBSD specific, and we don't have any use for it, at least for the time being. Please define specific bindings in projects that need it only.

@ysbaddaden ysbaddaden closed this Jan 9, 2018
@chris-huxtable
Copy link
Contributor Author

Pledge is one of the core offerings of OpenBSD. Everything in base has been pledged right down to tools like less, ls, and cd. It is as integral as arc4random which has been included. It has been manually included in ports of ruby for OpenBSD (patched in the build system). If you are coding something which you expect to be secure it should be used, just like chroot, and privilege separation.

@asterite
Copy link
Member

asterite commented Jan 9, 2018

@chris-huxtable The standard library can't provide functionality that works in some platforms but not others. Plus, this is just adding a C binding, and we don't document this.

I suggest to define and wrap this function in a shard and provide it, expliclty stating that it only works in OpenBSD.

@RX14
Copy link
Contributor

RX14 commented Jan 9, 2018

@chris-huxtable LibC isn't meant to be used. It's an internal implementation detail for the standard library only.

We might think about this if there was a Process.pledge which worked on openbsd but raised NotImplementedError on every other platform, however this PR doesn't add that.

Even then, i'd much rather have something cross-platform, and every unix does this kind of syscall firewall differently, so that's not really feasible.

@straight-shoota
Copy link
Member

It looks like in most programming languages this is supported a an optional package: https://gist.github.com/ligurio/f6114bd1df371047dd80ea9b8a55c104

@straight-shoota
Copy link
Member

Oh, not true: Go has it in core since May last year: http://undeadly.org/cgi?action=article&sid=20170323042425

@asterite
Copy link
Member

asterite commented Jan 9, 2018

@straight-shoota I couldn't find that in the std, it seems to be in the golang/sys repo.

@straight-shoota
Copy link
Member

You're right. Not in core. But an official package.

@chris-huxtable
Copy link
Contributor Author

I have expanded on this and created a shard if anyone is interested.
https://github.com/chris-huxtable/openbsd.cr

@RX14
Copy link
Contributor

RX14 commented Jan 11, 2018

@chris-huxtable that's cool, but uid/euid/username/groupname/etc really belong in the stdlib because they're cross-platform. It'd be ideal if a shard called openbsd.cr included only openbsd-specific things...

@straight-shoota
Copy link
Member

Or, like Go, we could have an official sys shard which contains such low level APIs for all operating systems...

@chris-huxtable
Copy link
Contributor Author

chris-huxtable commented Jan 11, 2018

If its valuable I can make a pull request which only contains privilege dropping and chroot. While making a shard which just contains pledge. Thoughts?

@RX14
Copy link
Contributor

RX14 commented Jan 11, 2018

Thinking about it more, it's probably best to look at what Go's done here in os/user.

That is: record Group, id : String, name : String, and record User, id : String, primary_group : Group, username : String, display_name : String, home_dir : String.

Not sure about chroot but my gut feeling is we should just add it.

@chris-huxtable
Copy link
Contributor Author

I have put together a pull request which would add chroot to Process.

I have also previously built classes for both system users and groups. I would be willing to open source those components. I think it makes the most sense to build them right into the standard library as setuid/setgid are fundamental process control functions which are baked in to all unix-based OS's.

@RX14
Copy link
Contributor

RX14 commented Jan 12, 2018

Yeah, I agree on having setuid, setgid in the stdlib, but I think introducing User and Group objects would be great. Then perhaps Process.become(User) and Process.become(Group) would be ideal APIs?

@chris-huxtable
Copy link
Contributor Author

I like that. I will put together a pull request.

@chris-huxtable
Copy link
Contributor Author

For anyone looking for pledge. I have created a shard that adds only pledge.
https://github.com/chris-huxtable/pledge.cr

@chris-huxtable chris-huxtable deleted the openbsd-pledge branch January 19, 2018 23:05
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.

None yet

5 participants