libselinux: add selinux_snapperd_contexts_path()
PATCH 1/1 libselinux: add selinux_snapperd_contexts_path()
Snapper needs a way how to set a proper selinux context on btrfs subvolumes originating in snapshot create command. Fs can't handle it on its own so snapper will enforce .snapshots subvolume relabeling according to a file returned by selinux_snapperd_contexts_path().
The format of the file will be similar to other contexts file:
snapperd_data = system_u:object_r:snapperd_data_t:s0
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1247530
https://bugzilla.redhat.com/show_bug.cgi?id=1247532
--- libselinux/include/selinux/selinux.h | 1 + libselinux/src/file_path_suffixes.h | 1 + libselinux/src/selinux_config.c | 10 +++++++++- libselinux/src/selinux_internal.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)
libselinux/include/selinux/selinux.h +1 -0
@@ -544,6 +544,7 @@ extern const char *selinux_lxc_contexts_path(void);extern const char *selinux_x_context_path (void );extern const char *selinux_sepgsql_context_path (void );extern const char *selinux_openssh_contexts_path (void ); +extern const char *selinux_snapperd_contexts_path (void );extern const char *selinux_systemd_contexts_path (void );extern const char *selinux_contexts_path (void );extern const char *selinux_securetty_types_path (void );
libselinux/src/file_path_suffixes.h +1 -0
@@ -24,6 +24,7 @@ S_(BINPOLICY, "/policy/policy") S_(VIRTUAL_IMAGE, "/contexts/virtual_image_context") S_(LXC_CONTEXTS, "/contexts/lxc_contexts") S_(OPENSSH_CONTEXTS, "/contexts/openssh_contexts") + S_(SNAPPERD_CONTEXTS, "/contexts/snapperd_contexts") S_(SYSTEMD_CONTEXTS, "/contexts/systemd_contexts") S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")S_ (FILE_CONTEXT_SUBS_DIST ,"/contexts/files/file_contexts.subs_dist" )
libselinux/src/selinux_config.c +9 -1
@@ -50,7 +50,8 @@#define BOOLEAN_SUBS 27#define OPENSSH_CONTEXTS 28#define SYSTEMD_CONTEXTS 29 -#define NEL 30 +#define SNAPPERD_CONTEXTS 30 +#define NEL 31/* Part of one-time lazy init */ static pthread_once_t once =PTHREAD_ONCE_INIT ;
@@ -499,6 +500,13 @@ const char *selinux_openssh_contexts_path(void)hidden_def (selinux_openssh_contexts_path) +const char *selinux_snapperd_contexts_path(void) +{ +return get_path (SNAPPERD_CONTEXTS ); +} + +hidden_def (selinux_snapperd_contexts_path) + const char *selinux_systemd_contexts_path(void) {return get_path (SYSTEMD_CONTEXTS );
libselinux/src/selinux_internal.h +1 -0
@@ -84,6 +84,7 @@ hidden_proto(selinux_mkload_policy) hidden_proto(selinux_x_context_path) hidden_proto(selinux_sepgsql_context_path) hidden_proto(selinux_openssh_contexts_path) + hidden_proto(selinux_snapperd_contexts_path) hidden_proto(selinux_systemd_contexts_path) hidden_proto(selinux_path) hidden_proto(selinux_check_passwd_access)
Signature · 1 line
2.7.4
Quoted 5 lines · Petr Lautrbach
Snapper needs a way how to set a proper selinux context on btrfs subvolumes originating in snapshot create command. Fs can't handle it on its own so snapper will enforce .snapshots subvolume relabeling according to a file returned by
selinux_snapperd_contexts_path().
Quoted 7 lines
The format of the file will be similar to other contexts file:
snapperd_data= system_u:object_r:snapperd_data_t:s0Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1247530
https://bugzilla.redhat.com/show_bug.cgi?id=1247532
Seems like there is a kernel bug here, if btrfs snapshots are being created in unlabeled_t initially? I understand and agree that ultimately something in userspace will have to assign a specific label, but they shouldn't be defaulting to unlabeled_t.
Quoted 74 lines
Signed-off-by Petr Lautrbach <[email protected]>--- libselinux/include/selinux/selinux.h | 1 + libselinux/src/file_path_suffixes.h | 1 + libselinux/src/selinux_config.c | 10 +++++++++- libselinux/src/selinux_internal.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)libselinux/include/selinux/selinux.h +1
-0@@ -544,6 +544,7 @@ extern const char *selinux_lxc_contexts_path(void);extern const char *selinux_x_context_path (void );extern const char *selinux_sepgsql_context_path (void );extern const char *selinux_openssh_contexts_path (void ); +extern const char *selinux_snapperd_contexts_path (void );extern const char *selinux_systemd_contexts_path (void );extern const char *selinux_contexts_path (void );extern const char *selinux_securetty_types_path (void );libselinux/src/file_path_suffixes.h +1
-0@@ -24,6 +24,7 @@ S_(BINPOLICY, "/policy/policy") S_(VIRTUAL_IMAGE, "/contexts/virtual_image_context") S_(LXC_CONTEXTS, "/contexts/lxc_contexts") S_(OPENSSH_CONTEXTS, "/contexts/openssh_contexts") + S_(SNAPPERD_CONTEXTS, "/contexts/snapperd_contexts") S_(SYSTEMD_CONTEXTS, "/contexts/systemd_contexts") S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")S_ (FILE_CONTEXT_SUBS_DIST ,"/contexts/files/file_contexts.subs_dist" )libselinux/src/selinux_config.c +9
-1@@ -50,7 +50,8 @@#define BOOLEAN_SUBS 27#define OPENSSH_CONTEXTS 28#define SYSTEMD_CONTEXTS 29 -#define NEL 30 +#define SNAPPERD_CONTEXTS 30 +#define NEL 31/* Part of one-time lazy init */ static pthread_once_t once =PTHREAD_ONCE_INIT ;@@ -499,6 +500,13 @@ const char *selinux_openssh_contexts_path(void)hidden_def (selinux_openssh_contexts_path) +const char *selinux_snapperd_contexts_path(void) +{ +return get_path (SNAPPERD_CONTEXTS ); +} + +hidden_def (selinux_snapperd_contexts_path) + const char *selinux_systemd_contexts_path(void) {return get_path (SYSTEMD_CONTEXTS );libselinux/src/selinux_internal.h +1
-0@@ -84,6 +84,7 @@ hidden_proto(selinux_mkload_policy) hidden_proto(selinux_x_context_path) hidden_proto(selinux_sepgsql_context_path) hidden_proto(selinux_openssh_contexts_path) + hidden_proto(selinux_snapperd_contexts_path) hidden_proto(selinux_systemd_contexts_path) hidden_proto(selinux_path) hidden_proto(selinux_check_passwd_access)
Paul Moore
maintainerQuoted 10 lines · Stephen Smalley
Quoted 9 lines · Petr Lautrbach
Snapper needs a way how to set a proper selinux context on btrfs subvolumes originating in snapshot create command. Fs can't handle it on its own so snapper will enforce .snapshots subvolume relabeling according to a file returned by
selinux_snapperd_contexts_path().The format of the file will be similar to other contexts file:
snapperd_data= system_u:object_r:snapperd_data_t:s0
Quoted 8 lines
Quoted 3 lines
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1247530
https://bugzilla.redhat.com/show_bug.cgi?id=1247532Seems like there is a kernel bug here, if btrfs snapshots are being created in
unlabeled_tinitially? I understand and agree that ultimately something in userspace will have to assign a specific label, but they shouldn't be defaulting tounlabeled_t.
It's been too long since I've looked at this, but from what I recall the btrfs snapshots are a real mess from a SELinux perspective and setting an initial label was not an easy thing to do.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 5 lines · Petr Lautrbach
Snapper needs a way how to set a proper selinux context on btrfs subvolumes originating in snapshot create command. Fs can't handle it on its own so snapper will enforce .snapshots subvolume relabeling according to a file returned by
selinux_snapperd_contexts_path().
Quoted 7 lines
The format of the file will be similar to other contexts file:
snapperd_data= system_u:object_r:snapperd_data_t:s0Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1247530
https://bugzilla.redhat.com/show_bug.cgi?id=1247532
Thanks, applied. I would recommend that a bug be opened against the kernel / btrfs about the fact that the inodes are initially unlabeled, as otherwise snapper will always need permissions to relabel unlabeled files and generally we would prefer that unlabeled be inaccessible.
Quoted 74 lines
Signed-off-by Petr Lautrbach <[email protected]>--- libselinux/include/selinux/selinux.h | 1 + libselinux/src/file_path_suffixes.h | 1 + libselinux/src/selinux_config.c | 10 +++++++++- libselinux/src/selinux_internal.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-)libselinux/include/selinux/selinux.h +1
-0@@ -544,6 +544,7 @@ extern const char *selinux_lxc_contexts_path(void);extern const char *selinux_x_context_path (void );extern const char *selinux_sepgsql_context_path (void );extern const char *selinux_openssh_contexts_path (void ); +extern const char *selinux_snapperd_contexts_path (void );extern const char *selinux_systemd_contexts_path (void );extern const char *selinux_contexts_path (void );extern const char *selinux_securetty_types_path (void );libselinux/src/file_path_suffixes.h +1
-0@@ -24,6 +24,7 @@ S_(BINPOLICY, "/policy/policy") S_(VIRTUAL_IMAGE, "/contexts/virtual_image_context") S_(LXC_CONTEXTS, "/contexts/lxc_contexts") S_(OPENSSH_CONTEXTS, "/contexts/openssh_contexts") + S_(SNAPPERD_CONTEXTS, "/contexts/snapperd_contexts") S_(SYSTEMD_CONTEXTS, "/contexts/systemd_contexts") S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")S_ (FILE_CONTEXT_SUBS_DIST ,"/contexts/files/file_contexts.subs_dist" )libselinux/src/selinux_config.c +9
-1@@ -50,7 +50,8 @@#define BOOLEAN_SUBS 27#define OPENSSH_CONTEXTS 28#define SYSTEMD_CONTEXTS 29 -#define NEL 30 +#define SNAPPERD_CONTEXTS 30 +#define NEL 31/* Part of one-time lazy init */ static pthread_once_t once =PTHREAD_ONCE_INIT ;@@ -499,6 +500,13 @@ const char *selinux_openssh_contexts_path(void)hidden_def (selinux_openssh_contexts_path) +const char *selinux_snapperd_contexts_path(void) +{ +return get_path (SNAPPERD_CONTEXTS ); +} + +hidden_def (selinux_snapperd_contexts_path) + const char *selinux_systemd_contexts_path(void) {return get_path (SYSTEMD_CONTEXTS );libselinux/src/selinux_internal.h +1
-0@@ -84,6 +84,7 @@ hidden_proto(selinux_mkload_policy) hidden_proto(selinux_x_context_path) hidden_proto(selinux_sepgsql_context_path) hidden_proto(selinux_openssh_contexts_path) + hidden_proto(selinux_snapperd_contexts_path) hidden_proto(selinux_systemd_contexts_path) hidden_proto(selinux_path) hidden_proto(selinux_check_passwd_access)