From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 8GJIBRkOiGEiBQAAgWs5BA (envelope-from ) for ; Sun, 07 Nov 2021 18:34:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 6Pf7ABkOiGFvVgAA1q6Kng (envelope-from ) for ; Sun, 07 Nov 2021 17:34:17 +0000 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 9CA87F89E for ; Sun, 7 Nov 2021 18:34:16 +0100 (CET) Received: from localhost ([::1]:60788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjm3b-0000iS-Kd for larch@yhetil.org; Sun, 07 Nov 2021 12:34:15 -0500 Received: from [2001:470:142:3::10] (port=52706 helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjm3P-0000i4-9w for bug-guix@gnu.org; Sun, 07 Nov 2021 12:34:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:43037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjm3O-0005YZ-Ff for bug-guix@gnu.org; Sun, 07 Nov 2021 12:34:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mjm3O-0006Iu-DI for bug-guix@gnu.org; Sun, 07 Nov 2021 12:34:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#51487: The openssh service does not allow multiple authorized key files per user Resent-From: Vivien Kraus Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sun, 07 Nov 2021 17:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51487 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 51487@debbugs.gnu.org Received: via spool by 51487-submit@debbugs.gnu.org id=B51487.163630642424205 (code B ref 51487); Sun, 07 Nov 2021 17:34:02 +0000 Received: (at 51487) by debbugs.gnu.org; 7 Nov 2021 17:33:44 +0000 Received: from localhost ([127.0.0.1]:54583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjm36-0006IL-8D for submit@debbugs.gnu.org; Sun, 07 Nov 2021 12:33:44 -0500 Received: from planete-kraus.eu ([89.234.140.182]:36470) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjm33-0006IA-98 for 51487@debbugs.gnu.org; Sun, 07 Nov 2021 12:33:42 -0500 Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id cfc80316; Sun, 7 Nov 2021 17:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=dkim; bh=Yi3Fw11lW03wsPX0o493oceTg F8=; b=AYL293tKISIaq3skSCuxFEr0+nK/VFrL26oFVHK0h1jbNngymqmUANofY /CbHENOeVL57sx6vUKMeh21bxkOPY1JWNHu7VrtvSfsZI/wK3dNkvkMiYosChZ2m e7AQRo8WV6nO/65ZC3JlO0/YvQc+Tazn6+cp1BgoqGb6iO2ibU= Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id 18aa5d54 (TLSv1.3:AEAD-CHACHA20-POLY1305-SHA256:256:NO); Sun, 7 Nov 2021 17:33:32 +0000 (UTC) References: <87fssjvmbp.fsf@planete-kraus.eu> <5e2cb25499ce79f6afc6b8fc775b6ff8e5817670.camel@planete-kraus.eu> <87fss8knw3.fsf_-_@gnu.org> User-agent: mu4e 1.6.9; emacs 27.2 Date: Sun, 07 Nov 2021 18:29:30 +0100 In-reply-to: <87fss8knw3.fsf_-_@gnu.org> Message-ID: <87lf1zc1lg.fsf@planete-kraus.eu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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" Reply-to: Vivien Kraus From: Vivien Kraus via Bug reports for GNU Guix X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636306456; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: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=XibtWyNMRPfv+YNvR4h03UIgutP51egqY2s9/M5z9Oo=; b=eoeFJVcauN3+MzCA4C2Ifs5If9/nwz71/AoKz3z+AjEHx+XmbvfiQ8RPx0+Bmv2KDKyl2c O4XDxfeMiP1NwruTsZZioch0MAxOdZclw4p1wzsKUqJg5dehlQapnfqF16G5hVCMJGvMg6 Rm90jUqxCe610xG4OHuXfnEalu5pz+ZfO8MlSjJXozjHdY+r4rMdCQTdLJI9780C1GiCix DOnbtynqygOUGHiUWf1aO9MzxtodvzU3bOQ0DEDBcMA1efWWL2KX3KE63TKXEFPmOR0zE0 3c8JVHfgs/H36s/p5ZjT99LRgmETvZlmnlH3aEVXDH7c29EvYQUe20ync4IujQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636306456; a=rsa-sha256; cv=none; b=n7noUaO17gCisn4yDAqw/dWT8/bXsSs4RGJpBtRy5pgvRy4KGlHj5/wXnk2X2MyssJXrZg QEgRI3sMqDMJPH7t5zKsLITTRZvfwWlpVEJcBedfHWUd2W5pIHW7raKd03GXawC65eqMDo RWUQa0XLvKz4VQLxsQQfEw3FPEY3SwXT+t3VpeVdjAU315GfngMSl8wyVJfoHMDgVZZiYA IDOMlSI9xjTtUVevvSMeKQuQeRziW1Nws2ATLCFGv3TtSduvXzb8nm8XWNi2tZA5inwcRe 8V2BgFaglhcEFFTN4D48ejY4uOWioU0rpxopoxi8fL6zl2IwXJeuNxnzuJJYUA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=dkim header.b=AYL293tK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Spam-Score: -2.92 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=dkim header.b=AYL293tK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 9CA87F89E X-Spam-Score: -2.92 X-Migadu-Scanner: scn0.migadu.com X-TUID: P90u2iuW5KXT --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Ludovic Court=C3=A8s writes: > Could you write it in functional style using a vhash (info "(guile) > VHashes")? You=E2=80=99ll probably need two list traversals: one to buil= d the > user/key mapping, and one to compute the list of users. I thought that as the vhash data structure inherited the drawbacks of vlist, it would not be worth using in place of a hash table, but you=E2=80= =99re saying that it=E2=80=99s still a better (more functional) data structure, n= oted. Here is the new patch (and I also forgot that appending short lists to long lists was not great, so I do all the appending at the end of the function now). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-gnu-openssh-service-Collect-all-keys-for-all-users.patch >From a2c4d7cefbc71fd3d35b0b7cc2f61118bd3a29b2 Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Fri, 29 Oct 2021 18:25:24 +0200 Subject: [PATCH] gnu: openssh-service: Collect all keys for all users. * gnu/services/ssh.scm (extend-openssh-authorized-keys): ensure that no key is forgotten. --- gnu/services/ssh.scm | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gnu/services/ssh.scm b/gnu/services/ssh.scm index a018052eeb..6ddaf55eeb 100644 --- a/gnu/services/ssh.scm +++ b/gnu/services/ssh.scm @@ -39,6 +39,7 @@ (define-module (gnu services ssh) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) + #:use-module (ice-9 vlist) #:export (lsh-configuration lsh-configuration? lsh-service @@ -532,10 +533,30 @@ (define (openssh-pam-services config) (define (extend-openssh-authorized-keys config keys) "Extend CONFIG with the extra authorized keys listed in KEYS." - (openssh-configuration - (inherit config) - (authorized-keys - (append (openssh-authorized-keys config) keys)))) + (let generate-keys + ((user-keys + (append (openssh-authorized-keys config) keys)) + ;; The by-user vhash indexes a list of list of keys for each user, the + ;; list of list is not concatenated eagerly to avoid quadratic + ;; complexity. + (by-user (alist->vhash '()))) + (match user-keys + (() + (openssh-configuration + (inherit config) + (authorized-keys + (vhash-fold + (lambda (user keys other-users) + `((,user ,@(apply append (reverse keys))) ,@other-users)) + '() by-user)))) + (((user keys ...) other-user-keys ...) + (let ((existing + (match (vhash-assoc user by-user) + ((_ . keys) keys) + (#f '())))) + (generate-keys + other-user-keys + (vhash-cons user `(,keys ,@existing) by-user))))))) (define openssh-service-type (service-type (name 'openssh) -- 2.33.1 --=-=-= Content-Type: text/plain Vivien --=-=-=--