Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@oxzi
Copy link
Contributor

@oxzi oxzi commented Jan 15, 2026

OpenBSD's pledge(2) system call allows the current process to self-restrict itself, being reduced to promised pledges. For example, unless a process says it wants to write to files, it is not allowed to do so any longer.

This change starts by calling pledge(2) in some network-facing checks, removing the more dangerous privileges, such as executing other files.

My initial motivation came from check_icmp, being installed as a setuid binary and (temporarily) running with root privileges. There, the pledge(2) calls result in check_icmp to only being allowed to interact with the network and to setuid(2) to the calling user later on.

Afterwards, I went through my most commonly used monitoring plugins directly interacting with the network. Thus, I continued with pledge(2)-ing check_curl - having a huge codebase and all -, check_ntp_time, check_smtp, check_ssh, and check_tcp.

For most of those, the changes were quite similar: start with network-friendly promises, parse the configuration, give up file access, and proceed with the actual check.


While this change might only address a niche, I would argue it might help a lot by only a few lines in case of disaster. But I am open for other opinions.

@RincewindsHat
Copy link
Member

Love it. I had a workshop about that recently and it sounds good :-)
I was thinking about asking for some explanatory comments, but now I am not sure whether that would add more than man 2 pledge would explain.

@oxzi
Copy link
Contributor Author

oxzi commented Jan 16, 2026

I would update this PR later to add one or two lines to the initial pledge(2) call explaining my reasoning for the promises. This might be useful for future updates or debugging in case something does not work due to a too strict restriction.

@RincewindsHat
Copy link
Member

that would definitely be nice :-)

@oxzi oxzi force-pushed the openbsd-pledge-init branch from 4bfcfce to bad7ec6 Compare January 17, 2026 20:26
@oxzi
Copy link
Contributor Author

oxzi commented Jan 17, 2026

Rebased the PR branch and added a short explanation about the chosen promises - next to the omnipresent stdio and error promises - above the first pledge(2) call in each check.

OpenBSD's pledge(2) system call allows the current process to
self-restrict itself, being reduced to promised pledges. For example,
unless a process says it wants to write to files, it is not allowed to
do so any longer.

This change starts by calling pledge(2) in some network-facing checks,
removing the more dangerous privileges, such as executing other files.

My initial motivation came from check_icmp, being installed as a setuid
binary and (temporarily) running with root privileges. There, the
pledge(2) calls result in check_icmp to only being allowed to interact
with the network and to setuid(2) to the calling user later on.

Afterwards, I went through my most commonly used monitoring plugins
directly interacting with the network. Thus, I continued with
pledge(2)-ing check_curl - having a huge codebase and all -,
check_ntp_time, check_smtp, check_ssh, and check_tcp.

For most of those, the changes were quite similar: start with
network-friendly promises, parse the configuration, give up file access,
and proceed with the actual check.
@oxzi oxzi force-pushed the openbsd-pledge-init branch from bad7ec6 to aa6af31 Compare January 20, 2026 20:20
@sthen
Copy link
Contributor

sthen commented Jan 30, 2026

btw I've added the patches from this PR to the OpenBSD -current packages, have seen no problems myself and had no reports of problems.

@RincewindsHat
Copy link
Member

@sthen thank you for the feedback :-)

@oxzi do you consider this PR ready for inclusion?

@oxzi
Copy link
Contributor Author

oxzi commented Jan 30, 2026

Yes, feel free to merge. I am using this patch since creating the PR and have not experienced any issues. Of course, these plugins have many switches and I cannot guarantee that nothing will break. As @sthen wrote, they are already shipped in of OpenBSD's current and I also don't know of any complains.

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.

3 participants