diff options
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/system.scm | 16 | ||||
| -rw-r--r-- | gnu/tests/base.scm | 121 |
2 files changed, 130 insertions, 7 deletions
diff --git a/gnu/system.scm b/gnu/system.scm index 44f93f91d17..c19730b331e 100644 --- a/gnu/system.scm +++ b/gnu/system.scm | |||
| @@ -809,6 +809,11 @@ bookkeeping." | |||
| 809 | %shepherd-root-service | 809 | %shepherd-root-service |
| 810 | 810 | ||
| 811 | (pam-root-service (operating-system-pam-services os)) | 811 | (pam-root-service (operating-system-pam-services os)) |
| 812 | ;; Make sure that privileged-programs activation script | ||
| 813 | ;; runs after accounts are created | ||
| 814 | (service privileged-program-service-type | ||
| 815 | (append (operating-system-privileged-programs os) | ||
| 816 | (operating-system-setuid-programs os))) | ||
| 812 | (account-service (append (operating-system-accounts os) | 817 | (account-service (append (operating-system-accounts os) |
| 813 | (operating-system-groups os)) | 818 | (operating-system-groups os)) |
| 814 | (operating-system-skeletons os)) | 819 | (operating-system-skeletons os)) |
| @@ -826,9 +831,6 @@ bookkeeping." | |||
| 826 | (operating-system-environment-variables os)) | 831 | (operating-system-environment-variables os)) |
| 827 | (service host-name-service-type host-name) | 832 | (service host-name-service-type host-name) |
| 828 | procs root-fs | 833 | procs root-fs |
| 829 | (service privileged-program-service-type | ||
| 830 | (append (operating-system-privileged-programs os) | ||
| 831 | (operating-system-setuid-programs os))) | ||
| 832 | (service profile-service-type | 834 | (service profile-service-type |
| 833 | (operating-system-packages os)) | 835 | (operating-system-packages os)) |
| 834 | boot-fs non-boot-fs | 836 | boot-fs non-boot-fs |
| @@ -850,6 +852,11 @@ bookkeeping." | |||
| 850 | (service shepherd-root-service-type) | 852 | (service shepherd-root-service-type) |
| 851 | 853 | ||
| 852 | (service user-processes-service-type) | 854 | (service user-processes-service-type) |
| 855 | ;; Make sure that privileged-programs activation script | ||
| 856 | ;; runs after accounts are created | ||
| 857 | (service privileged-program-service-type | ||
| 858 | (append (operating-system-privileged-programs os) | ||
| 859 | (operating-system-setuid-programs os))) | ||
| 853 | (account-service (append (operating-system-accounts os) | 860 | (account-service (append (operating-system-accounts os) |
| 854 | (operating-system-groups os)) | 861 | (operating-system-groups os)) |
| 855 | (operating-system-skeletons os)) | 862 | (operating-system-skeletons os)) |
| @@ -866,9 +873,6 @@ bookkeeping." | |||
| 866 | (list `("hosts" ,hosts-file))) | 873 | (list `("hosts" ,hosts-file))) |
| 867 | (service hosts-service-type | 874 | (service hosts-service-type |
| 868 | (local-host-entries host-name))) | 875 | (local-host-entries host-name))) |
| 869 | (service privileged-program-service-type | ||
| 870 | (append (operating-system-privileged-programs os) | ||
| 871 | (operating-system-setuid-programs os))) | ||
| 872 | (service profile-service-type (operating-system-packages os))))) | 876 | (service profile-service-type (operating-system-packages os))))) |
| 873 | 877 | ||
| 874 | (define* (operating-system-services os) | 878 | (define* (operating-system-services os) |
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)))) | ||
