@@ -37,9 +37,15 @@ fn get_current_security_context() -> Result<String> {
37
37
std:: fs:: read_to_string ( SELF_CURRENT ) . with_context ( || format ! ( "Reading {SELF_CURRENT}" ) )
38
38
}
39
39
40
+ /// Check if the current process has the capability to write SELinux security
41
+ /// contexts unknown to the current policy. In SELinux terms this capability is
42
+ /// gated under `mac_admin` (admin control over SELinux state), and in the Fedora
43
+ /// policy at least it's part of `install_t`.
40
44
#[ context( "Testing install_t" ) ]
41
45
fn test_install_t ( ) -> Result < bool > {
42
46
let tmpf = tempfile:: NamedTempFile :: new ( ) ?;
47
+ // Our implementation here writes a label which is always unknown to the current policy
48
+ // to verify that we have the capability to do so.
43
49
let st = Command :: new ( "chcon" )
44
50
. args ( [ "-t" , "invalid_bootcinstall_testlabel_t" ] )
45
51
. arg ( tmpf. path ( ) )
@@ -48,6 +54,20 @@ fn test_install_t() -> Result<bool> {
48
54
Ok ( st. success ( ) )
49
55
}
50
56
57
+ /// Ensure that the current process has the capability to write SELinux security
58
+ /// contexts unknown to the current policy.
59
+ ///
60
+ /// See [`test_install_t`] above for how we check for that capability.
61
+ ///
62
+ /// In the general case of both upgrade or install, we may e.g. jump major versions
63
+ /// or even operating systems, and we need the ability to write arbitrary labels.
64
+ /// If the current process doesn't already have `mac_admin/install_t` then we
65
+ /// make a new temporary copy of our binary, and give it the same label as /usr/bin/ostree,
66
+ /// which in Fedora derivatives at least was already historically labeled with
67
+ /// the correct install_t label.
68
+ ///
69
+ /// However, if you maintain a bootc operating system with SELinux, you should from
70
+ /// the start ensure that /usr/bin/bootc has the correct capabilities.
51
71
#[ context( "Ensuring selinux install_t type" ) ]
52
72
pub ( crate ) fn selinux_ensure_install ( ) -> Result < bool > {
53
73
let guardenv = "_bootc_selinuxfs_mounted" ;
0 commit comments