From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id AB6PEa77t2XqWgEAe85BDQ:P1 (envelope-from ) for ; Mon, 29 Jan 2024 20:25:34 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id AB6PEa77t2XqWgEAe85BDQ (envelope-from ) for ; Mon, 29 Jan 2024 20:25:34 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lassieur.org header.s=fm2 header.b=NtpiGQtG; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm3 header.b="F euRiRq"; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706556334; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=gjtJ98BMrhppJwBQj+oihwjHDqSbPQbYd72HrWC+PnI=; b=s+MyXq1y9+U5uXjugZWx2SAhZx758EPPmKPsKZcSorlVvUwanivU3B8USpechSUYhXoCOC CdALwfY2Sxgb0McUcliE+B2IVJ1SEtKS6mSdhe4Z8IGPZqOSVcXS9pt0b4n0Us4XtPF8Rn N+zuP7CcKUukc5405+RSvm2ZVzWIATwJWjQfSyWp7lSQTS6ZXDJJ8UwzyP5SE2cbyTGdun 1IMLFsaVeCr8r+rkl0s4ps6r19iF/LuMDwYo/pU3kcmgEWj9zDkoEU5wKhn1nzMS3XAsLq XeTA5GLxk6OEBjal22iqSORK1MC4uF/cPd4YZG/v5f5UqmyKIia+kz8WDx+dyw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lassieur.org header.s=fm2 header.b=NtpiGQtG; dkim=fail ("headers rsa verify failed") header.d=messagingengine.com header.s=fm3 header.b="F euRiRq"; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706556334; a=rsa-sha256; cv=none; b=rL5XjE7+ZgiWmtcyZu86LcXG8tM5ni0NX4exEAdATc9Pz/pANd6mbi4p6//qP83uOXzufP l/XxD49gcJ8Hd/aHYGnBS6e/BD8mzbP8F5STN/lJxQXq93u/Ebhbvm8Hxr8X/14oIhSvXh lGPTevtK68UIU1MkX+KiZ+Eva1KuN8Xp6x/RnMi8eZ00cnqaEcnMcmi3ecBuTMsdJh11tU ko5KsTJ5VyGyMGJwwMGuNK3PqISqH/7qh10Yc0h5VyNSLSNANwYHDGRGza6VLBShWrLSrR vDLE2JYKnm6VeZDvXQxUe7j2BgNPpUtejORnA4ssinvg4DndARSmdff3NIJ9sQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 245C757BE3 for ; Mon, 29 Jan 2024 20:25:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUXFp-0002fP-Ay; Mon, 29 Jan 2024 14:25:16 -0500 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 1rUXFW-0002cv-IQ for bug-guix@gnu.org; Mon, 29 Jan 2024 14:24:55 -0500 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 1rUXFW-0002pZ-2w for bug-guix@gnu.org; Mon, 29 Jan 2024 14:24:54 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rUXFe-0002eY-6n for bug-guix@gnu.org; Mon, 29 Jan 2024 14:25:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#46961: Nginx and certbot cervices don't play well togther Resent-From: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 29 Jan 2024 19:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46961 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Carlo Zancanaro Cc: 46961@debbugs.gnu.org Received: via spool by 46961-submit@debbugs.gnu.org id=B46961.170655626010150 (code B ref 46961); Mon, 29 Jan 2024 19:25:02 +0000 Received: (at 46961) by debbugs.gnu.org; 29 Jan 2024 19:24:20 +0000 Received: from localhost ([127.0.0.1]:33498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rUXEy-0002dd-0V for submit@debbugs.gnu.org; Mon, 29 Jan 2024 14:24:20 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:54961) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rUXEw-0002dP-M1 for 46961@debbugs.gnu.org; Mon, 29 Jan 2024 14:24:19 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 774335C0108; Mon, 29 Jan 2024 14:24:04 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 29 Jan 2024 14:24:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lassieur.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1706556244; x=1706642644; bh=gjtJ98BMrhppJwBQj+oihwjHDqSbPQbYd72HrWC+PnI=; b= NtpiGQtGWDYmCPx4regBfXK9UsoMBvEawkKtsm3JTcPj4EpZLixSW4LUyT24KWOb 5Qrs7bE4SXSO69zgcZnxlVKp0ZrOPCQAJARsOsgg4iigj/pJo/Y2LfttsCQYkLBm Lw1NG9+VJeCz0r73a8mE9fPrfR3rW+/fbqidJBef/fUf4jqn5rRo+VhmVjhNj3Wq 3mA0klL3stYungBWp+aHi2WG0syol/wowGEKi3+Dn/HTxBe5UEckFxXQUTMxEVu4 ZccTFS6JaY3NR664bZ2/E/xLJRf4jkj/C8PzVBkbruBq6GJV6ufaasTPV6LnXAq5 1GOTm59pxf6BhnianziaBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1706556244; x= 1706642644; bh=gjtJ98BMrhppJwBQj+oihwjHDqSbPQbYd72HrWC+PnI=; b=F euRiRqypwzH3gTfq8g/XXsOJEO2BYlhyu39pZNjBMwCF5GoGMGaO7NKZ+ab3hN0N Skuh0RxIIdxly7kbRFMQDKgeqn/xn8aXaX6H6w+HB6i3gmnttmptOP7UVWGRGDkx WwLzoBWcogfLG80+dJvlws6VEqOs9abysGcaMF8fuHLnhGFaMVgl86V2TfdTBlw+ HPP4/8Lh9BPBoZ5lPBVjCkBNietFUHsB430IlgxniM6u/1aRXm8XM1leEbDqSYD2 FMRoNNknmjyPvNdzRwnj3YMTNxuzB5PWRUZsIxZozVQF1qMpvWKCFH4iG1uRlLjT WEFrjxtvmGiEmOyX0H2tQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtgedguddufecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufgjfhffkfgfgggtgfesthhqredttderjeenucfhrhhomhepvehl rohmvghnthcunfgrshhsihgvuhhruceotghlvghmvghntheslhgrshhsihgvuhhrrdhorh hgqeenucggtffrrghtthgvrhhnpeeltedtffekiedtfedvhfekhfegteduledvtdefkeel gfejgeethedvveelfefgueenucffohhmrghinhepvgigrghmphhlvgdrtghomhdpphgvmh drnhgvfienucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pegtlhgvmhgvnhhtsehlrghsshhivghurhdrohhrgh X-ME-Proxy: Feedback-ID: i4c21472a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Jan 2024 14:24:02 -0500 (EST) From: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur In-Reply-To: <788b23efd206b4ef627de06236f868f97e3cbe05.1706098718.git.carlo@zancanaro.id.au> (Carlo Zancanaro's message of "Wed, 24 Jan 2024 23:18:38 +1100") References: <788b23efd206b4ef627de06236f868f97e3cbe05.1706098718.git.carlo@zancanaro.id.au> Date: Mon, 29 Jan 2024 20:23:58 +0100 Message-ID: <878r483pv5.fsf_-_@lassieur.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.76 X-Migadu-Scanner: mx13.migadu.com X-Spam-Score: -2.76 X-Migadu-Queue-Id: 245C757BE3 X-TUID: Dh0UEaaE7c+R Hi Carlo, On Wed, Jan 24 2024, Carlo Zancanaro wrote: > * gnu/services/certbot.scm (): Add > start-self-signed? field. > (generate-certificate-gexp): New procedure. > (certbot-activation): Generate self-signed certificates when > start-self-signed? is #t. > * doc/guix.texi (Certificate services): Document start-self-signed?. > --- > doc/guix.texi | 6 +++++ > gnu/services/certbot.scm | 56 +++++++++++++++++++++++++++++++++++++--- > 2 files changed, 59 insertions(+), 3 deletions(-) This is great, thank you! I tested it, it worked. Could you please just make sure lines fit within 80 columns? And there is a warning during compilation, pasted below. Would it make sense now to run =E2=80=98update-certificates=E2=80=99 at end= of the activation stuff? And would it make sense to reload nginx after =E2=80=98update-certificates= =E2=80=99 is run? Cl=C3=A9ment > diff --git a/doc/guix.texi b/doc/guix.texi > index 2d43ab9a65..15b256d0a3 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -32664,6 +32664,12 @@ Certificate Services > contain a space-delimited list of renewed certificate domains (for > example, @samp{"example.com www.example.com"}. >=20=20 > +@item @code{start-self-signed?} (default: @code{#t}) > +Whether to generate an initial self-signed certificate during system > +activation. This option is particularly useful to allow @code{nginx} to > +start before @code{certbot} has run, because @code{certbot} relies on > +@code{nginx} running to perform HTTP challenges. > + > @end table > @end deftp >=20=20 > diff --git a/gnu/services/certbot.scm b/gnu/services/certbot.scm > index 58e709f8a4..bb321a1b50 100644 > --- a/gnu/services/certbot.scm > +++ b/gnu/services/certbot.scm > @@ -64,7 +64,9 @@ (define-record-type* > (cleanup-hook certificate-cleanup-hook > (default #f)) > (deploy-hook certificate-configuration-deploy-hook > - (default #f))) > + (default #f)) > + (start-self-signed? certificate-configuration-start-self-signed? > + (default #t))) >=20=20 > (define-record-type* > certbot-configuration make-certbot-configuration > @@ -91,7 +93,10 @@ (define-record-type* > (define (certbot-deploy-hook name deploy-hook-script) > "Returns a gexp which creates symlinks for privkey.pem and fullchain.p= em > from /etc/certs/NAME to /etc/letsenctypt/live/NAME. If DEPLOY-HOOK-SCRI= PT is > -not #f then it is run after the symlinks have been created." > +not #f then it is run after the symlinks have been created. This wrappi= ng is > +necessary for certificates with start-self-signed? set to #t, as it will > +overwrite the initial self-signed certificates upon the first successful > +deploy." > (program-file > (string-append name "-deploy-hook") > (with-imported-modules '((guix build utils)) > @@ -108,7 +113,8 @@ (define (certbot-deploy-hook name deploy-hook-script) > "/etc/letsencrypt/live/" name "/fullchain.pem") > #$(string-append "/etc/certs/" name "/fullchain.pem.ne= w")) >=20=20 > - ;; Rename over the top of the old ones, if there are any. > + ;; Rename over the top of the old ones, just in case they were = the > + ;; original self-signed certificates. > (rename-file #$(string-append "/etc/certs/" name "/privkey.pem.= new") > #$(string-append "/etc/certs/" name "/privkey.pem"= )) > (rename-file #$(string-append "/etc/certs/" name "/fullchain.pe= m.new") > @@ -182,6 +188,44 @@ (define (certbot-renewal-jobs config) > #~(job '(next-minute-from (next-hour '(0 12)) (list (random 60))) > #$(certbot-command config)))) >=20=20 > +(define (generate-certificate-gexp certbot-cert-directory rsa-key-size) > + (match-lambda > + (($ name (primary-domain other-domains .= ..) challenge > + csr authentication-hook > + cleanup-hook deploy-hook) > + (let (;; Arbitrary default subject, with just the > + ;; right domain filled in. These values don't > + ;; have any real significance. > + (subject (string-append "/C=3DUS/ST=3DOregon/L=3DPortland/O= =3DCompany Name/OU=3DOrg/CN=3D" > + primary-domain)) > + (alt-names (if (null? other-domains) > + #f > + (format #f "subjectAltName=3D~{DNS:~a~^,~}" ot= her-domains))) gnu/services/certbot.scm:203:26: warning: "subjectAltName=3D~{DNS:~a~^,~}":= unsupported format option ~{, use (ice-9 format) instead > + (directory (string-append "/etc/certs/" (or name primary-doma= in)))) > + #~(begin > + (use-modules (ice-9 format)) > + (when (not (file-exists? #$directory)) > + ;; Due to the way certbot runs, we need to > + ;; create the self-signed certificates in the > + ;; archive folder and symlink them into the live > + ;; folder. This mimics what certbot does well > + ;; enough to make acquiring new certificates > + ;; work. In another mail you say it doesn't work as well as you thought it did? What doesn't work? > + (mkdir-p #$directory) > + (chmod #$directory #o755) > + (invoke #$(file-append openssl "/bin/openssl") > + "req" "-x509" > + "-newkey" #$(string-append "rsa:" (or rsa-key-size = "4096")) > + "-keyout" #$(string-append directory "/privkey.pem") > + "-out" #$(string-append directory "/fullchain.pem") > + "-sha256" > + "-days" "1" ; Only one day, because we expect certb= ot to run > + "-nodes" > + "-subj" #$subject > + #$@(if alt-names > + (list "-addext" alt-names) > + (list))))))))) > + > (define (certbot-activation config) > (let* ((certbot-directory "/var/lib/certbot") > (certbot-cert-directory "/etc/letsencrypt/live") > @@ -196,6 +240,12 @@ (define (certbot-activation config) > (mkdir-p #$webroot) > (mkdir-p #$certbot-directory) > (mkdir-p #$certbot-cert-directory) > + > + #$@(map (generate-certificate-gexp certbot-cert-directory > + (and rsa-key-size (numbe= r->string rsa-key-size))) > + (filter certificate-configuration-start-self-signed? > + certificates)) > + > (copy-file #$(certbot-command config) #$script) > (display #$message)))))))