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 /gnu/tests | |
| 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
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/security.scm | 88 |
1 files changed, 87 insertions, 1 deletions
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)))) | ||
