diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-05-16 22:13:44 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-05-18 23:11:19 -0400 |
| commit | d43d8377c741c849ca89dccb07e7d87f82ae88d5 (patch) | |
| tree | aba9f5a8c37dbd48ab74974f1c6e68aa1ba450c2 | |
| parent | 03e601da49e43ed0235144f32095ce5f58f16275 (diff) | |
services: rsync: Use least authority wrapper.
* gnu/services/rsync.scm (rsync-shepherd-service) Wrap rsync command in a
least-authority-wrapper.
Reviewed-by: Ludovic Courtès <ludo@gnu.org>
| -rw-r--r-- | gnu/services/rsync.scm | 97 |
1 files changed, 65 insertions, 32 deletions
diff --git a/gnu/services/rsync.scm b/gnu/services/rsync.scm index 826b757b1c6..42e4d0247e0 100644 --- a/gnu/services/rsync.scm +++ b/gnu/services/rsync.scm | |||
| @@ -19,16 +19,20 @@ | |||
| 19 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | 19 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 20 | 20 | ||
| 21 | (define-module (gnu services rsync) | 21 | (define-module (gnu services rsync) |
| 22 | #:use-module ((gnu build linux-container) #:select (%namespaces)) | ||
| 22 | #:use-module (gnu services) | 23 | #:use-module (gnu services) |
| 23 | #:use-module (gnu services base) | 24 | #:use-module (gnu services base) |
| 24 | #:use-module (gnu services shepherd) | 25 | #:use-module (gnu services shepherd) |
| 26 | #:autoload (gnu system file-systems) (file-system-mapping) | ||
| 25 | #:use-module (gnu system shadow) | 27 | #:use-module (gnu system shadow) |
| 26 | #:use-module (gnu packages rsync) | ||
| 27 | #:use-module (gnu packages admin) | 28 | #:use-module (gnu packages admin) |
| 29 | #:use-module (gnu packages linux) | ||
| 30 | #:use-module (gnu packages rsync) | ||
| 28 | #:use-module (guix records) | 31 | #:use-module (guix records) |
| 29 | #:use-module (guix gexp) | 32 | #:use-module (guix gexp) |
| 30 | #:use-module (guix diagnostics) | 33 | #:use-module (guix diagnostics) |
| 31 | #:use-module (guix i18n) | 34 | #:use-module (guix i18n) |
| 35 | #:use-module (guix least-authority) | ||
| 32 | #:use-module (srfi srfi-1) | 36 | #:use-module (srfi srfi-1) |
| 33 | #:use-module (srfi srfi-26) | 37 | #:use-module (srfi srfi-26) |
| 34 | #:use-module (ice-9 match) | 38 | #:use-module (ice-9 match) |
| @@ -236,37 +240,66 @@ please use 'modules' instead~%"))) | |||
| 236 | #t)) | 240 | #t)) |
| 237 | (const #f))) | 241 | (const #f))) |
| 238 | 242 | ||
| 239 | (let* ((rsync (rsync-configuration-package config)) | 243 | (define (module->file-system-mapping module) |
| 240 | (pid-file (rsync-configuration-pid-file config)) | 244 | "Return the <file-system-mapping> record corresponding to MODULE, an |
| 241 | (port-number (rsync-configuration-port-number config)) | 245 | <rsync-module> object." |
| 242 | (user (rsync-configuration-user config)) | 246 | (match-record module <rsync-module> |
| 243 | (group (rsync-configuration-group config)) | 247 | (file-name read-only?) |
| 244 | (config-file (rsync-config-file config)) | 248 | (file-system-mapping |
| 245 | (rsync-command #~(list (string-append #$rsync "/bin/rsync") | 249 | (source file-name) |
| 246 | "--config" #$config-file "--daemon"))) | 250 | (target source) |
| 247 | (list (shepherd-service | 251 | (writable? (not read-only?))))) |
| 248 | (provision '(rsync)) | 252 | |
| 249 | (documentation "Run rsync daemon.") | 253 | (match-record config <rsync-configuration> |
| 250 | (actions (list (shepherd-configuration-action config-file))) | 254 | (package log-file modules pid-file port-number user group) |
| 251 | (start #~(if #$inetd-style? | 255 | ;; Run the rsync daemon in its own 'mnt' namespace, to guard against |
| 252 | (make-inetd-constructor | 256 | ;; change to mount points it may be serving. |
| 253 | #$rsync-command | 257 | (let* ((config-file (rsync-config-file config)) |
| 254 | (cons (endpoint | 258 | (rsync-command #~(list #$(least-authority-wrapper |
| 255 | (make-socket-address AF_INET INADDR_ANY | 259 | (file-append rsync "/bin/rsync") |
| 256 | #$port-number)) | 260 | #:name "rsync" |
| 257 | (if #$ipv6-support? | 261 | #:namespaces (fold delq %namespaces |
| 258 | (list | 262 | '(net user)) |
| 259 | (endpoint | 263 | #:mappings |
| 260 | (make-socket-address AF_INET6 IN6ADDR_ANY | 264 | (append (list (file-system-mapping |
| 261 | #$port-number))) | 265 | (source "/var/run/rsyncd") |
| 262 | '())) | 266 | (target source) |
| 263 | #:user #$user | 267 | (writable? #t)) |
| 264 | #:group #$group) | 268 | (file-system-mapping |
| 265 | (make-forkexec-constructor #$rsync-command | 269 | (source (dirname log-file)) |
| 266 | #:pid-file #$pid-file | 270 | (target source) |
| 267 | #:user #$user | 271 | (writable? #t)) |
| 268 | #:group #$group))) | 272 | (file-system-mapping |
| 269 | (stop #~(make-kill-destructor)))))) | 273 | (source config-file) |
| 274 | (target source))) | ||
| 275 | (map module->file-system-mapping | ||
| 276 | modules))) | ||
| 277 | "--config" #$config-file "--daemon"))) | ||
| 278 | (list (shepherd-service | ||
| 279 | (provision '(rsync)) | ||
| 280 | (documentation "Run rsync daemon.") | ||
| 281 | (actions (list (shepherd-configuration-action config-file))) | ||
| 282 | (start #~(if #$inetd-style? | ||
| 283 | (make-inetd-constructor | ||
| 284 | #$rsync-command | ||
| 285 | (cons (endpoint | ||
| 286 | (make-socket-address AF_INET INADDR_ANY | ||
| 287 | #$port-number)) | ||
| 288 | (if #$ipv6-support? | ||
| 289 | (list | ||
| 290 | (endpoint | ||
| 291 | (make-socket-address AF_INET6 IN6ADDR_ANY | ||
| 292 | #$port-number))) | ||
| 293 | '())) | ||
| 294 | #:user #$user | ||
| 295 | #:group #$group) | ||
| 296 | (make-forkexec-constructor #$rsync-command | ||
| 297 | #:pid-file #$pid-file | ||
| 298 | #:user #$user | ||
| 299 | #:group #$group))) | ||
| 300 | (stop #~(if #$inetd-style? | ||
| 301 | (make-inetd-destructor) | ||
| 302 | (make-kill-destructor)))))))) | ||
| 270 | 303 | ||
| 271 | (define rsync-service-type | 304 | (define rsync-service-type |
| 272 | (service-type | 305 | (service-type |
