diff options
| author | Chris Lemmer-Webber <cwebber@dustycloud.org> | 2021-07-06 22:03:19 +0200 |
|---|---|---|
| committer | Christopher Lemmer Webber <cwebber@dustycloud.org> | 2021-07-29 11:32:08 -0400 |
| commit | a7ac19851baab3fbcc40c4b2cf5b00a6ac9cd2f3 (patch) | |
| tree | 3731cb92eecc360ecc886b6cffb1153b4c5ab9a6 /gnu/build/activation.scm | |
| parent | 5a1ce6cf70fcd386e56a325efafd7d73ea6cdfcf (diff) | |
services: setuid: More configurable setuid support.
New record <setuid-program> with fields for setting the specific user
and group, as well as specifically selecting the setuid and setgid bits,
for a program within the setuid-program-service.
* gnu/services.scm (setuid-program-file-like-deprecated): New function.
(setuid-program-service-type): Make use of
setuid-program->activation-gexp. Adjust the extend property to handle
<setuid-program>.
* gnu/build/activation.scm (activate-setuid-programs): Update to expect a
<setuid-record> list for each program entry.
* gnu/system.scm: (operating-system-setuid-programs): Renamed to
%operating-system-setuid-programs and replace it with new procedure.
(operating-system-default-essential-services,
hurd-default-essential-services): Replace
operating-system-setuid-programs with
%operating-system-setuid-programs.
* gnu/system/setuid.scm: New file.
* doc/guix.texi (Setuid Programs): Document <setuid-program>.
Co-authored-by: Brice Waegeneire <brice@waegenei.re>
Diffstat (limited to 'gnu/build/activation.scm')
| -rw-r--r-- | gnu/build/activation.scm | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm index 2af1d44b5f2..9f6126023c0 100644 --- a/gnu/build/activation.scm +++ b/gnu/build/activation.scm | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net> | 6 | ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net> |
| 7 | ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net> | 7 | ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net> |
| 8 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> | 8 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> |
| 9 | ;;; Copyright © 2020 Christine Lemmer-Webber <cwebber@dustycloud.org> | ||
| 10 | ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re> | ||
| 9 | ;;; | 11 | ;;; |
| 10 | ;;; This file is part of GNU Guix. | 12 | ;;; This file is part of GNU Guix. |
| 11 | ;;; | 13 | ;;; |
| @@ -24,6 +26,7 @@ | |||
| 24 | 26 | ||
| 25 | (define-module (gnu build activation) | 27 | (define-module (gnu build activation) |
| 26 | #:use-module (gnu system accounts) | 28 | #:use-module (gnu system accounts) |
| 29 | #:use-module (gnu system setuid) | ||
| 27 | #:use-module (gnu build accounts) | 30 | #:use-module (gnu build accounts) |
| 28 | #:use-module (gnu build linux-boot) | 31 | #:use-module (gnu build linux-boot) |
| 29 | #:use-module (guix build utils) | 32 | #:use-module (guix build utils) |
| @@ -279,14 +282,17 @@ they already exist." | |||
| 279 | "/run/setuid-programs") | 282 | "/run/setuid-programs") |
| 280 | 283 | ||
| 281 | (define (activate-setuid-programs programs) | 284 | (define (activate-setuid-programs programs) |
| 282 | "Turn PROGRAMS, a list of file names, into setuid programs stored under | 285 | "Turn PROGRAMS, a list of file setuid-programs record, into setuid programs |
| 283 | %SETUID-DIRECTORY." | 286 | stored under %SETUID-DIRECTORY." |
| 284 | (define (make-setuid-program prog) | 287 | (define (make-setuid-program program setuid? setgid? uid gid) |
| 285 | (let ((target (string-append %setuid-directory | 288 | (let ((target (string-append %setuid-directory |
| 286 | "/" (basename prog)))) | 289 | "/" (basename program))) |
| 287 | (copy-file prog target) | 290 | (mode (+ #o0555 ; base permissions |
| 288 | (chown target 0 0) | 291 | (if setuid? #o4000 0) ; setuid bit |
| 289 | (chmod target #o4555))) | 292 | (if setgid? #o2000 0)))) ; setgid bit |
| 293 | (copy-file program target) | ||
| 294 | (chown target uid gid) | ||
| 295 | (chmod target mode))) | ||
| 290 | 296 | ||
| 291 | (format #t "setting up setuid programs in '~a'...~%" | 297 | (format #t "setting up setuid programs in '~a'...~%" |
| 292 | %setuid-directory) | 298 | %setuid-directory) |
| @@ -302,15 +308,27 @@ they already exist." | |||
| 302 | (for-each (lambda (program) | 308 | (for-each (lambda (program) |
| 303 | (catch 'system-error | 309 | (catch 'system-error |
| 304 | (lambda () | 310 | (lambda () |
| 305 | (make-setuid-program program)) | 311 | (let* ((program-name (setuid-program-program program)) |
| 312 | (setuid? (setuid-program-setuid? program)) | ||
| 313 | (setgid? (setuid-program-setgid? program)) | ||
| 314 | (user (setuid-program-user program)) | ||
| 315 | (group (setuid-program-group program)) | ||
| 316 | (uid (match user | ||
| 317 | ((? string?) (passwd:uid (getpwnam user))) | ||
| 318 | ((? integer?) user))) | ||
| 319 | (gid (match group | ||
| 320 | ((? string?) (group:gid (getgrnam group))) | ||
| 321 | ((? integer?) group)))) | ||
| 322 | (make-setuid-program program-name setuid? setgid? uid gid))) | ||
| 306 | (lambda args | 323 | (lambda args |
| 307 | ;; If we fail to create a setuid program, better keep going | 324 | ;; If we fail to create a setuid program, better keep going |
| 308 | ;; so that we don't leave %SETUID-DIRECTORY empty or | 325 | ;; so that we don't leave %SETUID-DIRECTORY empty or |
| 309 | ;; half-populated. This can happen if PROGRAMS contains | 326 | ;; half-populated. This can happen if PROGRAMS contains |
| 310 | ;; incorrect file names: <https://bugs.gnu.org/38800>. | 327 | ;; incorrect file names: <https://bugs.gnu.org/38800>. |
| 311 | (format (current-error-port) | 328 | (format (current-error-port) |
| 312 | "warning: failed to make '~a' setuid-root: ~a~%" | 329 | "warning: failed to make ~s setuid/setgid: ~a~%" |
| 313 | program (strerror (system-error-errno args)))))) | 330 | (setuid-program-program program) |
| 331 | (strerror (system-error-errno args)))))) | ||
| 314 | programs)) | 332 | programs)) |
| 315 | 333 | ||
| 316 | (define (activate-special-files special-files) | 334 | (define (activate-special-files special-files) |
