Skip to content

pledge and unveil on OpenBSD#2366

Draft
amrfti wants to merge 2 commits into
PurpleI2P:opensslfrom
amrfti:unveil/pledge
Draft

pledge and unveil on OpenBSD#2366
amrfti wants to merge 2 commits into
PurpleI2P:opensslfrom
amrfti:unveil/pledge

Conversation

@amrfti

@amrfti amrfti commented Apr 4, 2026

Copy link
Copy Markdown

This patch implements native OpenBSD hardening for the i2pd daemon with unveil(2) and pledge(2) by placing a privledge restriction block at the end of Daemon::init. We get paths for tunconf, tunnelsdir, datadir, and certsdir from the config map.

Paths for name resolution (/etc/resolv.conf and /etc/hosts) are automatically unveiled by the dns promise.

@amrfti

amrfti commented Apr 4, 2026

Copy link
Copy Markdown
Author

Upon further testing I believe this still has some issues. In my first commit, I was lacking some additional paths that may have conditionally needed to be unveiled based on given arguments. Yet even still there are some strange issues that I believe are a result of some arguments not being initialized to their default fallback options until after we've finished unveiling. For example, I created this error while testing:

# i2pd --logfile /root/.i2pd/i2pd.log
i2pd: Could not create pid file /root/.i2pd/i2pd.pid: No such file or directory

I believe at the time I unveil the pidfile path, it's unintialized, which causes it to never get unveiled. I need to do more testing, feedback welcome.

@amrfti amrfti marked this pull request as draft April 4, 2026 21:09
@orignal

orignal commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

daemon/Daemon.cpp:317:76: error: function definition is not allowed here
317 | static void UnveilConfigOption(const std::string& key, const char* mask) {
| ^
daemon/Daemon.cpp:337:4: error: use of undeclared identifier 'UnveilConfigOption'
337 | UnveilConfigOption(rule.first, rule.second);
| ^

Please refrain from using nested functions.

@sonya-blade

Copy link
Copy Markdown

suppose it'd be best to go the "official" way:

  • submit the patch to the ports@openbsd.org, where it'd be reviewed and tested;
  • after the acceptance of the patch by community - merge in upstream from OpenBSD cvsweb or git
    thank you

@daviduhden daviduhden left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for working on OpenBSD hardening. I agree with the issue reported by orignal, and here is the precise correction.

C++ does not allow defining a named function inside another function. In this patch, static void UnveilConfigOption(...) is defined inside Daemon::init, which causes the compile error: function definition is not allowed here.

Please move that helper out of Daemon::init, for example to anonymous namespace file scope, or replace it with a local lambda and keep the rest of the logic unchanged.

Also please fix the PR text typo: privledge -> privilege.

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.

4 participants