diff options
| author | Dariqq <dariqq@posteo.net> | 2024-10-18 13:21:22 +0000 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2024-10-24 14:50:09 +0200 |
| commit | cc67a0b71d4a7d98a3732c3edf2eb340c2799697 (patch) | |
| tree | e21eb6eff0a4355df8c426fa13991f4d0855086c /gnu/tests | |
| parent | 952682fca61d73ee52a086e552e3985c7f539fde (diff) | |
gnu: system: Privilege programs after creating accounts.
Ensure that users and groups are already created when the privileging script
runs. The order these scripts appear in the folded activation-service depends
on the order these services are instantiated in the operating-system.
Fixes <https://issues.guix.gnu.org/73680>.
* gnu/system.scm (operating-system-default-essential-services): Move
privileged-program-service above account-service.
(hurd-default-essential-services): Likewise.
* gnu/tests/base.scm (%activation-os): New variable.
(run-activation-test): New procedure.
(%test-activation): New variable.
Change-Id: I59a191c5519475f256e81bdf2dc4cb01b96c31fe
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/base.scm | 121 |
1 files changed, 120 insertions, 1 deletions
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm index e1a676ecd44..9430cbee12f 100644 --- a/gnu/tests/base.scm +++ b/gnu/tests/base.scm | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> | 3 | ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> |
| 4 | ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 4 | ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 5 | ;;; Copyright © 2022 Marius Bakke <marius@gnu.org> | 5 | ;;; Copyright © 2022 Marius Bakke <marius@gnu.org> |
| 6 | ;;; Copyright © 2024 Dariqq <dariqq@posteo.net> | ||
| 6 | ;;; | 7 | ;;; |
| 7 | ;;; This file is part of GNU Guix. | 8 | ;;; This file is part of GNU Guix. |
| 8 | ;;; | 9 | ;;; |
| @@ -24,6 +25,7 @@ | |||
| 24 | #:use-module (gnu image) | 25 | #:use-module (gnu image) |
| 25 | #:use-module (gnu system) | 26 | #:use-module (gnu system) |
| 26 | #:autoload (gnu system image) (system-image) | 27 | #:autoload (gnu system image) (system-image) |
| 28 | #:use-module (gnu system privilege) | ||
| 27 | #:use-module (gnu system shadow) | 29 | #:use-module (gnu system shadow) |
| 28 | #:use-module (gnu system nss) | 30 | #:use-module (gnu system nss) |
| 29 | #:use-module (gnu system vm) | 31 | #:use-module (gnu system vm) |
| @@ -60,7 +62,8 @@ | |||
| 60 | %test-root-unmount | 62 | %test-root-unmount |
| 61 | %test-cleanup | 63 | %test-cleanup |
| 62 | %test-mcron | 64 | %test-mcron |
| 63 | %test-nss-mdns)) | 65 | %test-nss-mdns |
| 66 | %test-activation)) | ||
| 64 | 67 | ||
| 65 | (define %simple-os | 68 | (define %simple-os |
| 66 | (simple-operating-system)) | 69 | (simple-operating-system)) |
| @@ -1105,3 +1108,119 @@ non-ASCII names from /tmp.") | |||
| 1105 | "Test Avahi's multicast-DNS implementation, and in particular, test its | 1108 | "Test Avahi's multicast-DNS implementation, and in particular, test its |
| 1106 | glibc name service switch (NSS) module.") | 1109 | glibc name service switch (NSS) module.") |
| 1107 | (value (run-nss-mdns-test)))) | 1110 | (value (run-nss-mdns-test)))) |
| 1111 | |||
| 1112 | |||
| 1113 | ;;; | ||
| 1114 | ;;; Activation: Order of activation scripts | ||
| 1115 | ;;; Create accounts before running scripts using them | ||
| 1116 | |||
| 1117 | (define %activation-os | ||
| 1118 | ;; System with a new user/group, a setuid/setgid binary and an activation script | ||
| 1119 | (let* ((%hello-accounts | ||
| 1120 | (list (user-group (name "hello") (system? #t)) | ||
| 1121 | (user-account | ||
| 1122 | (name "hello") | ||
| 1123 | (group "hello") | ||
| 1124 | (system? #t) | ||
| 1125 | (comment "") | ||
| 1126 | (home-directory "/var/empty")))) | ||
| 1127 | (%hello-privileged | ||
| 1128 | (list | ||
| 1129 | (privileged-program | ||
| 1130 | (program (file-append hello "/bin/hello")) | ||
| 1131 | (setuid? #t) | ||
| 1132 | (setgid? #t) | ||
| 1133 | (user "hello") | ||
| 1134 | (group "hello")))) | ||
| 1135 | (%hello-activation | ||
| 1136 | (with-imported-modules (source-module-closure | ||
| 1137 | '((gnu build activation))) | ||
| 1138 | #~(begin | ||
| 1139 | (use-modules (gnu build activation)) | ||
| 1140 | |||
| 1141 | (let ((user (getpwnam "hello"))) | ||
| 1142 | (mkdir-p/perms "/run/hello" user #o755))))) | ||
| 1143 | |||
| 1144 | (hello-service-type | ||
| 1145 | (service-type | ||
| 1146 | (name 'hello) | ||
| 1147 | (extensions | ||
| 1148 | (list (service-extension account-service-type | ||
| 1149 | (const %hello-accounts)) | ||
| 1150 | (service-extension activation-service-type | ||
| 1151 | (const %hello-activation)) | ||
| 1152 | (service-extension privileged-program-service-type | ||
| 1153 | (const %hello-privileged)))) | ||
| 1154 | (default-value #f) | ||
| 1155 | (description "")))) | ||
| 1156 | |||
| 1157 | (operating-system | ||
| 1158 | (inherit %simple-os) | ||
| 1159 | (services | ||
| 1160 | (cons* (service hello-service-type) | ||
| 1161 | (operating-system-user-services | ||
| 1162 | %simple-os)))))) | ||
| 1163 | |||
| 1164 | (define (run-activation-test name) | ||
| 1165 | (define os | ||
| 1166 | (marionette-operating-system | ||
| 1167 | %activation-os)) | ||
| 1168 | |||
| 1169 | (define test | ||
| 1170 | (with-imported-modules '((gnu build marionette)) | ||
| 1171 | #~(begin | ||
| 1172 | (use-modules (gnu build marionette) | ||
| 1173 | (srfi srfi-64)) | ||
| 1174 | |||
| 1175 | (define marionette | ||
| 1176 | (make-marionette (list #$(virtual-machine os)))) | ||
| 1177 | |||
| 1178 | (test-runner-current (system-test-runner #$output)) | ||
| 1179 | (test-begin "activation") | ||
| 1180 | |||
| 1181 | (test-assert "directory exists" | ||
| 1182 | (marionette-eval | ||
| 1183 | '(file-exists? "/run/hello") | ||
| 1184 | marionette)) | ||
| 1185 | |||
| 1186 | (test-assert "directory correct permissions and owner" | ||
| 1187 | (marionette-eval | ||
| 1188 | '(let ((dir (stat "/run/hello")) | ||
| 1189 | (user (getpwnam "hello"))) | ||
| 1190 | (and (eqv? (stat:uid dir) | ||
| 1191 | (passwd:uid user)) | ||
| 1192 | (eqv? (stat:gid dir) | ||
| 1193 | (passwd:gid user)) | ||
| 1194 | (= (stat:perms dir) | ||
| 1195 | #o0755))) | ||
| 1196 | marionette)) | ||
| 1197 | |||
| 1198 | (test-assert "privileged-program exists" | ||
| 1199 | (marionette-eval | ||
| 1200 | '(file-exists? "/run/privileged/bin/hello") | ||
| 1201 | marionette)) | ||
| 1202 | |||
| 1203 | (test-assert "privileged-program correct permissions and owner" | ||
| 1204 | (marionette-eval | ||
| 1205 | '(let ((binary (stat "/run/privileged/bin/hello")) | ||
| 1206 | (user (getpwnam "hello")) | ||
| 1207 | (group (getgrnam "hello"))) | ||
| 1208 | (and (eqv? (stat:uid binary) | ||
| 1209 | (passwd:uid user)) | ||
| 1210 | (eqv? (stat:gid binary) | ||
| 1211 | (group:gid group)) | ||
| 1212 | (= (stat:perms binary) | ||
| 1213 | (+ #o0555 ;; base | ||
| 1214 | #o4000 ;; setuid | ||
| 1215 | #o2000)))) ;; setgid | ||
| 1216 | marionette)) | ||
| 1217 | |||
| 1218 | (test-end)))) | ||
| 1219 | |||
| 1220 | (gexp->derivation name test)) | ||
| 1221 | |||
| 1222 | (define %test-activation | ||
| 1223 | (system-test | ||
| 1224 | (name "activation") | ||
| 1225 | (description "Test that activation scripts are run in the correct order") | ||
| 1226 | (value (run-activation-test name)))) | ||
