diff options
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/networking.scm | 113 |
1 files changed, 109 insertions, 4 deletions
diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index 25f61034c66..2865e6ff350 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net> | 5 | ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net> |
| 6 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> | 6 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> |
| 7 | ;;; Copyright © 2021, 2023-2024 Ludovic Courtès <ludo@gnu.org> | 7 | ;;; Copyright © 2021, 2023-2024 Ludovic Courtès <ludo@gnu.org> |
| 8 | ;;; Copyright © 2025 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 8 | ;;; | 9 | ;;; |
| 9 | ;;; This file is part of GNU Guix. | 10 | ;;; This file is part of GNU Guix. |
| 10 | ;;; | 11 | ;;; |
| @@ -29,6 +30,7 @@ | |||
| 29 | #:use-module (gnu services base) | 30 | #:use-module (gnu services base) |
| 30 | #:use-module (gnu services dns) | 31 | #:use-module (gnu services dns) |
| 31 | #:use-module (gnu services networking) | 32 | #:use-module (gnu services networking) |
| 33 | #:use-module (gnu services ssh) | ||
| 32 | #:use-module (guix gexp) | 34 | #:use-module (guix gexp) |
| 33 | #:use-module (guix store) | 35 | #:use-module (guix store) |
| 34 | #:use-module (guix monads) | 36 | #:use-module (guix monads) |
| @@ -50,6 +52,7 @@ | |||
| 50 | %test-dnsmasq | 52 | %test-dnsmasq |
| 51 | %test-tor | 53 | %test-tor |
| 52 | %test-iptables | 54 | %test-iptables |
| 55 | %test-nftables | ||
| 53 | %test-ipfs)) | 56 | %test-ipfs)) |
| 54 | 57 | ||
| 55 | 58 | ||
| @@ -968,6 +971,8 @@ subnet 192.168.1.0 netmask 255.255.255.0 { | |||
| 968 | (description "Test a running Tor daemon configuration.") | 971 | (description "Test a running Tor daemon configuration.") |
| 969 | (value (run-tor-test)))) | 972 | (value (run-tor-test)))) |
| 970 | 973 | ||
| 974 | (define %inetd-echo-port 7) | ||
| 975 | |||
| 971 | (define* (run-iptables-test) | 976 | (define* (run-iptables-test) |
| 972 | "Run tests of 'iptables-service-type'." | 977 | "Run tests of 'iptables-service-type'." |
| 973 | (define iptables-rules | 978 | (define iptables-rules |
| @@ -988,8 +993,6 @@ COMMIT | |||
| 988 | COMMIT | 993 | COMMIT |
| 989 | ") | 994 | ") |
| 990 | 995 | ||
| 991 | (define inetd-echo-port 7) | ||
| 992 | |||
| 993 | (define os | 996 | (define os |
| 994 | (marionette-operating-system | 997 | (marionette-operating-system |
| 995 | (simple-operating-system | 998 | (simple-operating-system |
| @@ -1065,7 +1068,8 @@ COMMIT | |||
| 1065 | 1068 | ||
| 1066 | (test-error "iptables firewall blocks access to inetd echo service" | 1069 | (test-error "iptables firewall blocks access to inetd echo service" |
| 1067 | 'misc-error | 1070 | 'misc-error |
| 1068 | (wait-for-tcp-port inetd-echo-port marionette #:timeout 5)) | 1071 | (wait-for-tcp-port #$%inetd-echo-port marionette |
| 1072 | #:timeout 5)) | ||
| 1069 | 1073 | ||
| 1070 | ;; TODO: This test freezes up at the login prompt without any | 1074 | ;; TODO: This test freezes up at the login prompt without any |
| 1071 | ;; relevant messages on the console. Perhaps it is waiting for some | 1075 | ;; relevant messages on the console. Perhaps it is waiting for some |
| @@ -1077,7 +1081,7 @@ COMMIT | |||
| 1077 | ;; (use-modules (gnu services herd)) | 1081 | ;; (use-modules (gnu services herd)) |
| 1078 | ;; (stop-service 'iptables)) | 1082 | ;; (stop-service 'iptables)) |
| 1079 | ;; marionette) | 1083 | ;; marionette) |
| 1080 | ;; (wait-for-tcp-port inetd-echo-port marionette #:timeout 5))) | 1084 | ;; (wait-for-tcp-port #$%inetd-echo-port marionette #:timeout 5))) |
| 1081 | 1085 | ||
| 1082 | (test-end)))) | 1086 | (test-end)))) |
| 1083 | 1087 | ||
| @@ -1091,6 +1095,107 @@ COMMIT | |||
| 1091 | 1095 | ||
| 1092 | 1096 | ||
| 1093 | ;;; | 1097 | ;;; |
| 1098 | ;;; nftables. | ||
| 1099 | ;;; | ||
| 1100 | |||
| 1101 | (define (make-nftables-os ruleset) | ||
| 1102 | (simple-operating-system | ||
| 1103 | (service dhcp-client-service-type) | ||
| 1104 | (service inetd-service-type | ||
| 1105 | (inetd-configuration | ||
| 1106 | (entries (list | ||
| 1107 | (inetd-entry | ||
| 1108 | (name "echo") | ||
| 1109 | (socket-type 'stream) | ||
| 1110 | (protocol "tcp") | ||
| 1111 | (wait? #f) | ||
| 1112 | (user "root")))))) | ||
| 1113 | (service openssh-service-type) | ||
| 1114 | (service nftables-service-type | ||
| 1115 | (nftables-configuration | ||
| 1116 | (debug-levels '(all)) | ||
| 1117 | (ruleset ruleset))))) | ||
| 1118 | |||
| 1119 | (define %default-nftables-ruleset-for-tests | ||
| 1120 | ;; This is like the %default-nftables-ruleset, but without allowing any | ||
| 1121 | ;; connections from the loopback interface. | ||
| 1122 | (plain-file "nftables.conf" "\ | ||
| 1123 | table inet filter { | ||
| 1124 | chain input { | ||
| 1125 | type filter hook input priority 0; policy drop; | ||
| 1126 | |||
| 1127 | # early drop of invalid connections | ||
| 1128 | ct state invalid drop | ||
| 1129 | |||
| 1130 | # allow established/related connections | ||
| 1131 | ct state { established, related } accept | ||
| 1132 | |||
| 1133 | # allow from loopback | ||
| 1134 | # iif lo accept # COMMENTED OUT FOR TESTS | ||
| 1135 | # drop connections to lo not coming from lo | ||
| 1136 | iif != lo ip daddr 127.0.0.1/8 drop | ||
| 1137 | iif != lo ip6 daddr ::1/128 drop | ||
| 1138 | |||
| 1139 | # allow icmp | ||
| 1140 | ip protocol icmp accept | ||
| 1141 | ip6 nexthdr icmpv6 accept | ||
| 1142 | |||
| 1143 | # allow ssh | ||
| 1144 | tcp dport ssh accept | ||
| 1145 | |||
| 1146 | # reject everything else | ||
| 1147 | reject with icmpx type port-unreachable | ||
| 1148 | } | ||
| 1149 | chain forward { | ||
| 1150 | type filter hook forward priority 0; policy drop; | ||
| 1151 | } | ||
| 1152 | chain output { | ||
| 1153 | type filter hook output priority 0; policy accept; | ||
| 1154 | } | ||
| 1155 | }")) | ||
| 1156 | |||
| 1157 | (define %nftables-os | ||
| 1158 | (make-nftables-os %default-nftables-ruleset-for-tests)) | ||
| 1159 | |||
| 1160 | (define (run-nftables-test) | ||
| 1161 | (define os | ||
| 1162 | (marionette-operating-system | ||
| 1163 | %nftables-os | ||
| 1164 | #:imported-modules '((gnu services herd)) | ||
| 1165 | #:requirements '(inetd nftables ssh))) | ||
| 1166 | |||
| 1167 | (define test | ||
| 1168 | (with-imported-modules '((gnu build marionette)) | ||
| 1169 | #~(begin | ||
| 1170 | (use-modules (gnu build marionette) | ||
| 1171 | (srfi srfi-64)) | ||
| 1172 | (define marionette | ||
| 1173 | (make-marionette (list #$(virtual-machine os)))) | ||
| 1174 | |||
| 1175 | (test-runner-current (system-test-runner #$output)) | ||
| 1176 | (test-begin "nftables") | ||
| 1177 | |||
| 1178 | (test-error "nftables blocks access to inetd echo service" | ||
| 1179 | 'misc-error | ||
| 1180 | (wait-for-tcp-port #$%inetd-echo-port marionette | ||
| 1181 | #:timeout 5)) | ||
| 1182 | |||
| 1183 | (test-assert "nftables allows access to SSH TCP port 22" | ||
| 1184 | (wait-for-tcp-port 22 marionette)) | ||
| 1185 | |||
| 1186 | (test-end)))) | ||
| 1187 | |||
| 1188 | (gexp->derivation "nftables-test" test)) | ||
| 1189 | |||
| 1190 | (define %test-nftables | ||
| 1191 | (system-test | ||
| 1192 | (name "nftables") | ||
| 1193 | (description "Test the nftables service properly allow or block | ||
| 1194 | connection to ports.") | ||
| 1195 | (value (run-nftables-test)))) | ||
| 1196 | |||
| 1197 | |||
| 1198 | ;;; | ||
| 1094 | ;;; IPFS service | 1199 | ;;; IPFS service |
| 1095 | ;;; | 1200 | ;;; |
| 1096 | 1201 | ||
