Blame SOURCES/0011-tools-install-script-Add-config-file-f-option.patch

b5bae8
From 08fb8316b4ac42fe74c1fa5ca0ac593222cdf81a Mon Sep 17 00:00:00 2001
b5bae8
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
b5bae8
Date: Wed, 3 Jul 2019 14:55:24 +0200
b5bae8
Subject: [PATCH] tools,install-script: Add --config-file (-f) option
b5bae8
MIME-Version: 1.0
b5bae8
Content-Type: text/plain; charset=UTF-8
b5bae8
Content-Transfer-Encoding: 8bit
b5bae8
b5bae8
Let's add a new option so users can set their config from a file,
b5bae8
instead of directly passing the values via command-line.
b5bae8
b5bae8
CVE-2019-13313
b5bae8
Libosinfo: osinfo-install-script option leaks password via command line
b5bae8
argument. 'osinfo-install-script' is used to generate a script for
b5bae8
automated guest installations. It accepts user and admin passwords via
b5bae8
command line arguments, thus leaking them via process listing.
b5bae8
b5bae8
Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
b5bae8
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
b5bae8
---
b5bae8
 tools/osinfo-install-script.c | 102 +++++++++++++++++++++++++++++++++-
b5bae8
 1 file changed, 101 insertions(+), 1 deletion(-)
b5bae8
b5bae8
diff --git a/tools/osinfo-install-script.c b/tools/osinfo-install-script.c
b5bae8
index 15af48d..af58440 100644
b5bae8
--- a/tools/osinfo-install-script.c
b5bae8
+++ b/tools/osinfo-install-script.c
b5bae8
@@ -37,6 +37,33 @@ static gboolean list_profile = FALSE;
b5bae8
 static gboolean list_inj_method = FALSE;
b5bae8
 static gboolean quiet = FALSE;
b5bae8
 
b5bae8
+static const gchar *configs[] = {
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_HARDWARE_ARCH,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_L10N_TIMEZONE,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_L10N_LANGUAGE,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_L10N_KEYBOARD,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_ADMIN_PASSWORD,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_USER_PASSWORD,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_USER_LOGIN,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_USER_REALNAME,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_USER_AUTOLOGIN,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_USER_ADMIN,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_REG_LOGIN,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_REG_PASSWORD,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_REG_PRODUCTKEY,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_HOSTNAME,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_SCRIPT_DISK,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_AVATAR_LOCATION,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_AVATAR_DISK,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_PRE_INSTALL_DRIVERS_DISK,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_PRE_INSTALL_DRIVERS_LOCATION,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_POST_INSTALL_DRIVERS_DISK,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_POST_INSTALL_DRIVERS_LOCATION,
b5bae8
+    OSINFO_INSTALL_CONFIG_PROP_DRIVER_SIGNING,
b5bae8
+    NULL
b5bae8
+};
b5bae8
+
b5bae8
 static OsinfoInstallConfig *config;
b5bae8
 
b5bae8
 static gboolean handle_config(const gchar *option_name G_GNUC_UNUSED,
b5bae8
@@ -65,6 +93,47 @@ static gboolean handle_config(const gchar *option_name G_GNUC_UNUSED,
b5bae8
 }
b5bae8
 
b5bae8
 
b5bae8
+static gboolean handle_config_file(const gchar *option_name G_GNUC_UNUSED,
b5bae8
+                                   const gchar *value,
b5bae8
+                                   gpointer data G_GNUC_UNUSED,
b5bae8
+                                   GError **error)
b5bae8
+{
b5bae8
+    GKeyFile *key_file = NULL;
b5bae8
+    gchar *val = NULL;
b5bae8
+    gsize i;
b5bae8
+    gboolean ret = FALSE;
b5bae8
+
b5bae8
+    key_file = g_key_file_new();
b5bae8
+    if (!g_key_file_load_from_file(key_file, value, G_KEY_FILE_NONE, error))
b5bae8
+        goto error;
b5bae8
+
b5bae8
+    for (i = 0; configs[i] != NULL; i++) {
b5bae8
+        val = g_key_file_get_string(key_file, "install-script", configs[i], error);
b5bae8
+        if (val == NULL) {
b5bae8
+            if (g_error_matches(*error, G_KEY_FILE_ERROR,
b5bae8
+                                G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
b5bae8
+                g_clear_error(error);
b5bae8
+                continue;
b5bae8
+            }
b5bae8
+
b5bae8
+            goto error;
b5bae8
+        }
b5bae8
+
b5bae8
+        osinfo_entity_set_param(OSINFO_ENTITY(config),
b5bae8
+                                configs[i],
b5bae8
+                                val);
b5bae8
+        g_free(val);
b5bae8
+    }
b5bae8
+
b5bae8
+    ret = TRUE;
b5bae8
+
b5bae8
+error:
b5bae8
+    g_key_file_unref(key_file);
b5bae8
+
b5bae8
+    return ret;
b5bae8
+}
b5bae8
+
b5bae8
+
b5bae8
 static GOptionEntry entries[] =
b5bae8
 {
b5bae8
     { "profile", 'p', 0, G_OPTION_ARG_STRING, (void*)&profile,
b5bae8
@@ -78,6 +147,9 @@ static GOptionEntry entries[] =
b5bae8
     { "config", 'c', 0, G_OPTION_ARG_CALLBACK,
b5bae8
       handle_config,
b5bae8
       N_("Set configuration parameter"), "key=value" },
b5bae8
+    { "config-file", 'f', 0, G_OPTION_ARG_CALLBACK,
b5bae8
+      handle_config_file,
b5bae8
+      N_("Set configuration parameters"), "file:///path/to/config/file" },
b5bae8
     { "list-config", '\0', 0, G_OPTION_ARG_NONE, (void*)&list_config,
b5bae8
       N_("List configuration parameters"), NULL },
b5bae8
     { "list-profiles", '\0', 0, G_OPTION_ARG_NONE, (void*)&list_profile,
b5bae8
@@ -448,6 +520,15 @@ script. Defaults to C<media>, but can also be C<network>.
b5bae8
 
b5bae8
 Set the configuration parameter C<key> to C<value>.
b5bae8
 
b5bae8
+=item B<--config-file=config-file>
b5bae8
+
b5bae8
+Set the configurations parameters according to the config-file passed.
b5bae8
+
b5bae8
+Note that use of --config-file is strongly recommended if the user or
b5bae8
+admin passwords need to be set. Providing passwords directly using
b5bae8
+B<--config=> is insecure as the password is visible to all processes
b5bae8
+and users on the same host.
b5bae8
+
b5bae8
 =back
b5bae8
 
b5bae8
 =head1 CONFIGURATION KEYS
b5bae8
@@ -510,9 +591,29 @@ The software registration user password
b5bae8
 
b5bae8
 =back
b5bae8
 
b5bae8
+=head1 CONFIGURATION FILE FORMAT
b5bae8
+
b5bae8
+The configuration file must consist in a file which contains a
b5bae8
+`install-script` group and, under this group, C<key>=C<value>
b5bae8
+pairs, as shown below:
b5bae8
+
b5bae8
+[install-script]
b5bae8
+l10n-timezone=GMT
b5bae8
+l10n-keyboard=uk
b5bae8
+l10n-language=en_GB
b5bae8
+admin-password=123456
b5bae8
+user-login=berrange
b5bae8
+user-password=123456
b5bae8
+user-realname="Daniel P Berrange"
b5bae8
+
b5bae8
 =head1 EXAMPLE USAGE
b5bae8
 
b5bae8
-The following usage generates a Fedora 16 kickstart script
b5bae8
+The following usages generates a Fedora 16 kickstart script
b5bae8
+
b5bae8
+  # osinfo-install-script \
b5bae8
+         --profile jeos \
b5bae8
+         --config-file /path/to/config/file \
b5bae8
+         fedora16
b5bae8
 
b5bae8
   # osinfo-install-script \
b5bae8
          --profile jeos \
b5bae8
-- 
b5bae8
2.21.0
b5bae8