unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Danny Milosavljevic <dannym@scratchpost.org>
To: Mark H Weaver <mhw@netris.org>
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>, 43501@debbugs.gnu.org
Subject: bug#43501: Whitelisting/blacklisting transitive package dependencies
Date: Sat, 19 Sep 2020 16:24:11 +0200	[thread overview]
Message-ID: <20200919162411.1b6f621b@scratchpost.org> (raw)
In-Reply-To: <87wo0q77t3.fsf@netris.org>

[-- Attachment #1: Type: text/plain, Size: 8322 bytes --]

Hi,

On Fri, 18 Sep 2020 23:40:13 -0400
Mark H Weaver <mhw@netris.org> wrote:

> I think it's important that Guix core functionality should be usable
> without installing a collection of patented media codecs.  Those plugins
> should be purely optional.  In my opinion, we should find a way to
> eliminate those dependencies.

I agree that it would be good to prevent weird dependencies from creeping in--for
your stated reasons, but also for a lot of other reasons, chief of which is that
the most secure source code is the source code that has been eliminated.

Also, Guix sometimes pulls in transitive dependencies for the weirdest things.

The "*-minimal" packages we have make it less bad.

Still, it would nice to also have something that automatically checks whether
there are weird transitive inputs of a package, for each package (*especially*
in order to use that for "-minimal" packages).

I sometimes add #:disallowed-references after tracking down problems of
unintended transitive inputs (for example see f2fs-tools/static).  But even
that disallows just one specific reference (one package version).

What I want is to disallow any package of that name entirely in the dependency
graph--or even disallow references to specific source files (or other groups of
packages) entirely.
And I want it to keep disallowing it mechanically without me having to
remember it.

Guix lint already does something like I want, but for direct (non-transitive)
inputs.

It should be possible to add a "guix lint" check that also checks transitive
inputs of packages for suspicious packages.

The maintenance of a transitive-whitelist/-blacklist per package would then
probably be have to be done inside guix lint, though.  It could be nicer if
there were package fields for those for it eventually.  But for now, I guess
inside guix lint is good enough.

That said, for practicality one has to find some kind of groups of packages,
in order to keep the whitelist/blacklist from ballooning.  For now, I assume
that each group has an extra source file--which we know is not true in Guix
right now.  But we could make it true.

I started to add something to guix lint (possible procedures to use:
package-transitive-inputs, package-transitive-propagated-inputs,
package-transitive-native-inputs)--see patch below.  But note that it just
complains about everything now--we would still have to specify what is
"bad".

I would suggest to have a whitelist (of file names) and a blacklist
(of file names), and the following:
If a package has a whitelist and a transitive dependency is not on the
whitelist, complain.  If a package does not have a whitelist but does
have a blacklist and a transitive dependency is on the blacklist, complain.

I still find it illuminating as it is now.  Try:

$ guix lint qemu
[...]
gnu/packages/virtualization.scm:260:5: qemu@5.0.0: 'gnu/packages/dbm.scm' should probably not be referred to (but it is--because of packages (gdbm))
[...]
gnu/packages/virtualization.scm:260:5: qemu@5.0.0: 'gnu/packages/spice.scm' should probably not be referred to (but it is by packages (libcacard spice usbredir virglrenderer spice-protocol))
gnu/packages/virtualization.scm:260:5: qemu@5.0.0: 'gnu/packages/gl.scm' should probably not be referred to (but it is by packages (libepoxy mesa))
[...]
gnu/packages/virtualization.scm:260:5: qemu@5.0.0: 'gnu/packages/dbm.scm' should probably not be referred to (but it is by packages (gdbm))
[...]
gnu/packages/virtualization.scm:260:5: qemu@5.0.0: 'gnu/packages/pulseaudio.scm' should probably not be referred to (but it is because of packages (pulseaudio))

WTF!

Also, for the special case where no package in a source file A should refer to
any package in a source file B, it could be enough to establish a convention
of commenting out the respective "#:use-module (...)" in source file A (and
adding a "DO NOT USE" text to it), and never deleting that comment.

That way, once somebody had found what module one should not ever import, he
could document that fact.

diff --git a/guix/lint.scm b/guix/lint.scm
index ec43a4dcad..d65ac34441 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -72,6 +72,7 @@
   #:export (check-description-style
             check-inputs-should-be-native
             check-inputs-should-not-be-an-input-at-all
+            check-transitive-input-sanity
             check-patch-file-names
             check-synopsis-style
             check-derivation
@@ -287,6 +288,38 @@ of a package, and INPUT-NAMES, a list of package specifications such as
                                input))))
                  packages outputs))))
 
+(define (check-transitive-input-sanity package)
+  (let* ((examined-package-name (package-name package))
+         (examined-package-location (package-location package))
+         (examined-package-source-file-name (location-file examined-package-location))
+         (examined-package-dependency-source-file-names
+          (delete examined-package-source-file-name
+           (delete-duplicates
+            (map (match-lambda
+                  ((key dependency . rest) (location-file (package-location dependency))))
+             (package-transitive-target-inputs package))))))
+    (map (lambda (source-file-name)
+           (let ((packages-in-source-file
+                  (filter (match-lambda
+                            ((key dependency . rest) (string=? source-file-name
+                                                               (location-file
+                                                                (package-location dependency)))))
+                          (package-transitive-target-inputs package))))
+             (make-warning package
+              (G_ "'~a' should probably not be referred to (but it is--because of packages ~a)")
+              (list source-file-name (map (match-lambda
+                                           ((key dependency . rest)
+                                            (package-name dependency)))
+                                          packages-in-source-file))
+               #:field 'inputs)))
+         examined-package-dependency-source-file-names)))
+          (delete examined-package-source-file-name
+           (delete-duplicates
+            (map (match-lambda
+                  ((key dependency . rest) (location-file (package-location dependency))))
+             (package-transitive-target-inputs package))))))
+    (map (lambda (source-file-name)
+           (let ((packages-in-source-file
+                  (filter (match-lambda
+                            ((key dependency . rest) (string=? source-file-name
+                                                               (location-file
+                                                                (package-location dependency)))))
+                          (package-transitive-target-inputs package))))
+             (make-warning package
+              (G_ "'~a' should probably not be referred to (but it is--because of packages ~a)")
+              (list source-file-name (map (match-lambda
+                                           ((key dependency . rest)
+                                            (package-name dependency)))
+                                          packages-in-source-file))
+               #:field 'inputs)))
+         examined-package-dependency-source-file-names)))
+
+    ;; if examined-package-name like '%qemu%':
+    ;;   (package-name (map <car cdr> package-transitive-inputs)) no gstreamer; source file not
+    ;;   gstreamer.scm, gtk.scm.
+    ;;   allowed references to location-files
+  ;; TODO: gstreamer should not be anywhere in any transitive inputs of any qemu
+
 (define (check-inputs-should-be-native package)
   ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
   ;; native inputs.
@@ -1378,6 +1411,10 @@ them for PACKAGE."
 
 (define %local-checkers
   (list
+   (lint-checker
+     (name        'transitive-inputs)
+     (description "Checks transitive inputs")
+     (check check-transitive-input-sanity))
    (lint-checker
      (name        'description)
      (description "Validate package descriptions")

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-09-19 14:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-19  1:45 bug#43501: gst-plugins-bad cannot be built on linux-armhf, breaking qemu Maxim Cournoyer
2020-09-19  3:40 ` Mark H Weaver
2020-09-19 14:24   ` Danny Milosavljevic [this message]
2020-09-20 22:00   ` Mark H Weaver
2020-09-22  2:36     ` Maxim Cournoyer
2020-09-24  4:41       ` bug#43501: gst-plugins-bad cannot be built on linux-armhf Maxim Cournoyer
2020-09-26 18:57         ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200919162411.1b6f621b@scratchpost.org \
    --to=dannym@scratchpost.org \
    --cc=43501@debbugs.gnu.org \
    --cc=maxim.cournoyer@gmail.com \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).