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

Implement IsClientAuthorized() for FreeBSD and stop failing open #209

Closed
wants to merge 2 commits into from

Conversation

kevans91
Copy link
Contributor

@kevans91 kevans91 commented Sep 5, 2024

We can provide a sensible polkit implementation on FreeBSD with our analog to SO_PEERCRED, so do it. The functionality is identical modulo some naming differences in the xucred that we get back.

While we're here, don't fail open if polkit was specifically requested. AFAICT the meson build won't enable it without an explicit -Dpolkit=true, so if we got to auth.c with HAVE_POLKIT then the build requested it. Failing open (i.e. not consulting the policy) results in a daemon that behaves quite surprisingly when the user expected it to be consulting polkit before granting access. Considering the nature of the daemon, this seems like a safer/better default.

The current version fails open if we don't have some analog for the Linux
SO_PEERCRED functionality implemented for the platform we're building on.

This is incredibly surprising if polkit has been specifically requested, as
the default implementation will just allow all access without consulting
polkit at all.
FreeBSD's analog to SO_PEERCRED is LOCAL_PEERCRED, which returns a
(ABI stable) `struct xucred` rather than a `struct cred`.  Paper over the
platform differences with a typedef and a couple macros.
@kevans91
Copy link
Contributor Author

kevans91 commented Sep 5, 2024

CC @arrowd as our port maintainer

@arrowd
Copy link

arrowd commented Sep 5, 2024

This looks good to me, thanks for fixing this!


#include <polkit/polkit.h>
#include <stdbool.h>

#ifdef __FreeBSD__
Copy link

Choose a reason for hiding this comment

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

I don't know much about socket authentication, but what about macOS? Is the struct xucred only used on FreeBSD? A quick Google search implies that it's also used on Mac. Would you mind explaining what ucred vs xucred is about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

xucred is the ABI-stable userland export version (subset) of ucred -- if you have the former then the latter is considered kernel-only and it will populate an xucred for things in userland that want it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

macOS also seems to have LOCAL_PEERCRED, but I don't know what the polkit-on-macOS situation is like so I haven't bothered trying to expand it in that direction. Likely it also wants the xucred version of this.

#elif defined(HAVE_POLKIT)

#error polkit is enabled, but no socket cred implementation for this platform

#else

unsigned IsClientAuthorized(int socket, const char* action, const char* reader)
Copy link

Choose a reason for hiding this comment

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

Given the above, #error polkit is enabled, but no socket cred implementation for this platform, I'm not sure if this will matter or not. But I wonder if this function still has an effect, if we can log some kind of message to stderr stating that the allow-all IsClientAuthorized() function is being used.

May be outside the scope of this PR, but wanted to suggest it as a way to make it more obvious if others run into this.

Copy link
Contributor Author

@kevans91 kevans91 Sep 5, 2024

Choose a reason for hiding this comment

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

The allow-all one is what you should get when you build with -Dpolkit=false to avoid sprinkling more HAVE_POLKIT around and allow other authorization mechanisms to be plugged in instead. Its use is actually expected rather than an error in the default configuration, and that seems more or less fine.

Copy link

Choose a reason for hiding this comment

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

Ah, gotcha. Thank you for explaining!

@LudovicRousseau
Copy link
Owner

Merged in a2a7e07 and 19d0b26 with minor changes.

Thanks

@kevans91
Copy link
Contributor Author

kevans91 commented Sep 8, 2024

Merged in a2a7e07 and 19d0b26 with minor changes.

Thanks

Thanks!

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.

5 participants