selinux icon indicating copy to clipboard operation
selinux copied to clipboard

add GetSeUserByName, fallback to failsafe context in GetDefaultContextWithLevel

Open capnspacehook opened this issue 7 months ago • 7 comments

Ported getseuserbyname (https://github.com/SELinuxProject/selinux/blob/main/libselinux/src/seusers.c#L188) to Go, and added failsafe_context parsing to GetDefaultContextWithLevel as that's what libselinux's get_default_context_with_level does (https://github.com/SELinuxProject/selinux/blob/main/libselinux/src/get_context_list.c#L488).

getseuserbyname reads theseusers file (https://www.man7.org/linux/man-pages/man5/seusers.5.html) to find the SELinux user and the MLS level for a given Linux user.

get_default_context_with_level takes a SELinux user, MLS level, and an SELinux context (combination of SELinux user, role, domain, and MLS level, in many cases this context is the context of the caller) and returns the SELinux context that should be used when creating processes as a certain Linux user.

get_default_context_with_level attempts to find a suitable context for the specific SELinux user that was passed first, then searches in the list of global context mappings if no match was found, and finally just returns the failsafe context if no match was found anywhere else. GetDefaultContextWithLevel previously returned an error if no context could be found for the SELinux user or globally.

Man page for failsafe_context: https://www.man7.org/linux//man-pages/man5/failsafe_context.5.html

capnspacehook avatar May 20 '25 01:05 capnspacehook

Missed this, could you sign your commit?

rhatdan avatar Sep 04 '25 12:09 rhatdan

LGTM @kolyshkin @thaJeztah PTAL

rhatdan avatar Sep 04 '25 12:09 rhatdan

@rhatdan no prob, signed commit

capnspacehook avatar Oct 07 '25 20:10 capnspacehook

@capnspacehook can you split this into two commits, by functionality. Same PR is fine.

kolyshkin avatar Oct 07 '25 23:10 kolyshkin

@kolyshkin split into two commits

capnspacehook avatar Oct 08 '25 16:10 capnspacehook

@kolyshkin good idea, files are opened lazily now

capnspacehook avatar Oct 10 '25 15:10 capnspacehook

@kolyshkin signed off all commits and fixed a few linter warnings, anything else I need to do to move forward with this?

capnspacehook avatar Nov 20 '25 19:11 capnspacehook