From patchwork Tue Jul 11 18:12:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wojtek Kosior X-Patchwork-Id: 1052 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id BECA927BBEA; Tue, 11 Jul 2023 20:56:44 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CF14327BBE2 for ; Tue, 11 Jul 2023 20:56:43 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJJSy-00073h-AO; Tue, 11 Jul 2023 15:56:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJHrK-0005V8-JX for guix-patches@gnu.org; Tue, 11 Jul 2023 14:13:11 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJHrG-000806-Fx for guix-patches@gnu.org; Tue, 11 Jul 2023 14:13:10 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJHrB-0006w4-MX; Tue, 11 Jul 2023 14:13:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64573] [PATCH 0/3] guix: build: python-build-system: Have applications by default ignore non-Guix libraries in user site dir Resent-From: Wojtek Kosior Original-Sender: "Debbugs-submit" Resent-CC: lars@6xq.net, jgart@dismail.de, guix-patches@gnu.org Resent-Date: Tue, 11 Jul 2023 18:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64573 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64573@debbugs.gnu.org Cc: Wojtek Kosior , Lars-Dominik Braun , jgart X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Lars-Dominik Braun , jgart Received: via spool by submit@debbugs.gnu.org id=B.168909916026631 (code B ref -1); Tue, 11 Jul 2023 18:13:01 +0000 Received: (at submit) by debbugs.gnu.org; 11 Jul 2023 18:12:40 +0000 Received: from localhost ([127.0.0.1]:50992 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJHqq-0006vT-8q for submit@debbugs.gnu.org; Tue, 11 Jul 2023 14:12:40 -0400 Received: from lists.gnu.org ([209.51.188.17]:59356) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJHqk-0006vF-R4 for submit@debbugs.gnu.org; Tue, 11 Jul 2023 14:12:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJHqk-0005Rz-ES for guix-patches@gnu.org; Tue, 11 Jul 2023 14:12:34 -0400 Received: from koszko.org ([93.95.227.159]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJHqi-0007yv-6r for guix-patches@gnu.org; Tue, 11 Jul 2023 14:12:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=koszko.org; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=UZLmtaXhzxOKFnOpqUhuOOFvKTulsIoHSFjBybZnhAw=; b=dpMrDV/PQ94mKQuJGR1MGz3dnO LgxHgzNO4l8gqkSvFzT03y28iKhBM0SN6umSZH/YLRLWmEZa9Kftmznlwxl3y2Gezx6hP76QdjqeC 2rcDchb9wf7y/oU5uSxHvH2fggpjO8RLL7vt7OjqHieGZUiO0WPIDfKXfqu0xKCrnW5j1LixTlb0n RZJRwLmWVHiKzhnQk6G85OS2Pw0kzn9X3erLZx70S1QJII3+uVFq2Ng8beMXREH80Hd6cejABHkkW i2Jlf9nPs7aJrsYmDzzjAsa1GO2aTOvfdmKxEzMxGpkxVE1aQmAxHIt95MoMY9YX1tK0w553miEIY hrqRibEHiNu9B/PyP5IWiC5qrXDYkhNjHzmdmKFIb8Zm3U2TZ/3+Ruct+mf90OJfIHSerQwdmqvi0 TH5U5z2ebJJzzPCxWB2/ZWmy+x+lGIqFxg4p7z13j0ERs3NOb07O8cqS+RsPBpTvE+etLTeF9ZMuv IAS3qk5l2BCfeNjRXAPJkUz+SnjDODwd/n2PoQ3trnafj4zcXIfayGET0oIfLYK69PkApnWvmDJgB hQK+qTTr1C+hQEspuglIU2t65D3iiWKOfJj9kEURnHaKdWpEo0W/rlJXa+u7ATmrBMCSOrPM7Xwgq QFu0HqHV0TbA7/ica4j7MQzjCm5VF2DfGplzwncwY=; Received: from [77.252.47.107] (helo=localhost.localdomain) by koszko.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qJHqX-0007gL-Qg; Tue, 11 Jul 2023 20:12:21 +0200 Date: Tue, 11 Jul 2023 20:12:12 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Received-SPF: pass client-ip=93.95.227.159; envelope-from=koszko@koszko.org; helo=koszko.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Tue, 11 Jul 2023 15:56:05 -0400 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Wojtek Kosior X-ACL-Warn: , Wojtek Kosior via Guix-patches X-Patchwork-Original-From: Wojtek Kosior via Guix-patches via From: Wojtek Kosior Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Python applications used to prioritize loading their libraries from so-called "user site dir" (usually in ~/.local/lib/python/site-packages). The libraries would only be loaded from /gnu/store when not found in the user site dir. This used to cause hard-to-diagnose bugs like [1] when a user happened to have a similar but incompatible version of a library installed via pip. These patches modify the python-build-system's procedure responsible for wrapping executables. The modified proc defines a PYTHONNOUSERSITE variable which makes Python applications disregard the user site dir when loading libraries. While this solution does harden most Python applications, it can also break a few ones like pip that operate on the user site dir itself. To work around that, the second patch introduces a change to pip to allow installing to the user site directory even when PYTHONNOUSERSITE is set by the Guix-created wrapper script. The third patch adds a boolean argument called disable-user-site? to python-build-system. Packagers can set this argument to #f on per-package basis to disable the hardening behavior in case it breaks some application. Note that in the long run, it might be beneficial (although more time-consuming) to leave disable-user-site? as #t everywhere and instead modify the problematic applications — as done here with python-pip. It might even be practical to only merge the first 2 patches from this series. Please note that virtualenvs and packages that operate on them are likely unaffected by this change. The initial bug doesn't even occur with virtualenvs. I tested the changes with ./pre-inst-env guix shell -C --network --no-cwd python-xmldiff coreutils python-pip pip install xmldiff==2.4 echo > ~/.local/lib/python3.10/site-packages/xmldiff/main.py xmldiff --help Without any patches, the 4th line fails. With the patches applied, the 4th line succeeds and prints xmldiff's usage info [1] https://issues.guix.gnu.org/63912 Wojtek Kosior (3): guix: build: python-build-system: Don't process user site dir gnu: python-pip: Enable user site even with PYTHONNOUSERSITE guix: build: python-build-system: Honor disable-user-site? argument gnu/packages/python-build.scm | 10 +++++++++- guix/build-system/python.scm | 2 ++ guix/build/python-build-system.scm | 27 ++++++++++++++++++--------- 3 files changed, 29 insertions(+), 10 deletions(-) base-commit: 67e22584faaa558c2a5834a5013d77660ec45e85