From patchwork Sun Oct 6 17:39:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nigko Yerden X-Patchwork-Id: 68652 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 BAA9E27BBE9; Sun, 6 Oct 2024 18:47:17 +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=-7.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS autolearn=unavailable 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 3ACF727BBE2 for ; Sun, 6 Oct 2024 18:47:15 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxVLP-0006mf-Hr; Sun, 06 Oct 2024 13:46:59 -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 1sxVLM-0006mR-VY for guix-patches@gnu.org; Sun, 06 Oct 2024 13:46:57 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sxVLL-0005xH-Th; Sun, 06 Oct 2024 13:46:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=DhFCjHtjTSGDWaIwvDpa2zZImxW8GkMJ5v4pSZoR4lQ=; b=jipBlcs8dYECbjpLAfL/mP/TVhgwI5poodP72X0koUnpjWxs1H2tKutYpgPYXeWSr9YoR0/60RI82R9fbFXZZdNSErodFoDs3MIZAwWkfne8Ax9TqgVZV8xoUDvGxTy/1U7EOQc/H/g+CxzEGsY2NVHYtdXtEUQAdjzVtvk8ciL57caDuj3wKwPPVLYByBloOUvz2M2xi8DJg02ep9f7o4ndRzJ9u3pebqb8qUBPjH9QZ7SNws9FYN27R3kAxCbKWd/PM5jkUJYiEzKhqTLvRUajrPdrhYPQvatrG5xOeqObUJ4CSu5OzhL3BNug9jB74GU4StZqV+kIlZgetywmLA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sxVLR-00071y-Qq; Sun, 06 Oct 2024 13:47:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70341] [PATCH v9] services: tor: Add support for pluggable transports. References: <11e72216f4be8b6559ecc04646fd722daa5dd09d.1712846897.git.nigko.yerden@gmail.com> In-Reply-To: <11e72216f4be8b6559ecc04646fd722daa5dd09d.1712846897.git.nigko.yerden@gmail.com> Resent-From: Nigko Yerden Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 06 Oct 2024 17:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70341 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70341@debbugs.gnu.org Cc: Nigko Yerden , Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 70341-submit@debbugs.gnu.org id=B70341.172823678726966 (code B ref 70341); Sun, 06 Oct 2024 17:47:01 +0000 Received: (at 70341) by debbugs.gnu.org; 6 Oct 2024 17:46:27 +0000 Received: from localhost ([127.0.0.1]:42271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxVKs-00070e-Kb for submit@debbugs.gnu.org; Sun, 06 Oct 2024 13:46:27 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:57429) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxVKo-00070N-Ns for 70341@debbugs.gnu.org; Sun, 06 Oct 2024 13:46:25 -0400 Received: by mail-wr1-f66.google.com with SMTP id ffacd0b85a97d-37d00322446so2920047f8f.2 for <70341@debbugs.gnu.org>; Sun, 06 Oct 2024 10:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728236715; x=1728841515; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DhFCjHtjTSGDWaIwvDpa2zZImxW8GkMJ5v4pSZoR4lQ=; b=a8yeqQHnCyj/ZunLL7GlELa5PkwtONLbeiXhwV6U/MeuQhpEBEBsw1VYzqTDE0HoAV yih333MQ7l0ydt//m+2TScL3+hDQ8Z0nmokwaalM7S3LY4+lKlQ1/vPSBG5r+tOUCN/Y 6h8M9b+tzqNCgufV+Ag92gj6TE+VA9eGiWGCmyp1UwAdQrJ00V0IPRhtm05oPLA8A2Uh A//S/3rGQ2Y+p/E4rR4UIetgHZEADr6Yrn7lIq7mQXJw6ux8d79qT5PTF/at1sHmb0Od T930h+cxfdgQgE5mXUkNk8l/v81g04ALPvJA4AhTU38vkVxZF1HC/aWfoCFokueVd2BL gB5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728236715; x=1728841515; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DhFCjHtjTSGDWaIwvDpa2zZImxW8GkMJ5v4pSZoR4lQ=; b=VRh+VGrw0XBJA2jYCkhZ8Qh7TeKHSS3DhgShHPcfA0kqPBBsZxE8bftjXa5F3IJYL/ P0pT/HlAlgLgx/fUv21IIAaU4R8cqKJbhfxQivobFG6kRf7/jS3ypX2NWMiAy8pAZuPK ludVbsAkWbL85iHmPupcc38MCvKBMlhDjQ/TVsHBcfRk3PiZCjDkSh1S1ZSwCPavNPQV nJLGgwPufJr7BphB+xk033W5Lu1BYlqA/PQlm44FqCt99huf7rwhK2Bn6VchcXcrIF7w nXcRYc0bzxGkzbejXV3ZZPMvBmxGGMmZ7a+6OQuC2IWwWjupuD1LLV18d4J8Mt4XmPom aBGw== X-Gm-Message-State: AOJu0YzU1/g0lT0haN+2nY+v+W7ni0M2z+MzqgAcUZ3Yzh8jBJ78eVhb 1ZlFdCCvZDcK5yTmajtQF3y+K7IdRAc7t0k3bWJRO1KO7vk+oSYIo7NXjqk8 X-Google-Smtp-Source: AGHT+IFl2tduIPLAkD84l8dFJBch0NyZnga5MtQR6I0omfcbSPTnJctAzRRDXkx4hgxNltx0FHNVdA== X-Received: by 2002:adf:cf0d:0:b0:37c:d2ac:dd7d with SMTP id ffacd0b85a97d-37d0e783784mr4645843f8f.30.1728236715006; Sun, 06 Oct 2024 10:45:15 -0700 (PDT) Received: from localhost.localdomain ([188.168.141.132]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d1690f270sm3991574f8f.21.2024.10.06.10.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2024 10:45:14 -0700 (PDT) From: Nigko Yerden Date: Sun, 6 Oct 2024 22:39:08 +0500 Message-ID: X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Pluggable transports are programs that disguise Tor traffic, which can be useful in case Tor is censored. Pluggable transports cannot be configured by #:config-file file exclusively because Tor process is run via 'least-authority-wrapper' and cannot have access to transport plugin, which is a separate executable (Bug#70302, Bug#70332). ;;; Copyright © 2024 Nigko Yerden * doc/guix.texi (Networking Services): Document 'tor-transport-plugin' data type and 'transport-plugins' option for 'tor-configuration. * gnu/services/networking.scm: Export 'tor-configuration-transport-plugins', 'tor-transport-plugin', 'tor-transport-plugin?', 'tor-plugin-role', 'tor-plugin-protocol', and 'tor-plugin-program'. (): Add 'transport-plugins' field. (): New variable. (tor-configuration->torrc): Add content to 'torrc' computed-file. (tor-shepherd-service): Add file-system-mapping(s). Change-Id: I1b0319358778c7aee650bc843e021a6803a1cf3a --- This v9 patch version is exactly the same as v8 one. I submit this version exclusively because of qa.quix.gnu.org weird behavior. Regards, Nigko doc/guix.texi | 68 ++++++++++++++++++++++++++++++++++++ gnu/services/networking.scm | 69 ++++++++++++++++++++++++++++++------- 2 files changed, 124 insertions(+), 13 deletions(-) base-commit: 964c075dc5bcd1875b61c6eafbaab990cf49f69d diff --git a/doc/guix.texi b/doc/guix.texi index 52e36e4354..0405b1536d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -22045,6 +22045,12 @@ Networking Services @file{/var/run/tor/control-sock}, which will be made writable by members of the @code{tor} group. +@item @code{transport-plugins} (default: @code{'()}) +The list of @code{} records to use. +For any transport plugin you include in this list, appropriate +configuration line to enable transport plugin will be automatically +added to the default configuration file. + @end table @end deftp @@ -22073,6 +22079,68 @@ Networking Services @end table @end deftp +@cindex pluggable transports, tor +@deftp {Data Type} tor-transport-plugin +Data type representing a Tor pluggable transport plugin in +@code{tor-configuration}. Plugguble transports are programs +that disguise Tor traffic, which can be useful in case Tor is +censored. See the the Tor project's +@url{https://tb-manual.torproject.org/circumvention/, +documentation} and +@url{https://spec.torproject.org/pt-spec/index.html, +specification} for more information. + +Each transport plugin corresponds either to +@code{ClientTransportPlugin ...} or to +@code{ServerTransportPlugin ...} line in the default +configuration file, see @command{man tor}. +Available @code{tor-transport-plugin} fields are: + +@table @asis +@item @code{role} (default: @code{'client}) +This must be either @code{'client} or @code{'server}. Otherwise, +an error is raised. Set the @code{'server} value if you want to +run a bridge to help censored users connect to the Tor network, see +@url{https://community.torproject.org/relay/setup/bridge/, +the Tor project's brige guide}. Set the @code{'client} value +if you want to connect to somebody else's bridge, see +@url{https://bridges.torproject.org/, the Tor project's +``Get Bridges'' page}. In both cases the required +additional configuration should be provided via +@code{#:config-file} option of @code{tor-configuration}. +@item @code{protocol} (default: @code{"obfs4"}) +A string that specifies a pluggable transport protocol. +@item @code{program} +This must be a ``file-like'' object or a string +pointing to the pluggable transport plugin executable. +This option allows the Tor daemon run inside the container +to access the executable and all the references +(e.g. package dependencies) attached to it. +@end table + +Suppose you would like Tor daemon to use obfs4 type obfuscation and +to connect to Tor network via obfs4 bridge (a nonpublic Tor relay with +support for obfs4 type obfuscation). Then you may go to +@url{https://bridges.torproject.org/, https://bridges.torproject.org/} +and get there a couple of bridge lines (each starts with @code{obfs4 ...}) +and use these lines in tor-service-type configuration as follows: +@lisp +(service tor-service-type + (tor-configuration + (config-file (plain-file "torrc" + "\ +UseBridges 1 +Bridge obfs4 ... +Bridge obfs4 ...")) + (transport-plugins + (list (tor-transport-plugin + (program + (file-append + go-gitlab-torproject-org-tpo-anti-censorship-pluggable-transports-lyrebird + "/bin/lyrebird"))))))) +@end lisp +@end deftp + The @code{(gnu services rsync)} module provides the following services: You might want an rsync daemon if you have files that you want available diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 12d8934e43..5a4e3a960d 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -160,10 +160,16 @@ (define-module (gnu services networking) tor-configuration-hidden-services tor-configuration-socks-socket-type tor-configuration-control-socket-path + tor-configuration-transport-plugins tor-onion-service-configuration tor-onion-service-configuration? tor-onion-service-configuration-name tor-onion-service-configuration-mapping + tor-transport-plugin + tor-transport-plugin? + tor-plugin-role + tor-plugin-protocol + tor-plugin-program tor-hidden-service ; deprecated tor-service-type @@ -966,7 +972,9 @@ (define-record-type* (socks-socket-type tor-configuration-socks-socket-type ; 'tcp or 'unix (default 'tcp)) (control-socket? tor-configuration-control-socket-path - (default #f))) + (default #f)) + (transport-plugins tor-configuration-transport-plugins + (default '()))) (define %tor-accounts ;; User account and groups for Tor. @@ -996,10 +1004,24 @@ (define-configuration/no-serialization tor-onion-service-configuration @end lisp maps ports 22 and 80 of the Onion Service to the local ports 22 and 8080.")) +(define-record-type* + tor-transport-plugin make-tor-transport-plugin + tor-transport-plugin? + (role tor-plugin-role + (default 'client) + (sanitize (lambda (value) + (if (memq value '(client server)) + value + (configuration-field-error #f 'role value))))) + (protocol tor-plugin-protocol + (default "obfs4")) + (program tor-plugin-program)) + (define (tor-configuration->torrc config) "Return a 'torrc' file for CONFIG." (match-record config - (tor config-file hidden-services socks-socket-type control-socket?) + (tor config-file hidden-services socks-socket-type control-socket? + transport-plugins) (computed-file "torrc" (with-imported-modules '((guix build utils)) @@ -1038,6 +1060,20 @@ (define (tor-configuration->torrc config) (cons name mapping))) hidden-services)) + (for-each (match-lambda + ((role-string protocol program) + (format port "\ +~aTransportPlugin ~a exec ~a~%" + role-string protocol program))) + '#$(map (match-lambda + (($ role protocol program) + (list (if (eq? role 'client) + "Client" + "Server") + protocol + program))) + transport-plugins)) + (display "\ ### End of automatically generated lines.\n\n" port) @@ -1050,20 +1086,27 @@ (define (tor-configuration->torrc config) (define (tor-shepherd-service config) "Return a running Tor." (let* ((torrc (tor-configuration->torrc config)) + (transport-plugins (tor-configuration-transport-plugins config)) (tor (least-authority-wrapper (file-append (tor-configuration-tor config) "/bin/tor") #:name "tor" - #:mappings (list (file-system-mapping - (source "/var/lib/tor") - (target source) - (writable? #t)) - (file-system-mapping - (source "/var/run/tor") - (target source) - (writable? #t)) - (file-system-mapping - (source torrc) - (target source))) + #:mappings (append + (list (file-system-mapping + (source "/var/lib/tor") + (target source) + (writable? #t)) + (file-system-mapping + (source "/var/run/tor") + (target source) + (writable? #t)) + (file-system-mapping + (source torrc) + (target source))) + (map (lambda (plugin) + (file-system-mapping + (source (tor-plugin-program plugin)) + (target source))) + transport-plugins)) #:namespaces (delq 'net %namespaces)))) (list (shepherd-service (provision '(tor))