Blame SOURCES/1293.patch

0f2fcc
From 7f6d223078599c3a6a2f26bf89ba8a91afd4cb88 Mon Sep 17 00:00:00 2001
0f2fcc
From: Michal Domonkos <mdomonko@redhat.com>
0f2fcc
Date: Mon, 17 Dec 2018 14:38:22 +0100
0f2fcc
Subject: [PATCH] Add basic integration with %_pkgverify_level
0f2fcc
0f2fcc
RPM 4.14.2 introduced a new low-level security policy for package
0f2fcc
verification configured with the %_pkgverify_level macro:
0f2fcc
0f2fcc
http://rpm.org/wiki/Releases/4.14.2
0f2fcc
0f2fcc
In DNF, signature verification is done via RPM but in a separate step
0f2fcc
that precedes the transaction itself (BaseCli.gpgsigcheck()).  We can
0f2fcc
make use of that to catch signature errors and/or import public keys the
0f2fcc
same way as if gpgcheck was enabled from the start.  To that end, this
0f2fcc
commit forces the gpgcheck and localpkg_gpgcheck options to True if the
0f2fcc
policy would result in signature verification anyway.
0f2fcc
0f2fcc
Resolves RHEL-8 bug:
0f2fcc
https://bugzilla.redhat.com/show_bug.cgi?id=1614351
0f2fcc
---
0f2fcc
 dnf/cli/cli.py           | 18 ++++++++++++++++++
0f2fcc
 dnf/cli/option_parser.py |  2 +-
0f2fcc
 doc/command_ref.rst      |  2 +-
0f2fcc
 doc/conf_ref.rst         | 12 ++++++++++--
0f2fcc
 4 files changed, 30 insertions(+), 4 deletions(-)
0f2fcc
0f2fcc
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
0f2fcc
index ea328702f4..522a2ad936 100644
0f2fcc
--- a/dnf/cli/cli.py
0f2fcc
+++ b/dnf/cli/cli.py
0f2fcc
@@ -972,6 +972,24 @@ def configure(self, args, option_parser=None):
0f2fcc
         if self.base.conf.color != 'auto':
0f2fcc
             self.base.output.term.reinit(color=self.base.conf.color)
0f2fcc
 
0f2fcc
+        if rpm.expandMacro('%_pkgverify_level') in ('signature', 'all'):
0f2fcc
+            forcing = False
0f2fcc
+            for repo in self.base.repos.iter_enabled():
0f2fcc
+                if repo.gpgcheck:
0f2fcc
+                    continue
0f2fcc
+                repo.gpgcheck = True
0f2fcc
+                forcing = True
0f2fcc
+            if not self.base.conf.localpkg_gpgcheck:
0f2fcc
+                self.base.conf.localpkg_gpgcheck = True
0f2fcc
+                forcing = True
0f2fcc
+            if forcing:
0f2fcc
+                logger.warning(
0f2fcc
+                    _("Warning: Enforcing GPG signature check globally "
0f2fcc
+                      "as per active RPM security policy (see 'gpgcheck' in "
0f2fcc
+                      "dnf.conf(5) for how to squelch this message)"
0f2fcc
+                      )
0f2fcc
+                )
0f2fcc
+
0f2fcc
     def _read_conf_file(self, releasever=None):
0f2fcc
         timer = dnf.logging.Timer('config')
0f2fcc
         conf = self.base.conf
0f2fcc
diff --git a/dnf/cli/option_parser.py b/dnf/cli/option_parser.py
0f2fcc
index e60179cfac..ba5a316c79 100644
0f2fcc
--- a/dnf/cli/option_parser.py
0f2fcc
+++ b/dnf/cli/option_parser.py
0f2fcc
@@ -274,7 +274,7 @@ def _main_parser(self):
0f2fcc
                                  help=_("disable removal of dependencies that are no longer used"))
0f2fcc
         main_parser.add_argument("--nogpgcheck", action="store_false",
0f2fcc
                                  default=None, dest='gpgcheck',
0f2fcc
-                                 help=_("disable gpg signature checking"))
0f2fcc
+                                 help=_("disable gpg signature checking (if RPM policy allows)"))
0f2fcc
         main_parser.add_argument("--color", dest="color", default=None,
0f2fcc
                                  help=_("control whether color is used"))
0f2fcc
         main_parser.add_argument("--refresh", dest="freshest_metadata",
0f2fcc
diff --git a/doc/command_ref.rst b/doc/command_ref.rst
0f2fcc
index 6ba31ff9be..70659e6560 100644
0f2fcc
--- a/doc/command_ref.rst
0f2fcc
+++ b/doc/command_ref.rst
0f2fcc
@@ -275,7 +275,7 @@ Options
0f2fcc
     do not install documentation by using rpm flag 'RPMTRANS_FLAG_NODOCS'
0f2fcc
 
0f2fcc
 ``--nogpgcheck``
0f2fcc
-    skip checking GPG signatures on packages
0f2fcc
+    skip checking GPG signatures on packages (if RPM policy allows)
0f2fcc
 
0f2fcc
 ``--noplugins``
0f2fcc
     Disable all plugins.
0f2fcc
diff --git a/doc/conf_ref.rst b/doc/conf_ref.rst
0f2fcc
index 979e2d18c6..6bbcbda9c0 100644
0f2fcc
--- a/doc/conf_ref.rst
0f2fcc
+++ b/doc/conf_ref.rst
0f2fcc
@@ -452,7 +452,11 @@ configuration.
0f2fcc
 ``gpgcheck``
0f2fcc
     :ref:`boolean <boolean-label>`
0f2fcc
 
0f2fcc
-    Whether to perform GPG signature check on packages found in this repository. The default is False.
0f2fcc
+    Whether to perform GPG signature check on packages found in this repository.
0f2fcc
+    The default is False.
0f2fcc
+    This option can only be used to strengthen the active RPM security policy set with the `%_pkgverify_level` macro (see /usr/lib/rpm/macros for details).
0f2fcc
+    That means, if the macro is set to `signature` or `all` and this option is False, it will be overridden to True when DNF runs and a warning will be printed.
0f2fcc
+    To squelch the warning, make sure this option is True on every enabled repository and also enable :ref:`localpkg_gpgcheck <localpkg_gpgcheck-label>`.
0f2fcc
 
0f2fcc
 .. _include-label:
0f2fcc
 
0f2fcc
@@ -470,10 +474,14 @@ configuration.
0f2fcc
 
0f2fcc
     Determines how DNF resolves host names. Set this to '4'/'IPv4' or '6'/'IPv6' to resolve to IPv4 or IPv6 addresses only. By default, DNF resolves to either addresses.
0f2fcc
 
0f2fcc
+.. _localpkg_gpgcheck-label:
0f2fcc
+
0f2fcc
 ``localpkg_gpgcheck``
0f2fcc
     :ref:`boolean <boolean-label>`
0f2fcc
 
0f2fcc
-    Whether to perform a GPG signature check on local packages (packages in a file, not in a repositoy). The default is False.
0f2fcc
+    Whether to perform a GPG signature check on local packages (packages in a file, not in a repository).
0f2fcc
+    The default is False.
0f2fcc
+    This option is subject to the active RPM security policy (see :ref:`gpgcheck <gpgcheck-label>` for more details).
0f2fcc
 
0f2fcc
 ``max_parallel_downloads``
0f2fcc
     :ref:`integer <integer-label>`