From patchwork Fri May 10 08:32:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nigko Yerden X-Patchwork-Id: 64324 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 D1DBE27BBE2; Fri, 10 May 2024 09:36:23 +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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED 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 6C00F27BBE9 for ; Fri, 10 May 2024 09:36:21 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5Ljb-0001PC-2W; Fri, 10 May 2024 04:36:07 -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 1s5LjZ-0001OM-B5 for guix-patches@gnu.org; Fri, 10 May 2024 04:36:05 -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 1s5LjY-0007Cv-DV; Fri, 10 May 2024 04:36:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s5LjV-0003h4-S0; Fri, 10 May 2024 04:36:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70341] [PATCH v4] 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, guix-patches@gnu.org Resent-Date: Fri, 10 May 2024 08:36: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?= X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 70341-submit@debbugs.gnu.org id=B70341.171533013414176 (code B ref 70341); Fri, 10 May 2024 08:36:01 +0000 Received: (at 70341) by debbugs.gnu.org; 10 May 2024 08:35:34 +0000 Received: from localhost ([127.0.0.1]:41821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5Lj3-0003gZ-0M for submit@debbugs.gnu.org; Fri, 10 May 2024 04:35:33 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:60789) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5Lix-0003gI-OG for 70341@debbugs.gnu.org; Fri, 10 May 2024 04:35:31 -0400 Received: by mail-lj1-f195.google.com with SMTP id 38308e7fff4ca-2e0a0cc5e83so27351211fa.1 for <70341@debbugs.gnu.org>; Fri, 10 May 2024 01:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715330063; x=1715934863; 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=a/XxKLYfLTRZtD/+twN0ygtiWygE2upDzAySnFMBLM0=; b=i3Qq2BgqzjnTh576QIIkdJc4//HOgGJ+eMTK6tKvgd06QJPiybT5ge8NncNNPWPIpX 8n253mESzAaBaeCg4yOJNEUgz7fuLp52azBm9ewugOvQW7H9zjsGXWjQvLBmJXcG+5Om iF9XmOP1+ODuWewRGIy8Tq/Ua9+RT2XnDn07z2SnF388KE/8QqC9g8EHZS0SQLayFsiE WdcXlc5ze30irjKDmpDG59YO38B9IoVh6LnpGHd9qb0voV20XrW3M9GICXjIAJwcb83W Zz6icouExoR74cCD8Xc9/2/HFj+2yKxqXVtDLKnzRuBRkyvnILMfsnCc3njMwGUCnhKk BH3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715330063; x=1715934863; 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=a/XxKLYfLTRZtD/+twN0ygtiWygE2upDzAySnFMBLM0=; b=JeiSq2BcNR2A6qIVEPYlTMjCgP76jLxFXIqj1y1ej4qWn3LXCfOKMV1VOZXUe4coUX yhfYu1811nJ6kGZ/jOtjR8RFlDAr+gBGj/zztVfIFXZBK4szGs8FMW25iVtoaayGl7g/ zv2FoPFauLNHyj/znJzAgUcgnsykDcLMdCtFEsrMEnaKQ94tG3y8MtzBCAXLhiwnj+wv A7iII1HwCVq2I9XuiJusbhacxTutxxEzU99f9xeGjGK9doPQ9pTbojWqp/aUWjy02dR+ nYEwGgRgXF5UI4X0KyvntFHnr4D9XeUVRgwUcE1uv4awkVWh3sE+Wt8RMbu0vrbZcUqR Y26g== X-Gm-Message-State: AOJu0Yws7UJeix5Lzy8eJwpM39p1sdRzZ/VtMCN6mUU/xEf8BzuaETK1 Hy9W8WNGSWPnZtAvRhDA1XNfrUO27FTxyqxbjE8rCKbbQnsyfmsMO6uZF7Pq X-Google-Smtp-Source: AGHT+IEB1GhAaNZ49ERrIZm2e2UXu37XpRB8zRPXIu8HF3Ef+iO6VEuMtaAPoqOx1ge/191bPRHhLA== X-Received: by 2002:a2e:9355:0:b0:2dc:d2c5:ee9 with SMTP id 38308e7fff4ca-2e51fe52115mr11000991fa.2.1715330062336; Fri, 10 May 2024 01:34:22 -0700 (PDT) Received: from localhost.localdomain ([62.33.150.148]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2e4d0bbcc28sm4369801fa.11.2024.05.10.01.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 01:34:21 -0700 (PDT) From: Nigko Yerden Date: Fri, 10 May 2024 13:32:02 +0500 Message-ID: <0983e0fb3aa290e1e0796c31c174bb2b7fdb615e.1715329922.git.nigko.yerden@gmail.com> X-Mailer: git-send-email 2.41.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). Example configuration snippet to be appended to operation-system services (see https://bridges.torproject.org/ to get full bridge's lines): (service tor-service-type (tor-configuration (config-file (plain-file "torrc" "\ UseBridges 1 Bridge obfs4 ... Bridge obfs4 ...")) (transport-plugins (list (tor-transport-plugin (path-to-binary (file-append go-gitlab-torproject-org-tpo-anti-censorship-pluggable-transports-lyrebird "/bin/lyrebird"))))))) * 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-transport-plugin-role', 'tor-transport-plugin-protocol', and 'tor-transport-plugin-path'. (): 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 --- doc/guix.texi | 48 +++++++++++++++++++++++ gnu/services/networking.scm | 76 +++++++++++++++++++++++++++++-------- 2 files changed, 108 insertions(+), 16 deletions(-) base-commit: 360fea15cb25d0cdf55ec55488956257a0219fe4 diff --git a/doc/guix.texi b/doc/guix.texi index 1c1e0164e7..ae9bd7e290 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -127,6 +127,7 @@ Copyright @copyright{} 2024 Herman Rimm@* Copyright @copyright{} 2024 Matthew Trzcinski@* Copyright @copyright{} 2024 Richard Sent@* +Copyright @copyright{} 2024 Nigko Yerden@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -21877,6 +21878,13 @@ 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 @@ -21905,6 +21913,46 @@ 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}. Plagguble 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 +``ClientTransportPlugin ...'' or to +``ServerTransportPlugin ...'' line in the default +configuration file, see the @code{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{path-to-binary} +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 +@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 8e64e529ab..cb1749ffe6 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -22,6 +22,7 @@ ;;; Copyright © 2023 Declan Tsien ;;; Copyright © 2023 Bruno Victal ;;; Copyright © 2023 muradm +;;; Copyright © 2024 Nigko Yerden ;;; ;;; This file is part of GNU Guix. ;;; @@ -159,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-transport-plugin-role + tor-transport-plugin-protocol + tor-transport-plugin-path tor-hidden-service ; deprecated tor-service-type @@ -955,7 +962,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. @@ -985,10 +994,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-transport-plugin-role + (default 'client) + (sanitize (lambda (value) + (if (memq value '(client server)) + value + (configuration-field-error #f 'role value))))) + (protocol tor-transport-plugin-protocol + (default "obfs4")) + (path-to-binary tor-transport-plugin-path)) + (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)) @@ -1027,6 +1050,20 @@ (define (tor-configuration->torrc config) (cons name mapping))) hidden-services)) + (for-each (match-lambda + ((role-string protocol path) + (format port "\ +~aTransportPlugin ~a exec ~a~%" + role-string protocol path))) + '#$(map (match-lambda + (($ role protocol path) + (list (if (eq? role 'client) + "Client" + "Server") + protocol + path))) + transport-plugins)) + (display "\ ### End of automatically generated lines.\n\n" port) @@ -1039,23 +1076,30 @@ (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 "/dev/log") ;for syslog - (target source)) - (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 "/dev/log") ;for syslog + (target source)) + (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-transport-plugin-path plugin)) + (target source))) + transport-plugins)) #:namespaces (delq 'net %namespaces)))) (list (shepherd-service (provision '(tor))