From patchwork Thu Jan 3 20:02:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Dold X-Patchwork-Id: 651 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 992CF16A0A; Thu, 3 Jan 2019 20:03:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mira.cbaines.net (Postfix) with ESMTP id BAED316A07 for ; Thu, 3 Jan 2019 20:03:28 +0000 (GMT) Received: from localhost ([127.0.0.1]:57580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf9DD-0001xq-W0 for patchwork@mira.cbaines.net; Thu, 03 Jan 2019 15:03:28 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf9D6-0001xe-8Q for guix-patches@gnu.org; Thu, 03 Jan 2019 15:03:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf9Cv-0006C1-DS for guix-patches@gnu.org; Thu, 03 Jan 2019 15:03:15 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:52330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf9Cp-00068J-Q0 for guix-patches@gnu.org; Thu, 03 Jan 2019 15:03:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gf9Cp-0007DK-Lr for guix-patches@gnu.org; Thu, 03 Jan 2019 15:03:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#33966] fcgiwrap: additional options for logging and unix domain sockets Resent-From: Florian Dold Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 03 Jan 2019 20:03:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 33966 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 33966@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.154654577127700 (code B ref -1); Thu, 03 Jan 2019 20:03:03 +0000 Received: (at submit) by debbugs.gnu.org; 3 Jan 2019 20:02:51 +0000 Received: from localhost ([127.0.0.1]:45987 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gf9Cd-0007Ci-9c for submit@debbugs.gnu.org; Thu, 03 Jan 2019 15:02:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gf9Cb-0007CZ-4k for submit@debbugs.gnu.org; Thu, 03 Jan 2019 15:02:49 -0500 Received: from lists.gnu.org ([208.118.235.17]:51372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gf9Ca-0005wr-V9 for submit@debbugs.gnu.org; Thu, 03 Jan 2019 15:02:49 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf9CZ-0001uD-E3 for guix-patches@gnu.org; Thu, 03 Jan 2019 15:02:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf9CV-0005tg-9v for guix-patches@gnu.org; Thu, 03 Jan 2019 15:02:47 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:37457) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf9CU-0005sm-V0 for guix-patches@gnu.org; Thu, 03 Jan 2019 15:02:43 -0500 Received: by mail-wm1-x32f.google.com with SMTP id g67so31332383wmd.2 for ; Thu, 03 Jan 2019 12:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:openpgp:autocrypt:subject:message-id:date:user-agent :mime-version:content-language; bh=dA2Nabope81by/pztAh9HwURADXuXjjsX/kJFzZ7lLY=; b=juR8jT/KKPK2hL//oCjMSKm+pCflOcAQYsXRFjVJl9PHq1VbO0296CfCn6ZS7gmAjN laktG9iNK8hJhoIWafy2Fjl4zEW0YZt2R833+TSFuVIczXF9vo8yWBLSs2uqqAmsQNeJ 3t0Y5tJnZsXjBiIjSITbtmS2eBhoJpsdBroBp1maSIVTuSLZhVHqHIxMVC8kWzZ4RxuE VFHSTbS40xPX4VOBBmsOoezBgj9ZbH1Cj982vz4KaQinA17tHOcsrLql0PBtzC6uGZ59 W7I9XHxcLFsX8LYWYe6usDNYTRkgW+QVAzE6iOtTrunA2EAXpNrzKQkvleD7QeMbUKMc tcHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:openpgp:autocrypt:subject:message-id :date:user-agent:mime-version:content-language; bh=dA2Nabope81by/pztAh9HwURADXuXjjsX/kJFzZ7lLY=; b=Ktb7kJbQ12FJ0nJp6CAjo+HUaHOPOXcB4ktvTbv1w68ngO7KVduoiP5QOGrbOX4v7C hgui7tr9uXy0ZqNzUGpK9oAR5x0y8ZstqIZeczpUsNzontZEWH8Y6M7Rv9XUhgHavjOT JOOohjVqfaGHUju7zxUTlGwQXJztnet77evrfjGvevYAj72Rt0rRndq3jTTYdxdKojci UrsUzffmWiUcdYefHIwRh7zoZGfx/rl1wEvHmDmO7HFvMTEIOt1JXvZWCe3mrGDQNgOh HKc4dO8cXBWVyi/SU67U6EBCRobZiBVmmJFPVbfJ6OeeurmpjrZsm4gsHe3cFn1hlb+d OxkQ== X-Gm-Message-State: AA+aEWbFz86lYbHs3BOPmon7R49aVetD01XYvaSP6nEOBLrtbRfjRLDg i61UC0QdDjgr9eySsHICnioanTMJ X-Google-Smtp-Source: AFSGD/WsZnCbJXyZzEmS0Ia3r5c8oAq+94rcx8aGT1J3Qe5lMCPoCuwWnyYVcUsohiGGL0bua22bBw== X-Received: by 2002:a1c:83c8:: with SMTP id f191mr39193639wmd.134.1546545761369; Thu, 03 Jan 2019 12:02:41 -0800 (PST) Received: from [192.168.178.64] (p508876EC.dip0.t-ipconnect.de. [80.136.118.236]) by smtp.gmail.com with ESMTPSA id l6sm42366499wrv.70.2019.01.03.12.02.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 12:02:40 -0800 (PST) From: Florian Dold Openpgp: preference=signencrypt Autocrypt: addr=florian.dold@gmail.com; keydata= mQENBFr0DFABCADIf6L8MOVfrvjN8vTPngMjxGk4gpaRAYydTYMt8I7A746E8fI4vIp66b7x ZmT+RwnR+nydTLdAMEpwsqxOUtBLBG+63v/pOFEqHaWWjoWB9tC2GKa23o5accKdeVwZAUSC d8PMCTY0An25yjspAPFeSuS8OVhNcJgqwMRLrGAeb6nOiHzNgbcH3x+z8pvZ6uEmfxOmnPxz eJ2YkRB8EZtdz2kVSAs8hnDXXhA2kPYu299N42iOnsAI/ZQLw4L4CciFD9g7yHyjSGf2ugLd v2MY/e7bg2MbrpOjl9F6tkWcMG47Q15Zg5h5i1TUWb5u6BYwTWegxjoF8aghsD4YmlDdABEB AAG0JUZsb3JpYW4gRG9sZCA8Zmxvcmlhbi5kb2xkQGdtYWlsLmNvbT6JAVQEEwEIAD4WIQTS icR018Yz2C9+q1hf73L/w6CZwgUCWvQMUQIbAwUJAeEzgAULCQgHAgYVCgkICwIEFgIDAQIe AQIXgAAK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rrMgQFnMrfr0JQ6CDSklup4LRPjpjvdqX900QkVWErvMxDnC66pyur0o/ 3rSx Message-ID: <624ba072-d5fe-b159-46af-61e79caf22f1@gmail.com> Date: Thu, 3 Jan 2019 21:02:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 Content-Language: en-US-large X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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" X-getmail-retrieved-from-mailbox: Patches Hi Guix, this patch adds additional options to the fcgiwrap service. In particular it allows 1. writing the output of the fcgi process to a file (with the 'log-file' option) 2. arranging for a directory to be created so that the fcgiwrap process can create its listening socket without running into permission problems (with the 'ensure-socket-dir?' option) 3. adjusting the permissions on the listening unix domain socket, typically so that users in the fcgiwrap group have read and write access to that socket (with the 'adjusted-socket-permissions' option) Additionally, a potentially left-over fcgiwrap socket is cleaned up before starting the service, which would otherwise lead to the process refusing to run. The documentation is also changed to address a potential security issue, now recommending against running fcgiwrap as root. The configuration defaults are not ideal (a tcp socket with unrestricted access from any local user), but impossible to change without breaking existing system definitions. - Florian From 3ac9c6fa536faff23291b21d4e649b85386fedfc Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 3 Jan 2019 14:22:49 +0100 Subject: [PATCH] services: fcgiwrap: Implement additional options The fcgiwrap service now supports logging and can be run on a unix domain socket as unprivileged user. * doc/guix.texi (Web Services): Document new options and replace dangerous advice about running fcgiwrap as root. * gnu/services/web.scm: Add the options 'log-file', 'adjusted-socket-permissions' and 'ensure-socket-dir?'. --- doc/guix.texi | 26 +++++++--- gnu/services/web.scm | 119 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 120 insertions(+), 25 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index fcb5b8c08..608dd26ca 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -17756,12 +17756,26 @@ The user and group names, as strings, under which to run the the user asks for the specific user or group names @code{fcgiwrap} that the corresponding user and/or group is present on the system. -It is possible to configure a FastCGI-backed web service to pass HTTP -authentication information from the front-end to the back-end, and to -allow @code{fcgiwrap} to run the back-end process as a corresponding -local user. To enable this capability on the back-end., run -@code{fcgiwrap} as the @code{root} user and group. Note that this -capability also has to be configured on the front-end as well. +Note that whoever can write to the fcgiwrap socket is effectively able to +execute programs as the user/group running the fcgiwrap process. It is thus +strongly discouraged to run fcgiwrap as the @code{root} user or group. + +@item @code{log-file} (default: @code{#f}) +File where @command{fcgiwrap}'s output is written, or @code{#f} to not +store the output. + +@item @code{adjusted-socket-permissions} (default: @code{#f}) +Only applies to @code{unix} sockets. Adjusts the permissions of the socket +after it has been created. If set to an integer, it is interpreted as a +numeric file mode. If set to @code{#t}, it is interpreted as mode @code{#o660} +(read and write permissions for user and group). If set to the default +@code{#f}, no adjustments are made. + +@item @code{ensure-socket-dir?} (default: @code{#f}) +Only applies to @code{unix} sockets. If set to @code{#t} and the directory +component of the socket path in @code{socket} does not exist yet, the +directory is created with ownership set to the user and group running the +fcgiwrap process. @end table @end deftp diff --git a/gnu/services/web.scm b/gnu/services/web.scm index d71fed20e..a3d435489 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -39,6 +39,7 @@ #:use-module (guix records) #:use-module (guix modules) #:use-module (guix gexp) + #:use-module (guix i18n) #:use-module ((guix store) #:select (text-file)) #:use-module ((guix utils) #:select (version-major)) #:use-module ((guix packages) #:select (package-version)) @@ -696,14 +697,21 @@ of index files." (define-record-type* fcgiwrap-configuration make-fcgiwrap-configuration fcgiwrap-configuration? - (package fcgiwrap-configuration-package ; - (default fcgiwrap)) - (socket fcgiwrap-configuration-socket - (default "tcp:127.0.0.1:9000")) - (user fcgiwrap-configuration-user - (default "fcgiwrap")) - (group fcgiwrap-configuration-group - (default "fcgiwrap"))) + (package fcgiwrap-configuration-package ; + (default fcgiwrap)) + (socket fcgiwrap-configuration-socket + (default "tcp:127.0.0.1:9000")) + (user fcgiwrap-configuration-user + (default "fcgiwrap")) + (group fcgiwrap-configuration-group + (default "fcgiwrap")) + (log-file fcgiwrap-log-file + (default #f)) + ;; boolean or octal mode integer + (adjusted-socket-permissions fcgiwrap-adjusted-socket-permissions? + (default #f)) + (ensure-socket-dir? fcgiwrap-ensure-socket-dir? + (default #f))) (define fcgiwrap-accounts (match-lambda @@ -723,25 +731,98 @@ of index files." (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))))))) +(define (parse-fcgiwrap-socket s) + "Parse a fcgiwrap socket specification string into '(type args ...)" + (cond + ((string-prefix? "unix:" s) + (list 'unix (substring s 5))) + ((string-prefix? "tcp:" s) + (match (string-match "^tcp:([.0-9]+):([0-9]+)$" s) + ((? regexp-match? m) + (list + 'tcp + (match:substring m 1) + (string->number (match:substring m 2)))) + (_ (error "invalid tcp socket address")))) + ((string-prefix? "tcp6:" s) + (match (string-match "^tcp6:\\[(.*)\\]:([0-9]+)$" s) + ((? regexp-match? m) + (list + 'tcp6 + (match:substring m 1) + (string->number (match:substring m 2)))) + (_ (error "invalid tcp6 socket address")))) + (else (error "unrecognized socket protocol")))) + (define fcgiwrap-shepherd-service (match-lambda - (($ package socket user group) - (list (shepherd-service - (provision '(fcgiwrap)) - (documentation "Run the fcgiwrap daemon.") - (requirement '(networking)) - (start #~(make-forkexec-constructor - '(#$(file-append package "/sbin/fcgiwrap") - "-s" #$socket) - #:user #$user #:group #$group)) - (stop #~(make-kill-destructor))))))) + (($ package socket user group log-file perm ensure-dir?) + (define parsed-socket (parse-fcgiwrap-socket socket)) + (list + (shepherd-service + (provision '(fcgiwrap)) + (documentation "Run the fcgiwrap daemon.") + (requirement '(networking)) + (modules `((shepherd support) (ice-9 match) ,@%default-modules)) + (start + #~(lambda args + (define (clean-up file) + (catch 'system-error + (lambda () + (delete-file file)) + (lambda args + (unless (= ENOENT (system-error-errno args)) + (apply throw args))))) + (define* (wait-for-file file #:key (max-delay 5)) + (define start (current-time)) + (let loop () + (cond + ((file-exists? file) #t) + ((< (current-time) (+ start max-delay)) + (sleep 1) + (loop)) + (else #f)))) + (define (adjust-permissions file mode) + (match mode + (#t (chmod file #o660)) + (n (chmod file n)) + (#f 0))) + (define (ensure-socket-dir dir user group) + (unless (file-exists? dir) + (mkdir dir) ; FIXME: use mkdir-p instead? + (let ((uid (passwd:uid (getpwnam user))) + (gid (group:gid (getgrnam group)))) + (chown dir uid gid)))) + (define start-fcgiwrap + (make-forkexec-constructor + '(#$(file-append package "/sbin/fcgiwrap") + "-s" #$socket) + #:user #$user + #:group #$group + #:log-file #$log-file)) + (match '#$parsed-socket + (('unix path) + ;; Clean up socket, otherwise fcgiwrap might not start properly. + (clean-up path) + (when #$ensure-dir? + (ensure-socket-dir (dirname path) #$user #$group)) + (let ((pid (start-fcgiwrap)) + (socket-exists? (wait-for-file path))) + (if socket-exists? + (adjust-permissions path #$perm) + (local-output + #$(G_ "fcgiwrap: warning: waiting for socket ~s failed") + path)) + pid)) + (_ (start-fcgiwrap))))) + (stop #~(make-kill-destructor))))))) (define fcgiwrap-service-type (service-type (name 'fcgiwrap) (extensions (list (service-extension shepherd-root-service-type fcgiwrap-shepherd-service) - (service-extension account-service-type + (service-extension account-service-type fcgiwrap-accounts))) (default-value (fcgiwrap-configuration)))) -- 2.20.1