1 |
commit: 5b564f3b243368edd0e083c78a99b059a10e80ed |
2 |
Author: Russell Coker <russell <AT> coker <DOT> com <DOT> au> |
3 |
AuthorDate: Fri Feb 18 01:21:52 2022 +0000 |
4 |
Commit: Jason Zaman <perfinion <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Feb 27 02:13:17 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/hardened-refpolicy.git/commit/?id=5b564f3b |
7 |
|
8 |
matrixd-synapse policy V3 |
9 |
|
10 |
Here's the latest version of the matrixd-synapse policy including all the |
11 |
suggestions from a year ago. |
12 |
|
13 |
Probably ready to merge. |
14 |
Signed-off-by: Russell Coker <russell <AT> coker.com.au> |
15 |
Signed-off-by: Jason Zaman <perfinion <AT> gentoo.org> |
16 |
|
17 |
policy/modules/kernel/corenetwork.te.in | 2 +- |
18 |
policy/modules/services/matrixd.fc | 4 + |
19 |
policy/modules/services/matrixd.if | 1 + |
20 |
policy/modules/services/matrixd.te | 126 ++++++++++++++++++++++++++++++++ |
21 |
4 files changed, 132 insertions(+), 1 deletion(-) |
22 |
|
23 |
diff --git a/policy/modules/kernel/corenetwork.te.in b/policy/modules/kernel/corenetwork.te.in |
24 |
index 547328be..077aacf0 100644 |
25 |
--- a/policy/modules/kernel/corenetwork.te.in |
26 |
+++ b/policy/modules/kernel/corenetwork.te.in |
27 |
@@ -156,7 +156,7 @@ network_port(hadoop_namenode, tcp,8020,s0) |
28 |
network_port(hddtemp, tcp,7634,s0) |
29 |
network_port(howl, tcp,5335,s0, udp,5353,s0) |
30 |
network_port(hplip, tcp,1782,s0, tcp,2207,s0, tcp,2208,s0, tcp, 8290,s0, tcp,50000,s0, tcp,50002,s0, tcp,8292,s0, tcp,9100,s0, tcp,9101,s0, tcp,9102,s0, tcp,9220,s0, tcp,9221,s0, tcp,9222,s0, tcp,9280,s0, tcp,9281,s0, tcp,9282,s0, tcp,9290,s0, tcp,9291,s0) |
31 |
-network_port(http, tcp,80,s0, tcp,443,s0, tcp,488,s0, tcp,8008,s0, tcp,8009,s0, tcp,8443,s0) #8443 is mod_nss default port |
32 |
+network_port(http, tcp,80,s0, tcp,443,s0, tcp,488,s0, tcp,8008,s0, tcp,8009,s0, tcp,8443,s0, tcp,8448,s0) #8443 is mod_nss default port |
33 |
network_port(http_cache, tcp,3128,s0, udp,3130,s0, tcp,8080,s0, tcp,8118,s0, tcp,10001-10010,s0) # 8118 is for privoxy |
34 |
network_port(i18n_input, tcp,9010,s0) |
35 |
network_port(imaze, tcp,5323,s0, udp,5323,s0) |
36 |
|
37 |
diff --git a/policy/modules/services/matrixd.fc b/policy/modules/services/matrixd.fc |
38 |
new file mode 100644 |
39 |
index 00000000..b59b1c75 |
40 |
--- /dev/null |
41 |
+++ b/policy/modules/services/matrixd.fc |
42 |
@@ -0,0 +1,4 @@ |
43 |
+/var/lib/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_var_t,s0) |
44 |
+/var/log/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_log_t,s0) |
45 |
+/etc/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_conf_t,s0) |
46 |
+/usr/bin/synctl -- gen_context(system_u:object_r:matrixd_exec_t,s0) |
47 |
|
48 |
diff --git a/policy/modules/services/matrixd.if b/policy/modules/services/matrixd.if |
49 |
new file mode 100644 |
50 |
index 00000000..f1eff5f0 |
51 |
--- /dev/null |
52 |
+++ b/policy/modules/services/matrixd.if |
53 |
@@ -0,0 +1 @@ |
54 |
+## <summary>Matrixd</summary> |
55 |
|
56 |
diff --git a/policy/modules/services/matrixd.te b/policy/modules/services/matrixd.te |
57 |
new file mode 100644 |
58 |
index 00000000..5c217678 |
59 |
--- /dev/null |
60 |
+++ b/policy/modules/services/matrixd.te |
61 |
@@ -0,0 +1,126 @@ |
62 |
+policy_module(matrixd, 1.0.0) |
63 |
+ |
64 |
+######################################## |
65 |
+# |
66 |
+# Declarations |
67 |
+# |
68 |
+ |
69 |
+## <desc> |
70 |
+## <p> |
71 |
+## Determine whether Matrixd is allowed to federate |
72 |
+## (bind all UDP ports and connect to all TCP ports). |
73 |
+## </p> |
74 |
+## </desc> |
75 |
+gen_tunable(matrix_allow_federation, true) |
76 |
+ |
77 |
+## <desc> |
78 |
+## <p> |
79 |
+## Determine whether Matrixd can connect to the Postgres database. |
80 |
+## </p> |
81 |
+## </desc> |
82 |
+gen_tunable(matrix_postgresql_connect, false) |
83 |
+ |
84 |
+ |
85 |
+type matrixd_t; |
86 |
+type matrixd_exec_t; |
87 |
+init_daemon_domain(matrixd_t, matrixd_exec_t) |
88 |
+ |
89 |
+type matrixd_var_t; |
90 |
+files_type(matrixd_var_t) |
91 |
+ |
92 |
+type matrixd_log_t; |
93 |
+logging_log_file(matrixd_log_t) |
94 |
+ |
95 |
+type matrixd_conf_t; |
96 |
+files_config_file(matrixd_conf_t) |
97 |
+ |
98 |
+type matrixd_tmp_t; |
99 |
+files_tmp_file(matrixd_tmp_t) |
100 |
+ |
101 |
+######################################## |
102 |
+# |
103 |
+# Local policy |
104 |
+# |
105 |
+ |
106 |
+allow matrixd_t self:fifo_file rw_file_perms; |
107 |
+allow matrixd_t self:tcp_socket create_stream_socket_perms; |
108 |
+allow matrixd_t self:netlink_route_socket r_netlink_socket_perms; |
109 |
+ |
110 |
+allow matrixd_t self:udp_socket create_socket_perms; |
111 |
+allow matrixd_t self:unix_dgram_socket create_socket_perms; |
112 |
+# execmem is needed for Python callbacks |
113 |
+# https://cffi.readthedocs.io/en/latest/using.html#callbacks |
114 |
+allow matrixd_t self:process execmem; |
115 |
+ |
116 |
+allow matrixd_t matrixd_tmp_t:file { manage_file_perms map }; |
117 |
+files_tmp_filetrans(matrixd_t, matrixd_tmp_t, file) |
118 |
+fs_tmpfs_filetrans(matrixd_t, matrixd_tmp_t, file) |
119 |
+ |
120 |
+manage_files_pattern(matrixd_t, matrixd_var_t, matrixd_var_t) |
121 |
+files_search_var_lib(matrixd_t) |
122 |
+allow matrixd_t matrixd_var_t:file map; |
123 |
+allow matrixd_t matrixd_var_t:dir manage_dir_perms; |
124 |
+ |
125 |
+logging_search_logs(matrixd_t) |
126 |
+manage_files_pattern(matrixd_t, matrixd_log_t, matrixd_log_t) |
127 |
+ |
128 |
+read_files_pattern(matrixd_t, matrixd_conf_t, matrixd_conf_t) |
129 |
+allow matrixd_t matrixd_conf_t:dir list_dir_perms; |
130 |
+ |
131 |
+kernel_read_system_state(matrixd_t) |
132 |
+kernel_read_vm_overcommit_sysctl(matrixd_t) |
133 |
+ |
134 |
+# The following in the systemd service file causes a domain transition when |
135 |
+# running python3: |
136 |
+# SELinuxContext=system_u:system_r:matrixd_t:s0 |
137 |
+corecmd_bin_entry_type(matrixd_t) |
138 |
+corecmd_exec_bin(matrixd_t) |
139 |
+corecmd_exec_shell(matrixd_t) |
140 |
+ |
141 |
+corenet_tcp_bind_generic_node(matrixd_t) |
142 |
+corenet_tcp_bind_http_port(matrixd_t) |
143 |
+corenet_tcp_connect_http_cache_port(matrixd_t) |
144 |
+corenet_tcp_connect_http_port(matrixd_t) |
145 |
+ |
146 |
+corenet_udp_bind_generic_node(matrixd_t) |
147 |
+corenet_udp_bind_generic_port(matrixd_t) |
148 |
+corenet_udp_bind_reserved_port(matrixd_t) |
149 |
+ |
150 |
+dev_read_urand(matrixd_t) |
151 |
+ |
152 |
+files_read_etc_files(matrixd_t) |
153 |
+files_read_etc_runtime_files(matrixd_t) |
154 |
+files_read_etc_symlinks(matrixd_t) |
155 |
+ |
156 |
+# for /usr/share/ca-certificates |
157 |
+files_read_usr_files(matrixd_t) |
158 |
+ |
159 |
+init_search_runtime(matrixd_t) |
160 |
+logging_send_syslog_msg(matrixd_t) |
161 |
+ |
162 |
+miscfiles_read_generic_tls_privkey(matrixd_t) |
163 |
+miscfiles_read_generic_certs(matrixd_t) |
164 |
+miscfiles_read_localization(matrixd_t) |
165 |
+ |
166 |
+sysnet_read_config(matrixd_t) |
167 |
+ |
168 |
+userdom_search_user_runtime_root(matrixd_t) |
169 |
+ |
170 |
+optional_policy(` |
171 |
+ apache_search_config(matrixd_t) |
172 |
+') |
173 |
+ |
174 |
+tunable_policy(`matrix_allow_federation',` |
175 |
+ corenet_tcp_connect_all_unreserved_ports(matrixd_t) |
176 |
+ corenet_tcp_connect_generic_port(matrixd_t) |
177 |
+ corenet_udp_bind_all_ports(matrixd_t) |
178 |
+', ` |
179 |
+ corenet_dontaudit_tcp_connect_all_ports(matrixd_t) |
180 |
+ corenet_dontaudit_udp_bind_all_ports(matrixd_t) |
181 |
+') |
182 |
+ |
183 |
+tunable_policy(`matrix_postgresql_connect',` |
184 |
+ postgresql_stream_connect(matrixd_t) |
185 |
+ postgresql_tcp_connect(matrixd_t) |
186 |
+') |
187 |
+ |