diff options
| author | Danny Milosavljevic <dannym@friendly-machines.com> | 2025-12-18 00:54:21 +0100 |
|---|---|---|
| committer | Danny Milosavljevic <dannym@friendly-machines.com> | 2026-01-08 01:53:57 +0100 |
| commit | ac92638bcec817cbbf94201eab0b342553987d42 (patch) | |
| tree | f841f1b82ab5fab71c5981905bd4119be518b345 | |
| parent | 5dca6d6643ba88414d10dee224c3bfa430e9cd4b (diff) | |
services: Add opensnitch-service.
* gnu/services/opensnitch.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add reference to it.
* doc/guix.texi (Miscellaneous Services, Security): Document it.
* gnu/tests/security.scm (%test-opensnitch): New variable.
Change-Id: I63d1b6636b3aaecf399664ec97383d82ff1391d1
| -rw-r--r-- | doc/guix.texi | 121 | ||||
| -rw-r--r-- | gnu/local.mk | 1 | ||||
| -rw-r--r-- | gnu/services/opensnitch.scm | 230 | ||||
| -rw-r--r-- | gnu/tests/security.scm | 88 |
4 files changed, 439 insertions, 1 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 93918f19446..75204215c5c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -46281,6 +46281,127 @@ Mode for filter. | |||
| 46281 | 46281 | ||
| 46282 | @c End of auto-generated fail2ban documentation. | 46282 | @c End of auto-generated fail2ban documentation. |
| 46283 | 46283 | ||
| 46284 | @cindex OpenSnitch | ||
| 46285 | @subsubheading OpenSnitch Service | ||
| 46286 | |||
| 46287 | @uref{https://github.com/evilsocket/opensnitch, OpenSnitch} is an | ||
| 46288 | application-level firewall that monitors outbound connections and prompts | ||
| 46289 | users to allow or deny them on a per-application basis. | ||
| 46290 | |||
| 46291 | @code{opensnitch-service-type} is provided by the @code{(gnu services | ||
| 46292 | opensnitch)} module. | ||
| 46293 | |||
| 46294 | @defvar opensnitch-service-type | ||
| 46295 | This is the service type for the OpenSnitch application firewall daemon. | ||
| 46296 | Its value must be an @code{opensnitch-configuration} record. | ||
| 46297 | |||
| 46298 | Below is an example configuration: | ||
| 46299 | |||
| 46300 | @lisp | ||
| 46301 | (service opensnitch-service-type) | ||
| 46302 | @end lisp | ||
| 46303 | |||
| 46304 | This service depends on the @code{networking} service. | ||
| 46305 | @end defvar | ||
| 46306 | |||
| 46307 | @deftp {Data Type} opensnitch-configuration | ||
| 46308 | Available @code{opensnitch-configuration} fields are: | ||
| 46309 | |||
| 46310 | @table @asis | ||
| 46311 | @item @code{opensnitch} (default: @code{opensnitch-daemon}) (type: package) | ||
| 46312 | The @code{opensnitch-daemon} package to use. | ||
| 46313 | |||
| 46314 | @item @code{server-address} (default: @code{"unix:///tmp/osui.sock"}) (type: string) | ||
| 46315 | Address for the UI to connect to the daemon. | ||
| 46316 | |||
| 46317 | @item @code{server-log-file} (default: @code{"/var/log/opensnitchd.log"}) (type: string) | ||
| 46318 | Path to the daemon log file. | ||
| 46319 | |||
| 46320 | @item @code{authentication-type} (default: @code{"simple"}) (type: string) | ||
| 46321 | Authentication type for UI-daemon communication. | ||
| 46322 | |||
| 46323 | @item @code{tls-ca-cert} (default: @code{""}) (type: string) | ||
| 46324 | Path to TLS CA certificate. | ||
| 46325 | |||
| 46326 | @item @code{tls-server-cert} (default: @code{""}) (type: string) | ||
| 46327 | Path to TLS server certificate. | ||
| 46328 | |||
| 46329 | @item @code{tls-client-cert} (default: @code{""}) (type: string) | ||
| 46330 | Path to TLS client certificate. | ||
| 46331 | |||
| 46332 | @item @code{tls-client-key} (default: @code{""}) (type: string) | ||
| 46333 | Path to TLS client key. | ||
| 46334 | |||
| 46335 | @item @code{tls-skip-verify?} (default: @code{#f}) (type: boolean) | ||
| 46336 | Whether to skip TLS verification. | ||
| 46337 | |||
| 46338 | @item @code{tls-client-auth-type} (default: @code{"no-client-cert"}) (type: string) | ||
| 46339 | TLS client authentication type. | ||
| 46340 | |||
| 46341 | @item @code{default-action} (default: @code{"allow"}) (type: string) | ||
| 46342 | Default action for connections: @code{"allow"} or @code{"deny"}. | ||
| 46343 | |||
| 46344 | @item @code{default-duration} (default: @code{"once"}) (type: string) | ||
| 46345 | Default duration for rules: @code{"once"}, @code{"until-restart"}, | ||
| 46346 | @code{"always"}, etc. | ||
| 46347 | |||
| 46348 | @item @code{intercept-unknown?} (default: @code{#f}) (type: boolean) | ||
| 46349 | Whether to intercept connections from unknown processes. | ||
| 46350 | |||
| 46351 | @item @code{proc-monitor-method} (default: @code{"ebpf"}) (type: string) | ||
| 46352 | Method for monitoring processes: @code{"ebpf"}, @code{"proc"}, or | ||
| 46353 | @code{"audit"}. | ||
| 46354 | |||
| 46355 | @item @code{log-level} (default: @code{2}) (type: integer) | ||
| 46356 | Log level: 0=silent, 1=error, 2=warning, 3=important, 4=debug. | ||
| 46357 | |||
| 46358 | @item @code{log-utc?} (default: @code{#t}) (type: boolean) | ||
| 46359 | Whether to log timestamps in UTC. | ||
| 46360 | |||
| 46361 | @item @code{log-micro?} (default: @code{#f}) (type: boolean) | ||
| 46362 | Whether to include microseconds in log timestamps. | ||
| 46363 | |||
| 46364 | @item @code{firewall} (default: @code{"nftables"}) (type: string) | ||
| 46365 | Firewall backend: @code{"nftables"} or @code{"iptables"}. | ||
| 46366 | |||
| 46367 | @item @code{fw-config-path} (default: @code{"/etc/opensnitchd/system-fw.json"}) (type: string) | ||
| 46368 | Path to the system firewall configuration file. | ||
| 46369 | |||
| 46370 | @item @code{fw-monitor-interval} (default: @code{"15s"}) (type: string) | ||
| 46371 | Interval for monitoring firewall rules. | ||
| 46372 | |||
| 46373 | @item @code{fw-queue-bypass?} (default: @code{#t}) (type: boolean) | ||
| 46374 | Whether to bypass the queue when the daemon is not running. | ||
| 46375 | |||
| 46376 | @item @code{rules-path} (default: @code{"/etc/opensnitchd/rules/"}) (type: string) | ||
| 46377 | Directory where firewall rules are stored. | ||
| 46378 | |||
| 46379 | @item @code{rules-enable-checksums?} (default: @code{#f}) (type: boolean) | ||
| 46380 | Whether to enable checksums for rules. | ||
| 46381 | |||
| 46382 | @item @code{ebpf-events-workers} (default: @code{8}) (type: integer) | ||
| 46383 | Number of eBPF event worker threads. | ||
| 46384 | |||
| 46385 | @item @code{ebpf-queue-events-size} (default: @code{0}) (type: integer) | ||
| 46386 | Size of the eBPF events queue (0 = default). | ||
| 46387 | |||
| 46388 | @item @code{stats-max-events} (default: @code{250}) (type: integer) | ||
| 46389 | Maximum number of events to keep in statistics. | ||
| 46390 | |||
| 46391 | @item @code{stats-max-stats} (default: @code{25}) (type: integer) | ||
| 46392 | Maximum number of statistics entries. | ||
| 46393 | |||
| 46394 | @item @code{stats-workers} (default: @code{6}) (type: integer) | ||
| 46395 | Number of statistics worker threads. | ||
| 46396 | |||
| 46397 | @item @code{internal-gc-percent} (default: @code{100}) (type: integer) | ||
| 46398 | Go garbage collector percentage. | ||
| 46399 | |||
| 46400 | @item @code{internal-flush-conns-on-start?} (default: @code{#t}) (type: boolean) | ||
| 46401 | Whether to flush existing connections on daemon start. | ||
| 46402 | @end table | ||
| 46403 | @end deftp | ||
| 46404 | |||
| 46284 | @cindex resize-file-system | 46405 | @cindex resize-file-system |
| 46285 | @subsubheading Resize File System Service | 46406 | @subsubheading Resize File System Service |
| 46286 | 46407 | ||
diff --git a/gnu/local.mk b/gnu/local.mk index f2d060c43b2..75accdbf20e 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -758,6 +758,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 758 | %D%/services/networking.scm \ | 758 | %D%/services/networking.scm \ |
| 759 | %D%/services/nix.scm \ | 759 | %D%/services/nix.scm \ |
| 760 | %D%/services/nfs.scm \ | 760 | %D%/services/nfs.scm \ |
| 761 | %D%/services/opensnitch.scm \ | ||
| 761 | %D%/services/pam-mount.scm \ | 762 | %D%/services/pam-mount.scm \ |
| 762 | %D%/services/power.scm \ | 763 | %D%/services/power.scm \ |
| 763 | %D%/services/science.scm \ | 764 | %D%/services/science.scm \ |
diff --git a/gnu/services/opensnitch.scm b/gnu/services/opensnitch.scm new file mode 100644 index 00000000000..2f213a81b01 --- /dev/null +++ b/gnu/services/opensnitch.scm | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2025 Danny Milosavljevic <dannym@friendly-machines.com> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu services opensnitch) | ||
| 20 | #:use-module (gnu packages networking) | ||
| 21 | #:use-module (gnu services) | ||
| 22 | #:use-module (gnu services base) | ||
| 23 | #:use-module (gnu services configuration) | ||
| 24 | #:use-module (gnu services shepherd) | ||
| 25 | #:use-module (guix gexp) | ||
| 26 | #:use-module (guix packages) | ||
| 27 | #:use-module (guix records) | ||
| 28 | #:use-module (json) | ||
| 29 | #:export (opensnitch-configuration | ||
| 30 | opensnitch-configuration? | ||
| 31 | opensnitch-service-type)) | ||
| 32 | |||
| 33 | (define-configuration/no-serialization opensnitch-configuration | ||
| 34 | (opensnitch | ||
| 35 | (package opensnitch-daemon) | ||
| 36 | "The @code{opensnitch-daemon} package to use.") | ||
| 37 | |||
| 38 | ;; Server settings | ||
| 39 | (server-address | ||
| 40 | (string "unix:///tmp/osui.sock") | ||
| 41 | "Address for the UI to connect to the daemon.") | ||
| 42 | (server-log-file | ||
| 43 | (string "/var/log/opensnitchd.log") | ||
| 44 | "Path to the daemon log file.") | ||
| 45 | |||
| 46 | ;; Authentication settings | ||
| 47 | (authentication-type | ||
| 48 | (string "simple") | ||
| 49 | "Authentication type for UI-daemon communication.") | ||
| 50 | (tls-ca-cert | ||
| 51 | (string "") | ||
| 52 | "Path to TLS CA certificate.") | ||
| 53 | (tls-server-cert | ||
| 54 | (string "") | ||
| 55 | "Path to TLS server certificate.") | ||
| 56 | (tls-client-cert | ||
| 57 | (string "") | ||
| 58 | "Path to TLS client certificate.") | ||
| 59 | (tls-client-key | ||
| 60 | (string "") | ||
| 61 | "Path to TLS client key.") | ||
| 62 | (tls-skip-verify? | ||
| 63 | (boolean #f) | ||
| 64 | "Whether to skip TLS verification.") | ||
| 65 | (tls-client-auth-type | ||
| 66 | (string "no-client-cert") | ||
| 67 | "TLS client authentication type.") | ||
| 68 | |||
| 69 | ;; Default behavior | ||
| 70 | (default-action | ||
| 71 | (string "allow") | ||
| 72 | "Default action for connections: @code{\"allow\"} or @code{\"deny\"}.") | ||
| 73 | (default-duration | ||
| 74 | (string "once") | ||
| 75 | "Default duration for rules: @code{\"once\"}, @code{\"until-restart\"}, | ||
| 76 | @code{\"always\"}, etc.") | ||
| 77 | (intercept-unknown? | ||
| 78 | (boolean #f) | ||
| 79 | "Whether to intercept connections from unknown processes.") | ||
| 80 | |||
| 81 | ;; Process monitoring | ||
| 82 | (proc-monitor-method | ||
| 83 | (string "ebpf") | ||
| 84 | "Method for monitoring processes: @code{\"ebpf\"}, @code{\"proc\"}, or | ||
| 85 | @code{\"audit\"}.") | ||
| 86 | |||
| 87 | ;; Logging | ||
| 88 | (log-level | ||
| 89 | (integer 2) | ||
| 90 | "Log level: 0=silent, 1=error, 2=warning, 3=important, 4=debug.") | ||
| 91 | (log-utc? | ||
| 92 | (boolean #t) | ||
| 93 | "Whether to log timestamps in UTC.") | ||
| 94 | (log-micro? | ||
| 95 | (boolean #f) | ||
| 96 | "Whether to include microseconds in log timestamps.") | ||
| 97 | |||
| 98 | ;; Firewall settings | ||
| 99 | (firewall | ||
| 100 | (string "nftables") | ||
| 101 | "Firewall backend: @code{\"nftables\"} or @code{\"iptables\"}.") | ||
| 102 | (fw-config-path | ||
| 103 | (string "/etc/opensnitchd/system-fw.json") | ||
| 104 | "Path to the system firewall configuration file.") | ||
| 105 | (fw-monitor-interval | ||
| 106 | (string "15s") | ||
| 107 | "Interval for monitoring firewall rules.") | ||
| 108 | (fw-queue-bypass? | ||
| 109 | (boolean #t) | ||
| 110 | "Whether to bypass the queue when the daemon is not running.") | ||
| 111 | |||
| 112 | ;; Rules settings | ||
| 113 | (rules-path | ||
| 114 | (string "/etc/opensnitchd/rules/") | ||
| 115 | "Directory where firewall rules are stored.") | ||
| 116 | (rules-enable-checksums? | ||
| 117 | (boolean #f) | ||
| 118 | "Whether to enable checksums for rules.") | ||
| 119 | |||
| 120 | ;; eBPF settings | ||
| 121 | (ebpf-events-workers | ||
| 122 | (integer 8) | ||
| 123 | "Number of eBPF event worker threads.") | ||
| 124 | (ebpf-queue-events-size | ||
| 125 | (integer 0) | ||
| 126 | "Size of the eBPF events queue (0 = default).") | ||
| 127 | |||
| 128 | ;; Statistics settings | ||
| 129 | (stats-max-events | ||
| 130 | (integer 250) | ||
| 131 | "Maximum number of events to keep in statistics.") | ||
| 132 | (stats-max-stats | ||
| 133 | (integer 25) | ||
| 134 | "Maximum number of statistics entries.") | ||
| 135 | (stats-workers | ||
| 136 | (integer 6) | ||
| 137 | "Number of statistics worker threads.") | ||
| 138 | |||
| 139 | ;; Internal settings | ||
| 140 | (internal-gc-percent | ||
| 141 | (integer 100) | ||
| 142 | "Go garbage collector percentage.") | ||
| 143 | (internal-flush-conns-on-start? | ||
| 144 | (boolean #t) | ||
| 145 | "Whether to flush existing connections on daemon start.")) | ||
| 146 | |||
| 147 | (define (opensnitch-configuration->json config) | ||
| 148 | "Convert CONFIG to a JSON string for the OpenSnitch daemon." | ||
| 149 | (match-record config <opensnitch-configuration> | ||
| 150 | (server-address server-log-file | ||
| 151 | authentication-type tls-ca-cert tls-server-cert tls-client-cert | ||
| 152 | tls-client-key tls-skip-verify? tls-client-auth-type | ||
| 153 | default-action default-duration intercept-unknown? | ||
| 154 | proc-monitor-method log-level log-utc? log-micro? | ||
| 155 | firewall fw-config-path fw-monitor-interval fw-queue-bypass? | ||
| 156 | rules-path rules-enable-checksums? | ||
| 157 | ebpf-events-workers ebpf-queue-events-size | ||
| 158 | stats-max-events stats-max-stats stats-workers | ||
| 159 | internal-gc-percent internal-flush-conns-on-start?) | ||
| 160 | (scm->json-string | ||
| 161 | `((Server . ((Address . ,server-address) | ||
| 162 | (Authentication . ((Type . ,authentication-type) | ||
| 163 | (TLSOptions . ((CACert . ,tls-ca-cert) | ||
| 164 | (ServerCert . ,tls-server-cert) | ||
| 165 | (ClientCert . ,tls-client-cert) | ||
| 166 | (ClientKey . ,tls-client-key) | ||
| 167 | (SkipVerify . ,tls-skip-verify?) | ||
| 168 | (ClientAuthType . ,tls-client-auth-type))))) | ||
| 169 | (LogFile . ,server-log-file))) | ||
| 170 | (DefaultAction . ,default-action) | ||
| 171 | (DefaultDuration . ,default-duration) | ||
| 172 | (InterceptUnknown . ,intercept-unknown?) | ||
| 173 | (ProcMonitorMethod . ,proc-monitor-method) | ||
| 174 | (LogLevel . ,log-level) | ||
| 175 | (LogUTC . ,log-utc?) | ||
| 176 | (LogMicro . ,log-micro?) | ||
| 177 | (Firewall . ,firewall) | ||
| 178 | (FwOptions . ((ConfigPath . ,fw-config-path) | ||
| 179 | (MonitorInterval . ,fw-monitor-interval) | ||
| 180 | (QueueBypass . ,fw-queue-bypass?))) | ||
| 181 | (Rules . ((Path . ,rules-path) | ||
| 182 | (EnableChecksums . ,rules-enable-checksums?))) | ||
| 183 | (Ebpf . ((EventsWorkers . ,ebpf-events-workers) | ||
| 184 | (QueueEventsSize . ,ebpf-queue-events-size))) | ||
| 185 | (Stats . ((MaxEvents . ,stats-max-events) | ||
| 186 | (MaxStats . ,stats-max-stats) | ||
| 187 | (Workers . ,stats-workers))) | ||
| 188 | (Internal . ((GCPercent . ,internal-gc-percent) | ||
| 189 | (FlushConnsOnStart . ,internal-flush-conns-on-start?)))) | ||
| 190 | #:pretty #t))) | ||
| 191 | |||
| 192 | (define (opensnitch-config-file config) | ||
| 193 | "Return a file-like object for the OpenSnitch configuration." | ||
| 194 | (plain-file "opensnitch-config.json" | ||
| 195 | (opensnitch-configuration->json config))) | ||
| 196 | |||
| 197 | (define (opensnitch-activation config) | ||
| 198 | "Return the activation gexp for CONFIG." | ||
| 199 | (match-record config <opensnitch-configuration> | ||
| 200 | (rules-path) | ||
| 201 | (with-imported-modules '((guix build utils)) | ||
| 202 | #~(begin | ||
| 203 | (use-modules (guix build utils)) | ||
| 204 | (mkdir-p #$rules-path))))) | ||
| 205 | |||
| 206 | (define (opensnitch-shepherd-service config) | ||
| 207 | (match-record config <opensnitch-configuration> | ||
| 208 | (opensnitch server-log-file) | ||
| 209 | (list (shepherd-service | ||
| 210 | (documentation "Run the OpenSnitch application firewall daemon.") | ||
| 211 | (provision '(opensnitch)) | ||
| 212 | (requirement '(user-processes networking)) | ||
| 213 | (start #~(make-forkexec-constructor | ||
| 214 | (list #$(file-append opensnitch "/sbin/opensnitchd") | ||
| 215 | "-config-file" #$(opensnitch-config-file config)) | ||
| 216 | #:log-file #$server-log-file)) | ||
| 217 | (stop #~(make-kill-destructor)))))) | ||
| 218 | |||
| 219 | (define opensnitch-service-type | ||
| 220 | (service-type | ||
| 221 | (name 'opensnitch) | ||
| 222 | (description "Run the OpenSnitch application firewall daemon.") | ||
| 223 | (extensions | ||
| 224 | (list (service-extension shepherd-root-service-type | ||
| 225 | opensnitch-shepherd-service) | ||
| 226 | (service-extension activation-service-type | ||
| 227 | opensnitch-activation) | ||
| 228 | (service-extension profile-service-type | ||
| 229 | (compose list opensnitch-configuration-opensnitch)))) | ||
| 230 | (default-value (opensnitch-configuration)))) | ||
diff --git a/gnu/tests/security.scm b/gnu/tests/security.scm index 8887396b89b..204f3262da8 100644 --- a/gnu/tests/security.scm +++ b/gnu/tests/security.scm | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2022 muradm <mail@muradm.net> | 2 | ;;; Copyright © 2022 muradm <mail@muradm.net> |
| 3 | ;;; Copyright © 2025 Danny Milosavljevic <dannym@friendly-machines.com> | ||
| 3 | ;;; | 4 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 6 | ;;; |
| @@ -19,8 +20,10 @@ | |||
| 19 | (define-module (gnu tests security) | 20 | (define-module (gnu tests security) |
| 20 | #:use-module (guix gexp) | 21 | #:use-module (guix gexp) |
| 21 | #:use-module (gnu packages admin) | 22 | #:use-module (gnu packages admin) |
| 23 | #:use-module (gnu packages linux) | ||
| 22 | #:use-module (gnu services) | 24 | #:use-module (gnu services) |
| 23 | #:use-module (gnu services base) | 25 | #:use-module (gnu services base) |
| 26 | #:use-module (gnu services opensnitch) | ||
| 24 | #:use-module (gnu services security) | 27 | #:use-module (gnu services security) |
| 25 | #:use-module (gnu services ssh) | 28 | #:use-module (gnu services ssh) |
| 26 | #:use-module (gnu system) | 29 | #:use-module (gnu system) |
| @@ -28,7 +31,8 @@ | |||
| 28 | #:use-module (gnu tests) | 31 | #:use-module (gnu tests) |
| 29 | #:export (%test-fail2ban-basic | 32 | #:export (%test-fail2ban-basic |
| 30 | %test-fail2ban-extension | 33 | %test-fail2ban-extension |
| 31 | %test-fail2ban-simple)) | 34 | %test-fail2ban-simple |
| 35 | %test-opensnitch)) | ||
| 32 | 36 | ||
| 33 | 37 | ||
| 34 | ;;; | 38 | ;;; |
| @@ -238,3 +242,85 @@ | |||
| 238 | (name "fail2ban-extension") | 242 | (name "fail2ban-extension") |
| 239 | (description "Test extension fail2ban running capability.") | 243 | (description "Test extension fail2ban running capability.") |
| 240 | (value (run-fail2ban-extension-test)))) | 244 | (value (run-fail2ban-extension-test)))) |
| 245 | |||
| 246 | |||
| 247 | ;;; | ||
| 248 | ;;; OpenSnitch tests | ||
| 249 | ;;; | ||
| 250 | |||
| 251 | (define (run-opensnitch-test) | ||
| 252 | (define os | ||
| 253 | (marionette-operating-system | ||
| 254 | (simple-operating-system | ||
| 255 | (service opensnitch-service-type) | ||
| 256 | (service static-networking-service-type | ||
| 257 | (list %qemu-static-networking))) | ||
| 258 | #:imported-modules '((gnu services herd)))) | ||
| 259 | |||
| 260 | (define vm | ||
| 261 | (virtual-machine | ||
| 262 | (operating-system os) | ||
| 263 | (port-forwardings '()))) | ||
| 264 | |||
| 265 | (define test | ||
| 266 | (with-imported-modules '((gnu build marionette) | ||
| 267 | (guix build utils)) | ||
| 268 | #~(begin | ||
| 269 | (use-modules (srfi srfi-64) | ||
| 270 | (gnu build marionette)) | ||
| 271 | |||
| 272 | (define marionette (make-marionette (list #$vm))) | ||
| 273 | |||
| 274 | (test-runner-current (system-test-runner #$output)) | ||
| 275 | (test-begin "opensnitch") | ||
| 276 | |||
| 277 | (test-assert "opensnitch running" | ||
| 278 | (marionette-eval | ||
| 279 | '(begin | ||
| 280 | (use-modules (gnu services herd)) | ||
| 281 | (start-service 'opensnitch)) | ||
| 282 | marionette)) | ||
| 283 | |||
| 284 | (test-assert "opensnitch log file" | ||
| 285 | (marionette-eval | ||
| 286 | '(file-exists? "/var/log/opensnitchd.log") | ||
| 287 | marionette)) | ||
| 288 | |||
| 289 | (test-assert "opensnitch rules directory" | ||
| 290 | (marionette-eval | ||
| 291 | '(file-exists? "/etc/opensnitchd/rules") | ||
| 292 | marionette)) | ||
| 293 | |||
| 294 | (test-assert "opensnitch process running" | ||
| 295 | (marionette-eval | ||
| 296 | `(zero? (system* ,#$(file-append procps "/bin/pgrep") | ||
| 297 | "-x" "opensnitchd")) | ||
| 298 | marionette)) | ||
| 299 | |||
| 300 | (test-assert "opensnitch running after restart" | ||
| 301 | (marionette-eval | ||
| 302 | '(begin | ||
| 303 | (use-modules (gnu services herd)) | ||
| 304 | (restart-service 'opensnitch)) | ||
| 305 | marionette)) | ||
| 306 | |||
| 307 | (test-assert "opensnitch process running after restart" | ||
| 308 | (marionette-eval | ||
| 309 | `(let loop ((tries 0)) | ||
| 310 | (if (zero? (system* ,#$(file-append procps "/bin/pgrep") | ||
| 311 | "-x" "opensnitchd")) | ||
| 312 | #t | ||
| 313 | (if (< tries 30) | ||
| 314 | (begin (sleep 1) (loop (+ tries 1))) | ||
| 315 | #f))) | ||
| 316 | marionette)) | ||
| 317 | |||
| 318 | (test-end)))) | ||
| 319 | |||
| 320 | (gexp->derivation "opensnitch-test" test)) | ||
| 321 | |||
| 322 | (define %test-opensnitch | ||
| 323 | (system-test | ||
| 324 | (name "opensnitch") | ||
| 325 | (description "Test OpenSnitch application firewall daemon.") | ||
| 326 | (value (run-opensnitch-test)))) | ||
