1 |
commit: 7312b188899d6ea718be9c885eb4a6f15ccd8aa7 |
2 |
Author: Kenton Groombridge <me <AT> concord <DOT> sh> |
3 |
AuthorDate: Thu Dec 23 15:55:53 2021 +0000 |
4 |
Commit: Jason Zaman <perfinion <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jan 30 01:12:42 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/hardened-refpolicy.git/commit/?id=7312b188 |
7 |
|
8 |
container: add policy for privileged containers |
9 |
|
10 |
Signed-off-by: Kenton Groombridge <me <AT> concord.sh> |
11 |
Signed-off-by: Jason Zaman <perfinion <AT> gentoo.org> |
12 |
|
13 |
policy/modules/services/container.te | 86 ++++++++++++++++++++++++++++++++++++ |
14 |
1 file changed, 86 insertions(+) |
15 |
|
16 |
diff --git a/policy/modules/services/container.te b/policy/modules/services/container.te |
17 |
index 7ab2765e..483cdcb2 100644 |
18 |
--- a/policy/modules/services/container.te |
19 |
+++ b/policy/modules/services/container.te |
20 |
@@ -22,6 +22,9 @@ attribute container_engine_user_domain; |
21 |
# containers which require network access |
22 |
attribute container_net_domain; |
23 |
|
24 |
+# containers considered privileged |
25 |
+attribute privileged_container_domain; |
26 |
+ |
27 |
attribute container_engine_exec_type; |
28 |
|
29 |
attribute container_mountpoint_type; |
30 |
@@ -43,6 +46,13 @@ ifdef(`enable_mls',` |
31 |
') |
32 |
mls_trusted_object(container_engine_t) |
33 |
|
34 |
+type spc_t, container_domain, container_net_domain, container_system_domain, privileged_container_domain; |
35 |
+domain_type(spc_t) |
36 |
+role system_r types spc_t; |
37 |
+ |
38 |
+type spc_user_t, container_domain, container_net_domain, container_user_domain, privileged_container_domain; |
39 |
+domain_type(spc_user_t) |
40 |
+ |
41 |
type container_unit_t; |
42 |
init_unit_file(container_unit_t) |
43 |
|
44 |
@@ -562,3 +572,79 @@ filetrans_pattern(container_engine_user_domain, container_data_home_t, container |
45 |
filetrans_pattern(container_engine_user_domain, container_data_home_t, container_ro_file_t, dir, "overlay2-images") |
46 |
filetrans_pattern(container_engine_user_domain, container_data_home_t, container_ro_file_t, dir, "overlay2-layers") |
47 |
filetrans_pattern(container_engine_user_domain, container_data_home_t, container_file_t, dir, "volumes") |
48 |
+ |
49 |
+######################################## |
50 |
+# |
51 |
+# Common privileged container local policy |
52 |
+# |
53 |
+ |
54 |
+allow privileged_container_domain container_file_t:file entrypoint; |
55 |
+allow privileged_container_domain container_ro_file_t:file entrypoint; |
56 |
+allow privileged_container_domain container_var_lib_t:file entrypoint; |
57 |
+ |
58 |
+optional_policy(` |
59 |
+ systemd_dbus_chat_machined(privileged_container_domain) |
60 |
+ systemd_dbus_chat_logind(privileged_container_domain) |
61 |
+') |
62 |
+ |
63 |
+######################################## |
64 |
+# |
65 |
+# spc local policy |
66 |
+# |
67 |
+# spc_t is the default type for containers created |
68 |
+# with the --privileged (or similar) argument |
69 |
+# |
70 |
+ |
71 |
+# Containers run from an engine with the --privileged argument are not |
72 |
+# restricted by the engine. One of these restrictions is a manual |
73 |
+# transition to the default context for containers, usually container_t. |
74 |
+# Instead of performing a manual transition when creating a restricted |
75 |
+# container (default), we do an automatic transition to spc_t when |
76 |
+# restrictions are disabled. |
77 |
+domtrans_pattern(container_engine_system_domain, container_file_t, spc_t) |
78 |
+domtrans_pattern(container_engine_system_domain, container_ro_file_t, spc_t) |
79 |
+domtrans_pattern(container_engine_system_domain, container_var_lib_t, spc_t) |
80 |
+ |
81 |
+allow container_engine_system_domain spc_t:process { setsched signal_perms }; |
82 |
+ |
83 |
+allow spc_t container_engine_system_domain:fifo_file rw_fifo_file_perms; |
84 |
+ |
85 |
+init_dbus_chat(spc_t) |
86 |
+ |
87 |
+optional_policy(` |
88 |
+ dbus_system_bus_client(spc_t) |
89 |
+ dbus_all_session_bus_client(spc_t) |
90 |
+') |
91 |
+ |
92 |
+optional_policy(` |
93 |
+# If unconfined domains are enabled, spc is also unconfined |
94 |
+ unconfined_domain_noaudit(spc_t) |
95 |
+ domain_ptrace_all_domains(spc_t) |
96 |
+') |
97 |
+ |
98 |
+######################################## |
99 |
+# |
100 |
+# spc user local policy |
101 |
+# |
102 |
+ |
103 |
+# Similar to above, automatically transition to spc_user_t when a |
104 |
+# container engine runs a container with the --privileged argument |
105 |
+domtrans_pattern(container_engine_user_domain, container_file_t, spc_user_t) |
106 |
+domtrans_pattern(container_engine_user_domain, container_ro_file_t, spc_user_t) |
107 |
+domtrans_pattern(container_engine_user_domain, container_var_lib_t, spc_user_t) |
108 |
+fs_fusefs_domtrans(container_engine_user_domain, spc_user_t) |
109 |
+ |
110 |
+allow container_engine_user_domain spc_user_t:process { setsched signal_perms }; |
111 |
+ |
112 |
+allow spc_user_t container_engine_user_domain:fifo_file rw_fifo_file_perms; |
113 |
+ |
114 |
+optional_policy(` |
115 |
+ dbus_system_bus_client(spc_user_t) |
116 |
+ dbus_all_session_bus_client(spc_user_t) |
117 |
+') |
118 |
+ |
119 |
+optional_policy(` |
120 |
+ # If unconfined domains are enabled, spc is also unconfined |
121 |
+ unconfined_domain_noaudit(spc_user_t) |
122 |
+ domain_ptrace_all_domains(spc_user_t) |
123 |
+') |