From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GHFyCRDtxGBqjAAAgWs5BA (envelope-from ) for ; Sat, 12 Jun 2021 19:21:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 4MjyBBDtxGDAFwAAB5/wlQ (envelope-from ) for ; Sat, 12 Jun 2021 17:21:20 +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 6147D1F2A4 for ; Sat, 12 Jun 2021 19:21:19 +0200 (CEST) Received: from localhost ([::1]:53966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ls7Jt-0002Fe-UU for larch@yhetil.org; Sat, 12 Jun 2021 13:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls7Jf-0002FF-Vj for guix-patches@gnu.org; Sat, 12 Jun 2021 13:21:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ls7Je-0003q6-Ms for guix-patches@gnu.org; Sat, 12 Jun 2021 13:21:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ls7Je-0002JH-FU for guix-patches@gnu.org; Sat, 12 Jun 2021 13:21:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48975] New firewall service Resent-From: Solene Rapenne Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 12 Jun 2021 17:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48975 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 48975@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16235184178809 (code B ref -1); Sat, 12 Jun 2021 17:21:02 +0000 Received: (at submit) by debbugs.gnu.org; 12 Jun 2021 17:20:17 +0000 Received: from localhost ([127.0.0.1]:41982 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ls7Iu-0002I1-KB for submit@debbugs.gnu.org; Sat, 12 Jun 2021 13:20:16 -0400 Received: from lists.gnu.org ([209.51.188.17]:41456) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ls7It-0002Hu-CU for submit@debbugs.gnu.org; Sat, 12 Jun 2021 13:20:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls7It-00027k-49 for guix-patches@gnu.org; Sat, 12 Jun 2021 13:20:15 -0400 Received: from perso.pw ([163.172.223.238]:29991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls7Ip-0003J8-To for guix-patches@gnu.org; Sat, 12 Jun 2021 13:20:14 -0400 Received: from perso.pw (localhost [127.0.0.1]) by perso.pw (OpenSMTPD) with ESMTP id ae87e3e5 for ; Sat, 12 Jun 2021 19:20:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=perso.pw; h=date:from:to :subject:message-id:mime-version:content-type :content-transfer-encoding; s=1337; bh=BMUX1hiSWHT9VDrXpZRKW5f7U ZA=; b=kdP2oNesEKBbrp8+c0IcDoWLwyThWKh1KPL2zzDviVDXqIj4uc5JSIGvr 7RWi1I9SqeqOSGYDoGJMZ4tO9gezj0AiJ1Ok5cHAOj9Gm7WNjUBVbTdQd5jC1C9x 7QsHsT6duXQGmYkL+XfR1hYkHoFI2V2pQd4sLjF68sOjECiTDE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=perso.pw; h=date:from:to :subject:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=1337; b=MkmlECIBEuqvTThbAvN zVSCE/0P1n98AiXY2ug3U7ArR7Y7fXdqzfypmQxJAljm5spZIAOjs+TZ8FOStnRI TGP1/zorODxubwYEd4Jus8GnKYXTrUpyw/Dtb6m0oi1zX33YX/wdxEh9WIOdofco USIUQDirAPUji2JOBDSoEAlA= Received: from localhost (176-154-164-34.abo.bbox.fr [176.154.164.34]) by perso.pw (OpenSMTPD) with ESMTPSA id 556dfa08 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Sat, 12 Jun 2021 19:20:00 +0200 (CEST) Date: Sat, 12 Jun 2021 19:19:59 +0200 Message-ID: <20210612191959.6394494e@perso.pw> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=163.172.223.238; envelope-from=solene@perso.pw; helo=perso.pw X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Solene Rapenne X-ACL-Warn: , Solene Rapenne via Guix-patches From: Solene Rapenne via Guix-patches via X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623518479; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=aClICmPOVqI4v350mHLsIB9EUZKUA/aUHuZICuY2nSk=; b=DgNbDjqpJLwqbQGhczaak+ivxx1qYtYIdyAy44oWRIWwl/JgrX7VcSLUPkqe7VZTNGXI5B msBOWcg3x9Ql4+/C2awOUuJ5VSkOrXY2uTXhII30FC0vxn4scQM7ANrhDV0uFByBbYJsDp Mw9nzwD7DycOJD8JZzOzdCvTHW9w8dxUQRZ83CvV/NlOdRHq2KBV+/dkUveBzV3waeDFR3 ABuxj1u1BSGCuJc1pLVB5L0axzbbpnS1c5t5RD001ajW/mH4ntCISvOuZ89fVKVMlR90aP p8vwlZY54rRP+qyOzNdTcMejuKN319r0yBBSjIrKTH3x2ZnUKQ53LhcdH317CA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623518479; a=rsa-sha256; cv=none; b=jBFq200Hg0vg34Q/Pn0RLaVUY6RE01snCb+5P8XSijU5ozLcvB/An24o1F6mDutXZP1oF2 WawzOQv4w7EVBpIZeJxXqGelijmXNJM6g+TlXHywXJWz5NqsqEeSJxVOjxPALNvxI4JdMN WkrbCd2AU6h5LPest1B+nbMiveMCV6Vy7YRoRCv3pv9oSDSfBrqnB+h+MPnq86QiQKNleZ noIcpGcMoRTFlhAPGLICx8KynhCVM7RFCPdHnjIMSlFbPJ9Q4FhT4JQ82T4RpvzNKlHgqk o9PydgsR8T93Lo/RhpJSenEjo0X4pealNcFY8E/WSgIh9ByZIny0QMjFl4UXmQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=perso.pw header.s=1337 header.b=kdP2oNes; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -2.93 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=perso.pw header.s=1337 header.b=kdP2oNes; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 6147D1F2A4 X-Spam-Score: -2.93 X-Migadu-Scanner: scn1.migadu.com X-TUID: Yazb2+vKeJGp Hello, I wrote a new firewall service, I already wrote an email to guix-devel about it and I've been suggested to submit it here. The idea is to propose an easy way to manage your firewall. On a personal computer or a server with no fancy network, you certainly want to block access from the outside to all the ports except a few ones. The configuration looks like this, currently it only supports TCP and UDP ports. Maybe NAT could be added later or other feature, I'm opened to suggestions. (service firewall-service-type (firewall-configuration (udp '(53)) (tcp '(22 70 1965)))) Here is the code, I took bits from iptables as a base and then used the Tor service way to generate the configuration file. diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 87b3d754a3..d311f95448 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -221,7 +221,11 @@ =20 keepalived-configuration keepalived-configuration? - keepalived-service-type)) + keepalived-service-type + + firewall-service-type + firewall-configuration + firewall-configuration?)) =20 ;;; Commentary: ;;; @@ -2190,4 +2194,76 @@ of the IPFS peer-to-peer storage network."))) "Run @uref{https://www.keepalived.org/, Keepalived} routing software."))) =20 +=0C +;;; +;;; Firewall +;;; + +(define-record-type* + firewall-configuration make-firewall-configuration + firewall-configuration? + (tcp firewall-configuration-tcp + (default '())) + (udp firewall-configuration-udp + (default '()))) + +(define (firewall-configuration->file tcp udp) + "Return the iptables rules from the ports list" + (computed-file + "firewall-generated-rules" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (ice-9 match)) + (call-with-output-file #$output + (lambda (out) + (display "\ +*filter +:INPUT DROP +:FORWARD DROP +:OUTPUT ACCEPT +-A INPUT -i lo -j ACCEPT +-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT\n" out) + + ;; tcp rules + (when (not (null? (list #$@tcp))) + (format out "\ +~{-A INPUT -p tcp --dport ~a -j ACCEPT~%~}" + (list #$@tcp))) + + ;; udp rules + (when (not (null? (list #$@udp))) + (format out "\ +~{-A INPUT -p udp --dport ~a -j ACCEPT~%~}" + (list #$@udp))) + + (display "COMMIT\n" out) + #t)))))) + +(define firewall-shepherd-service + (match-lambda + (($ tcp udp) + (let* ((iptables-restore (file-append iptables "/sbin/iptables-restor= e")) + (ip6tables-restore (file-append iptables "/sbin/ip6tables-rest= ore")) + (ruleset (firewall-configuration->file tcp udp))) + (shepherd-service + (documentation "Easy firewall management") + (provision '(firewall)) + (start #~(lambda _ + (invoke #$iptables-restore #$ruleset) + (invoke #$ip6tables-restore #$ruleset))) + (stop #~(lambda _ + (invoke #$iptables-restore #$ruleset) + (invoke #$ip6tables-restore #$ruleset)))))))) + +(define firewall-service-type + (service-type + (name 'firewall) + (description + "Run @command{iptables-restore}, setting up the specified rules.") + (extensions + (list (service-extension shepherd-root-service-type + (compose list firewall-shepherd-service)))))) + + ;;; networking.scm ends here