summaryrefslogtreecommitdiff
path: root/gnu/services/virtualization.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-12-20 10:36:25 +0100
committerLudovic Courtès <ludo@gnu.org>2024-02-10 22:59:43 +0100
commitf331a667d3827c5c7603c87956c601d5e42ef82b (patch)
tree13b7c011a87991654c56fa785a734f5c21ff86d3 /gnu/services/virtualization.scm
parent11d5b505e5e0f6bccd804d407cc609b421962073 (diff)
services: secret-service: Make the endpoint configurable.
Until now, the secret service had a hard-coded TCP endpoint on port 1004. This change lets users specify arbitrary socket addresses. * gnu/build/secret-service.scm (socket-address->string): New procedure, taken from Shepherd. (secret-service-send-secrets): Replace ‘port’ by ‘address’ and adjust accordingly. (secret-service-receive-secrets): Likewise. * gnu/services/virtualization.scm (secret-service-shepherd-services): Likewise. (secret-service-operating-system): Add optional ‘address’ parameter and honor it. Adjust ‘start’ method accordingly. Change-Id: I87a9514f1c170dca756ce76083d7182c6ebf6578
Diffstat (limited to 'gnu/services/virtualization.scm')
-rw-r--r--gnu/services/virtualization.scm40
1 files changed, 23 insertions, 17 deletions
diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index f0f0ab3bf11..5b8566f6009 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -996,7 +996,7 @@ specified, the QEMU default path is used."))
996;;; Secrets for guest VMs. 996;;; Secrets for guest VMs.
997;;; 997;;;
998 998
999(define (secret-service-shepherd-services port) 999(define (secret-service-shepherd-services address)
1000 "Return a Shepherd service that fetches sensitive material at local PORT, 1000 "Return a Shepherd service that fetches sensitive material at local PORT,
1001over TCP. Reboot upon failure." 1001over TCP. Reboot upon failure."
1002 ;; This is a Shepherd service, rather than an activation snippet, to make 1002 ;; This is a Shepherd service, rather than an activation snippet, to make
@@ -1018,7 +1018,7 @@ over TCP. Reboot upon failure."
1018 "receiving secrets from the host...~%") 1018 "receiving secrets from the host...~%")
1019 (force-output (current-error-port)) 1019 (force-output (current-error-port))
1020 1020
1021 (let ((sent (secret-service-receive-secrets #$port))) 1021 (let ((sent (secret-service-receive-secrets #$address)))
1022 (unless sent 1022 (unless sent
1023 (sleep 3) 1023 (sleep 3)
1024 (reboot)))))) 1024 (reboot))))))
@@ -1039,9 +1039,13 @@ over TCP. Reboot upon failure."
1039boot time. This service is meant to be used by virtual machines (VMs) that 1039boot time. This service is meant to be used by virtual machines (VMs) that
1040can only be accessed by their host."))) 1040can only be accessed by their host.")))
1041 1041
1042(define (secret-service-operating-system os) 1042(define* (secret-service-operating-system os
1043 #:optional
1044 (address
1045 #~(make-socket-address
1046 AF_INET INADDR_ANY 1004)))
1043 "Return an operating system based on OS that includes the secret-service, 1047 "Return an operating system based on OS that includes the secret-service,
1044that will be listening to receive secret keys on port 1004, TCP." 1048that will be listening to receive secret keys on ADDRESS."
1045 (operating-system 1049 (operating-system
1046 (inherit os) 1050 (inherit os)
1047 (services 1051 (services
@@ -1049,7 +1053,7 @@ that will be listening to receive secret keys on port 1004, TCP."
1049 ;; activation: that requires entropy and thus takes time during boot, and 1053 ;; activation: that requires entropy and thus takes time during boot, and
1050 ;; those keys are going to be overwritten by secrets received from the 1054 ;; those keys are going to be overwritten by secrets received from the
1051 ;; host anyway. 1055 ;; host anyway.
1052 (cons (service secret-service-type 1004) 1056 (cons (service secret-service-type address)
1053 (modify-services (operating-system-user-services os) 1057 (modify-services (operating-system-user-services os)
1054 (openssh-service-type 1058 (openssh-service-type
1055 config => (openssh-configuration 1059 config => (openssh-configuration
@@ -1243,24 +1247,26 @@ is added to the OS specified in CONFIG."
1243 (source-module-closure '((gnu build secret-service) 1247 (source-module-closure '((gnu build secret-service)
1244 (guix build utils))) 1248 (guix build utils)))
1245 #~(lambda () 1249 #~(lambda ()
1246 (let ((pid (fork+exec-command #$vm-command 1250 (let* ((pid (fork+exec-command #$vm-command
1247 #:user "childhurd" 1251 #:user "childhurd"
1248 ;; XXX TODO: use "childhurd" after 1252 ;; XXX TODO: use "childhurd" after
1249 ;; updating Shepherd 1253 ;; updating Shepherd
1250 #:group "kvm" 1254 #:group "kvm"
1251 #:environment-variables 1255 #:environment-variables
1252 ;; QEMU tries to write to /var/tmp 1256 ;; QEMU tries to write to /var/tmp
1253 ;; by default. 1257 ;; by default.
1254 '("TMPDIR=/tmp"))) 1258 '("TMPDIR=/tmp")))
1255 (port #$(hurd-vm-port config %hurd-vm-secrets-port)) 1259 (port #$(hurd-vm-port config %hurd-vm-secrets-port))
1256 (root #$(hurd-vm-configuration-secret-root config))) 1260 (root #$(hurd-vm-configuration-secret-root config))
1261 (address (make-socket-address AF_INET INADDR_LOOPBACK
1262 port)))
1257 (catch #t 1263 (catch #t
1258 (lambda _ 1264 (lambda _
1259 ;; XXX: 'secret-service-send-secrets' won't complete until 1265 ;; XXX: 'secret-service-send-secrets' won't complete until
1260 ;; the guest has booted and its secret service server is 1266 ;; the guest has booted and its secret service server is
1261 ;; running, which could take 20+ seconds during which PID 1 1267 ;; running, which could take 20+ seconds during which PID 1
1262 ;; is stuck waiting. 1268 ;; is stuck waiting.
1263 (if (secret-service-send-secrets port root) 1269 (if (secret-service-send-secrets address root)
1264 pid 1270 pid
1265 (begin 1271 (begin
1266 (kill (- pid) SIGTERM) 1272 (kill (- pid) SIGTERM)