|
|
e76f14 |
From b70675c87da92ca74019a177214deea2597a9b46 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Wed, 13 Jul 2016 21:21:07 +0100
|
|
|
e76f14 |
Subject: [PATCH] lib: Deprecate old SELinux APIs, rewrite SELinux
|
|
|
e76f14 |
documentation (RHBZ#1152825).
|
|
|
e76f14 |
|
|
|
e76f14 |
Also turns the --selinux option of guestfish, guestmount and
|
|
|
e76f14 |
virt-rescue into a no-op -- it didn't work before so this is
|
|
|
e76f14 |
effectively no change.
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 35bac3a6501354e4a3805877d950e741429f169b)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
builder/builder.ml | 6 -----
|
|
|
e76f14 |
customize/customize_main.ml | 5 ----
|
|
|
e76f14 |
dib/dib.ml | 6 -----
|
|
|
e76f14 |
fish/fish.c | 5 ++--
|
|
|
e76f14 |
fish/guestfish.pod | 2 +-
|
|
|
e76f14 |
fuse/guestmount.c | 5 ++--
|
|
|
e76f14 |
fuse/guestmount.pod | 2 +-
|
|
|
e76f14 |
generator/actions.ml | 5 ++++
|
|
|
e76f14 |
rescue/rescue.c | 5 ++--
|
|
|
e76f14 |
rescue/virt-rescue.pod | 3 +--
|
|
|
e76f14 |
src/guestfs.pod | 59 +++++++++++++++------------------------------
|
|
|
e76f14 |
test-tool/test-tool.c | 1 -
|
|
|
e76f14 |
tests/selinux/run-test.pl | 2 --
|
|
|
e76f14 |
13 files changed, 33 insertions(+), 73 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/builder/builder.ml b/builder/builder.ml
|
|
|
e76f14 |
index ac4c748..0bffc9a 100644
|
|
|
e76f14 |
--- a/builder/builder.ml
|
|
|
e76f14 |
+++ b/builder/builder.ml
|
|
|
e76f14 |
@@ -630,12 +630,6 @@ let main () =
|
|
|
e76f14 |
may g#set_smp cmdline.smp;
|
|
|
e76f14 |
g#set_network cmdline.network;
|
|
|
e76f14 |
|
|
|
e76f14 |
- (* Make sure to turn SELinux off to avoid awkward interactions
|
|
|
e76f14 |
- * between the appliance kernel and applications/libraries interacting
|
|
|
e76f14 |
- * with SELinux xattrs.
|
|
|
e76f14 |
- *)
|
|
|
e76f14 |
- g#set_selinux false;
|
|
|
e76f14 |
-
|
|
|
e76f14 |
(* The output disk is being created, so use cache=unsafe here. *)
|
|
|
e76f14 |
g#add_drive_opts ~format:output_format ~cachemode:"unsafe" output_filename;
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/customize/customize_main.ml b/customize/customize_main.ml
|
|
|
e76f14 |
index 1aa2fb4..7011335 100644
|
|
|
e76f14 |
--- a/customize/customize_main.ml
|
|
|
e76f14 |
+++ b/customize/customize_main.ml
|
|
|
e76f14 |
@@ -169,11 +169,6 @@ read the man page virt-customize(1).
|
|
|
e76f14 |
may g#set_memsize memsize;
|
|
|
e76f14 |
may g#set_smp smp;
|
|
|
e76f14 |
g#set_network network;
|
|
|
e76f14 |
- (* Make sure to turn SELinux off to avoid awkward interactions
|
|
|
e76f14 |
- * between the appliance kernel and applications/libraries interacting
|
|
|
e76f14 |
- * with SELinux xattrs.
|
|
|
e76f14 |
- *)
|
|
|
e76f14 |
- g#set_selinux false;
|
|
|
e76f14 |
|
|
|
e76f14 |
(* Add disks. *)
|
|
|
e76f14 |
add g dryrun;
|
|
|
e76f14 |
diff --git a/dib/dib.ml b/dib/dib.ml
|
|
|
e76f14 |
index 382c9d2..de4f242 100644
|
|
|
e76f14 |
--- a/dib/dib.ml
|
|
|
e76f14 |
+++ b/dib/dib.ml
|
|
|
e76f14 |
@@ -634,12 +634,6 @@ let main () =
|
|
|
e76f14 |
may g#set_smp cmdline.smp;
|
|
|
e76f14 |
g#set_network cmdline.network;
|
|
|
e76f14 |
|
|
|
e76f14 |
- (* Make sure to turn SELinux off to avoid awkward interactions
|
|
|
e76f14 |
- * between the appliance kernel and applications/libraries interacting
|
|
|
e76f14 |
- * with SELinux xattrs.
|
|
|
e76f14 |
- *)
|
|
|
e76f14 |
- g#set_selinux false;
|
|
|
e76f14 |
-
|
|
|
e76f14 |
(* Main disk with the built image. *)
|
|
|
e76f14 |
let fmt = "raw" in
|
|
|
e76f14 |
let fn =
|
|
|
e76f14 |
diff --git a/fish/fish.c b/fish/fish.c
|
|
|
e76f14 |
index ed851ac..bf591e5 100644
|
|
|
e76f14 |
--- a/fish/fish.c
|
|
|
e76f14 |
+++ b/fish/fish.c
|
|
|
e76f14 |
@@ -137,7 +137,7 @@ usage (int status)
|
|
|
e76f14 |
" --no-progress-bars Disable progress bars\n"
|
|
|
e76f14 |
" --remote[=pid] Send commands to remote %s\n"
|
|
|
e76f14 |
" -r|--ro Mount read-only\n"
|
|
|
e76f14 |
- " --selinux Enable SELinux support\n"
|
|
|
e76f14 |
+ " --selinux For backwards compat only, does nothing\n"
|
|
|
e76f14 |
" -v|--verbose Verbose messages\n"
|
|
|
e76f14 |
" -V|--version Display version and exit\n"
|
|
|
e76f14 |
" -w|--rw Mount read-write\n"
|
|
|
e76f14 |
@@ -268,8 +268,7 @@ main (int argc, char *argv[])
|
|
|
e76f14 |
}
|
|
|
e76f14 |
}
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "selinux")) {
|
|
|
e76f14 |
- if (guestfs_set_selinux (g, 1) == -1)
|
|
|
e76f14 |
- exit (EXIT_FAILURE);
|
|
|
e76f14 |
+ /* nothing */
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
|
|
|
e76f14 |
keys_from_stdin = 1;
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "progress-bars")) {
|
|
|
e76f14 |
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
|
|
|
e76f14 |
index 05105e8..bdc2298 100644
|
|
|
e76f14 |
--- a/fish/guestfish.pod
|
|
|
e76f14 |
+++ b/fish/guestfish.pod
|
|
|
e76f14 |
@@ -407,7 +407,7 @@ See also L</OPENING DISKS FOR READ AND WRITE> below.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<--selinux>
|
|
|
e76f14 |
|
|
|
e76f14 |
-Enable SELinux support for the guest. See L<guestfs(3)/SELINUX>.
|
|
|
e76f14 |
+This option is provided for backwards compatibility and does nothing.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<-v>
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
|
|
|
e76f14 |
index 4e9cf86..1fd2f72 100644
|
|
|
e76f14 |
--- a/fuse/guestmount.c
|
|
|
e76f14 |
+++ b/fuse/guestmount.c
|
|
|
e76f14 |
@@ -124,7 +124,7 @@ usage (int status)
|
|
|
e76f14 |
" -o|--option opt Pass extra option to FUSE\n"
|
|
|
e76f14 |
" --pid-file filename Write PID to filename\n"
|
|
|
e76f14 |
" -r|--ro Mount read-only\n"
|
|
|
e76f14 |
- " --selinux Enable SELinux support\n"
|
|
|
e76f14 |
+ " --selinux For backwards compat only, does nothing\n"
|
|
|
e76f14 |
" -v|--verbose Verbose messages\n"
|
|
|
e76f14 |
" -V|--version Display version and exit\n"
|
|
|
e76f14 |
" -w|--rw Mount read-write\n"
|
|
|
e76f14 |
@@ -228,8 +228,7 @@ main (int argc, char *argv[])
|
|
|
e76f14 |
else if (STREQ (long_options[option_index].name, "fuse-help"))
|
|
|
e76f14 |
fuse_help ();
|
|
|
e76f14 |
else if (STREQ (long_options[option_index].name, "selinux")) {
|
|
|
e76f14 |
- if (guestfs_set_selinux (g, 1) == -1)
|
|
|
e76f14 |
- exit (EXIT_FAILURE);
|
|
|
e76f14 |
+ /* nothing */
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "format")) {
|
|
|
e76f14 |
OPTION_format;
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
|
|
|
e76f14 |
diff --git a/fuse/guestmount.pod b/fuse/guestmount.pod
|
|
|
e76f14 |
index e7f37ae..be075e5 100644
|
|
|
e76f14 |
--- a/fuse/guestmount.pod
|
|
|
e76f14 |
+++ b/fuse/guestmount.pod
|
|
|
e76f14 |
@@ -362,7 +362,7 @@ See also L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<--selinux>
|
|
|
e76f14 |
|
|
|
e76f14 |
-Enable SELinux support for the guest.
|
|
|
e76f14 |
+This option is provided for backwards compatibility and does nothing.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<-v>
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/generator/actions.ml b/generator/actions.ml
|
|
|
e76f14 |
index 964a42b..a515c4c 100644
|
|
|
e76f14 |
--- a/generator/actions.ml
|
|
|
e76f14 |
+++ b/generator/actions.ml
|
|
|
e76f14 |
@@ -645,6 +645,7 @@ Use C<guestfs_available> or C<guestfs_feature_available> instead." };
|
|
|
e76f14 |
style = RErr, [Bool "selinux"], [];
|
|
|
e76f14 |
fish_alias = ["selinux"]; config_only = true;
|
|
|
e76f14 |
blocking = false;
|
|
|
e76f14 |
+ deprecated_by = Some "selinux_relabel";
|
|
|
e76f14 |
shortdesc = "set SELinux enabled or disabled at appliance boot";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
This sets the selinux flag that is passed to the appliance
|
|
|
e76f14 |
@@ -660,6 +661,7 @@ see L<guestfs(3)>." };
|
|
|
e76f14 |
name = "get_selinux"; added = (1, 0, 67);
|
|
|
e76f14 |
style = RBool "selinux", [], [];
|
|
|
e76f14 |
blocking = false;
|
|
|
e76f14 |
+ deprecated_by = Some "selinux_relabel";
|
|
|
e76f14 |
shortdesc = "get SELinux enabled flag";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
This returns the current setting of the selinux flag which
|
|
|
e76f14 |
@@ -7315,6 +7317,7 @@ away any pending events, and deallocates all resources." };
|
|
|
e76f14 |
style = RErr, [String "context"], [];
|
|
|
e76f14 |
proc_nr = Some 185;
|
|
|
e76f14 |
optional = Some "selinux";
|
|
|
e76f14 |
+ deprecated_by = Some "selinux_relabel";
|
|
|
e76f14 |
shortdesc = "set SELinux security context";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
This sets the SELinux security context of the daemon
|
|
|
e76f14 |
@@ -7327,6 +7330,7 @@ See the documentation about SELINUX in L<guestfs(3)>." };
|
|
|
e76f14 |
style = RString "context", [], [];
|
|
|
e76f14 |
proc_nr = Some 186;
|
|
|
e76f14 |
optional = Some "selinux";
|
|
|
e76f14 |
+ deprecated_by = Some "selinux_relabel";
|
|
|
e76f14 |
shortdesc = "get SELinux security context";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
This gets the SELinux security context of the daemon.
|
|
|
e76f14 |
@@ -9863,6 +9867,7 @@ This option may not be specified at the same time as the C<correct> option.
|
|
|
e76f14 |
name = "llz"; added = (1, 17, 6);
|
|
|
e76f14 |
style = RString "listing", [Pathname "directory"], [];
|
|
|
e76f14 |
proc_nr = Some 305;
|
|
|
e76f14 |
+ deprecated_by = Some "lgetxattrs";
|
|
|
e76f14 |
shortdesc = "list the files in a directory (long format with SELinux contexts)";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
List the files in F<directory> in the format of 'ls -laZ'.
|
|
|
e76f14 |
diff --git a/rescue/rescue.c b/rescue/rescue.c
|
|
|
e76f14 |
index 982f3c4..f753e6d 100644
|
|
|
e76f14 |
--- a/rescue/rescue.c
|
|
|
e76f14 |
+++ b/rescue/rescue.c
|
|
|
e76f14 |
@@ -72,7 +72,7 @@ usage (int status)
|
|
|
e76f14 |
" --network Enable network\n"
|
|
|
e76f14 |
" -r|--ro Access read-only\n"
|
|
|
e76f14 |
" --scratch[=N] Add scratch disk(s)\n"
|
|
|
e76f14 |
- " --selinux Enable SELinux\n"
|
|
|
e76f14 |
+ " --selinux For backwards compat only, does nothing\n"
|
|
|
e76f14 |
" --smp N Enable SMP with N >= 2 virtual CPUs\n"
|
|
|
e76f14 |
" --suggest Suggest mount commands for this guest\n"
|
|
|
e76f14 |
" -v|--verbose Verbose messages\n"
|
|
|
e76f14 |
@@ -148,8 +148,7 @@ main (int argc, char *argv[])
|
|
|
e76f14 |
else if (STREQ (long_options[option_index].name, "short-options"))
|
|
|
e76f14 |
display_short_options (options);
|
|
|
e76f14 |
else if (STREQ (long_options[option_index].name, "selinux")) {
|
|
|
e76f14 |
- if (guestfs_set_selinux (g, 1) == -1)
|
|
|
e76f14 |
- exit (EXIT_FAILURE);
|
|
|
e76f14 |
+ /* nothing */
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "append")) {
|
|
|
e76f14 |
append = optarg;
|
|
|
e76f14 |
} else if (STREQ (long_options[option_index].name, "network")) {
|
|
|
e76f14 |
diff --git a/rescue/virt-rescue.pod b/rescue/virt-rescue.pod
|
|
|
e76f14 |
index bb563bc..00f03aa 100644
|
|
|
e76f14 |
--- a/rescue/virt-rescue.pod
|
|
|
e76f14 |
+++ b/rescue/virt-rescue.pod
|
|
|
e76f14 |
@@ -209,8 +209,7 @@ command line.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<--selinux>
|
|
|
e76f14 |
|
|
|
e76f14 |
-Enable SELinux in the rescue appliance. You should read
|
|
|
e76f14 |
-L<guestfs(3)/SELINUX> before using this option.
|
|
|
e76f14 |
+This option is provided for backwards compatibility and does nothing.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<--smp> N
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/src/guestfs.pod b/src/guestfs.pod
|
|
|
e76f14 |
index af30406..9ac7792 100644
|
|
|
e76f14 |
--- a/src/guestfs.pod
|
|
|
e76f14 |
+++ b/src/guestfs.pod
|
|
|
e76f14 |
@@ -433,8 +433,8 @@ an X86 host).
|
|
|
e76f14 |
|
|
|
e76f14 |
=item *
|
|
|
e76f14 |
|
|
|
e76f14 |
-For SELinux guests, you may need to enable SELinux and load policy
|
|
|
e76f14 |
-first. See L</SELINUX> in this manpage.
|
|
|
e76f14 |
+For SELinux guests, you may need to relabel the guest after
|
|
|
e76f14 |
+creating new files. See L</SELINUX> below.
|
|
|
e76f14 |
|
|
|
e76f14 |
=item *
|
|
|
e76f14 |
|
|
|
e76f14 |
@@ -486,44 +486,23 @@ L<sd-journal(3)>, L<sd_journal_open(3)>.
|
|
|
e76f14 |
|
|
|
e76f14 |
=head2 SELINUX
|
|
|
e76f14 |
|
|
|
e76f14 |
-We support SELinux guests. To ensure that labeling happens correctly
|
|
|
e76f14 |
-in SELinux guests, you need to enable SELinux and load the guest's
|
|
|
e76f14 |
-policy:
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-=over 4
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-=item 1.
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-Before launching, do:
|
|
|
e76f14 |
-
|
|
|
e76f14 |
- guestfs_set_selinux (g, 1);
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-=item 2.
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-After mounting the guest's filesystem(s), load the policy. This
|
|
|
e76f14 |
-is best done by running the L<load_policy(8)> command in the
|
|
|
e76f14 |
-guest itself:
|
|
|
e76f14 |
-
|
|
|
e76f14 |
- guestfs_sh (g, "/usr/sbin/load_policy");
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-(Older versions of C<load_policy> require you to specify the
|
|
|
e76f14 |
-name of the policy file).
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-=item 3.
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-Optionally, set the security context for the API. The correct
|
|
|
e76f14 |
-security context to use can only be known by inspecting the
|
|
|
e76f14 |
-guest. As an example:
|
|
|
e76f14 |
-
|
|
|
e76f14 |
- guestfs_setcon (g, "unconfined_u:unconfined_r:unconfined_t:s0");
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-=back
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-This will work for running commands and editing existing files.
|
|
|
e76f14 |
-
|
|
|
e76f14 |
-When new files are created, you may need to label them explicitly,
|
|
|
e76f14 |
-for example by running the external command
|
|
|
e76f14 |
-C<restorecon pathname>.
|
|
|
e76f14 |
+We support SELinux guests. However it is not possible to load the
|
|
|
e76f14 |
+SELinux policy of the guest into the appliance kernel. Therefore the
|
|
|
e76f14 |
+strategy for dealing with SELinux guests is to relabel them after
|
|
|
e76f14 |
+making changes.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+In libguestfs E<ge> 1.34 there is a new API, L</guestfs_setfiles>,
|
|
|
e76f14 |
+which can be used for this. To properly use this API you have to
|
|
|
e76f14 |
+parse the guest SELinux configuration. See the L<virt-customize(1)>
|
|
|
e76f14 |
+module F<customize/SELinux_relabel.ml> for how to do this.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+A simpler but slower alternative is to touch F</.autorelabel> in the
|
|
|
e76f14 |
+guest, which means that the guest will relabel itself at next boot.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+Libguestfs E<le> 1.32 had APIs C<guestfs_set_selinux>,
|
|
|
e76f14 |
+C<guestfs_get_selinux>, C<guestfs_setcon> and C<guestfs_getcon>.
|
|
|
e76f14 |
+These did not work properly, are deprecated, and should not be used in
|
|
|
e76f14 |
+new code.
|
|
|
e76f14 |
|
|
|
e76f14 |
=head2 UMASK
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
|
|
|
e76f14 |
index a5ecf5c..6699fc3 100644
|
|
|
e76f14 |
--- a/test-tool/test-tool.c
|
|
|
e76f14 |
+++ b/test-tool/test-tool.c
|
|
|
e76f14 |
@@ -253,7 +253,6 @@ main (int argc, char *argv[])
|
|
|
e76f14 |
printf ("guestfs_get_pgroup: %d\n", guestfs_get_pgroup (g));
|
|
|
e76f14 |
printf ("guestfs_get_program: %s\n", guestfs_get_program (g));
|
|
|
e76f14 |
printf ("guestfs_get_recovery_proc: %d\n", guestfs_get_recovery_proc (g));
|
|
|
e76f14 |
- printf ("guestfs_get_selinux: %d\n", guestfs_get_selinux (g));
|
|
|
e76f14 |
printf ("guestfs_get_smp: %d\n", guestfs_get_smp (g));
|
|
|
e76f14 |
p = guestfs_get_tmpdir (g);
|
|
|
e76f14 |
printf ("guestfs_get_tmpdir: %s\n", p ? : "(null)");
|
|
|
e76f14 |
diff --git a/tests/selinux/run-test.pl b/tests/selinux/run-test.pl
|
|
|
e76f14 |
index f0f241f..7e4620f 100755
|
|
|
e76f14 |
--- a/tests/selinux/run-test.pl
|
|
|
e76f14 |
+++ b/tests/selinux/run-test.pl
|
|
|
e76f14 |
@@ -105,8 +105,6 @@ if ($test_type eq "selinux" && $test_via eq "fuse") {
|
|
|
e76f14 |
# Create a filesystem that could support xattrs and SELinux labels.
|
|
|
e76f14 |
my $g = Sys::Guestfs->new ();
|
|
|
e76f14 |
|
|
|
e76f14 |
-#$g->set_selinux (1) if $test_type eq "selinux";
|
|
|
e76f14 |
-
|
|
|
e76f14 |
$g->add_drive_scratch (256*1024*1024);
|
|
|
e76f14 |
$g->launch ();
|
|
|
e76f14 |
|
|
|
e76f14 |
--
|
|
|
e76f14 |
1.8.3.1
|
|
|
e76f14 |
|