-
Notifications
You must be signed in to change notification settings - Fork 0
/
cicap.te
219 lines (166 loc) · 8.44 KB
/
cicap.te
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
policy_module(cicap, 20210713.1.4)
require {
type antivirus_t;
type antivirus_var_run_t;
type init_t;
type logrotate_t;
type rpm_script_t;
type setfiles_t;
type tmp_t;
type setroubleshootd_t;
type system_cronjob_t;
type systemd_tmpfiles_t;
type unconfined_t;
type unconfined_service_t;
class udp_socket { connect create getattr read setopt write }; # clamd UDP
class tcp_socket { accept bind connect create getattr listen name_bind read setopt write }; # clamd TCP and c-icap TCP
class fifo_file { open read write }; # clamd.sock
# class capability net_admin;
}
type cicap_t;
type cicap_exec_t;
type cicap_port_t;
type cicap_bin_t;
type cicap_conf_t;
type cicap_log_t;
type cicap_tmp_t;
type cicap_var_run_t;
define(`cicap_all_types',`{ cicap_t cicap_exec_t cicap_bin_t cicap_conf_t cicap_log_t cicap_tmp_t cicap_var_run_t }')
corenet_port(cicap_port_t)
init_daemon_domain(cicap_t, cicap_exec_t)
filetrans_pattern(cicap_t, tmp_t, cicap_tmp_t, file) # make our files in /var/tmp our own.
#permissive cicap_t;
## DEBUGGING:
# echo "XX0"; make -f /usr/share/selinux/devel/Makefile
# echo "XX1"; semanage port -d -t cicap_port_t -p tcp 1344; semodule -r cicap
# echo "XX2"; semodule -i /root/selinux/cicap/cicap.pp; semanage port -a -t cicap_port_t -p tcp 1344; restorecon -vR /etc/ /run/ /tmp/ /usr/ /var/log/ /var/run/ /var/tmp/
# echo "XX3"; service c-icap-server stop; rm -f /var/log/audit/audit.log; service auditd restart; service c-icap-server start
# echo "XX4"; audit2allow -Ri /var/log/audit/audit.log >/root/x; vi /root/x
##
# filesystems
fs_associate(cicap_bin_t)
fs_associate(cicap_conf_t)
fs_associate(cicap_exec_t)
fs_associate(cicap_log_t)
fs_associate(cicap_tmp_t)
fs_associate(cicap_var_run_t)
fs_associate_tmpfs(cicap_var_run_t)
# clamdaccess via tcp_socket
allow cicap_t self:tcp_socket { accept bind create getattr listen read setopt write };
sssd_read_public_files(cicap_t)
sssd_search_lib(cicap_t)
fs_exec_tmpfs_files(cicap_t)
fs_getattr_tmpfs(cicap_t)
fs_manage_tmpfs_dirs(cicap_t)
fs_manage_tmpfs_files(cicap_t)
# c-icap.sock/ctl/pid
manage_fifo_files_pattern(cicap_t, cicap_var_run_t, cicap_var_run_t)
## perms for clamav/clamd via fifo_file / socket
auth_read_passwd_file(cicap_t)
dbus_system_bus_client(cicap_t)
sssd_stream_connect(cicap_t)
allow antivirus_t cicap_tmp_t:file { getattr open read };
fs_associate_tmpfs(antivirus_var_run_t)
search_dirs_pattern(cicap_t, antivirus_var_run_t, antivirus_var_run_t)
getattr_files_pattern(cicap_t, antivirus_var_run_t, antivirus_var_run_t)
read_files_pattern(cicap_t, antivirus_var_run_t, antivirus_var_run_t)
write_sock_files_pattern(cicap_t, antivirus_var_run_t, antivirus_var_run_t)
antivirus_stream_connect(cicap_t)
## cicap_t defaults
search_dirs_pattern(cicap_t, cicap_conf_t, cicap_conf_t)
read_files_pattern(cicap_t, cicap_conf_t, cicap_conf_t)
manage_files_pattern(cicap_t, cicap_log_t, cicap_log_t)
rw_dirs_pattern(cicap_t, cicap_tmp_t, cicap_tmp_t)
manage_dirs_pattern(cicap_t, cicap_tmp_t, cicap_tmp_t)
manage_files_pattern(cicap_t, cicap_tmp_t, cicap_tmp_t)
manage_files_pattern(cicap_t, cicap_var_run_t, cicap_var_run_t)
getattr_dirs_pattern(cicap_t, var_run_t, var_run_t)
search_dirs_pattern(cicap_t, var_run_t, var_run_t)
read_fifo_files_pattern(cicap_t, var_run_t, var_run_t)
create_fifo_files_pattern(cicap_t, var_run_t, var_run_t)
manage_files_pattern(cicap_t, var_run_t, var_run_t)
files_rw_pid_dirs(cicap_t)
manage_fifo_files_pattern(cicap_t, cicap_var_run_t, cicap_var_run_t)
# network perms
allow cicap_t cicap_port_t:tcp_socket { accept bind connect create getattr listen name_bind read setopt write };
allow cicap_t cicap_port_t:udp_socket { connect create getattr read setopt write };
allow cicap_t self:udp_socket { connect create getattr read setopt write };
corenet_tcp_bind_generic_node(cicap_t)
corenet_tcp_connect_clamd_port(cicap_t)
# other perms
sysnet_read_config(cicap_t)
# sys admin and service perms
## setroubleshootd_t
getattr_dirs_pattern(setroubleshootd_t, cicap_all_types, cicap_all_types)
search_dirs_pattern(setroubleshootd_t, cicap_all_types, cicap_all_types)
getattr_files_pattern(setroubleshootd_t, cicap_all_types, cicap_all_types)
read_files_pattern(setroubleshootd_t, cicap_all_types, cicap_all_types)
## rpm_script_t
getattr_dirs_pattern(rpm_script_t, cicap_all_types, cicap_all_types)
search_dirs_pattern(rpm_script_t, cicap_all_types, cicap_all_types)
getattr_files_pattern(rpm_script_t, cicap_all_types, cicap_all_types)
## init_t
manage_dirs_pattern(init_t, cicap_all_types, cicap_all_types)
manage_files_pattern(init_t, cicap_all_types, cicap_all_types)
manage_lnk_files_pattern(init_t, cicap_all_types, cicap_all_types)
## setfiles_t (ie. restorecon)
list_dirs_pattern(setfiles_t, cicap_all_types, cicap_all_types)
# relabelfrom:
relabelfrom_dirs_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelfrom_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelfrom_fifo_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelfrom_lnk_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelfrom_sock_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
# relabelto:
relabelto_dirs_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelto_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelto_fifo_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelto_lnk_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
relabelto_sock_files_pattern(setfiles_t, cicap_all_types, cicap_all_types)
## unconfined_t
allow unconfined_t cicap_all_types:{dir file} { relabelfrom relabelto };
manage_dirs_pattern(unconfined_t, cicap_all_types, cicap_all_types)
exec_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
manage_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
manage_lnk_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
# relabelfrom:
relabelfrom_dirs_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelfrom_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelfrom_fifo_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelfrom_lnk_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelfrom_sock_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
# relabelto:
relabelto_dirs_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelto_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelto_fifo_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelto_lnk_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
relabelto_sock_files_pattern(unconfined_t, cicap_all_types, cicap_all_types)
## unconfined_service_t
manage_dirs_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
exec_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
manage_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
manage_lnk_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
# relabelfrom:
relabelfrom_dirs_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelfrom_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelfrom_fifo_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelfrom_lnk_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelfrom_sock_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
# relabelto:
relabelto_dirs_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelto_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelto_fifo_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelto_lnk_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
relabelto_sock_files_pattern(unconfined_service_t, cicap_all_types, cicap_all_types)
## systemd_tmpfiles_t does see our files in /tmp, too.
getattr_dirs_pattern(systemd_tmpfiles_t, cicap_tmp_t, cicap_tmp_t)
search_dirs_pattern(systemd_tmpfiles_t, cicap_tmp_t, cicap_tmp_t)
manage_dirs_pattern(systemd_tmpfiles_t, cicap_tmp_t, cicap_tmp_t)
manage_files_pattern(systemd_tmpfiles_t, cicap_tmp_t, cicap_tmp_t)
## logrotate_t
manage_dirs_pattern(logrotate_t, cicap_log_t, cicap_log_t)
manage_files_pattern(logrotate_t, cicap_log_t, cicap_log_t)
## system_cronjob_t
manage_dirs_pattern(system_cronjob_t, cicap_all_types, cicap_all_types)
manage_files_pattern(system_cronjob_t, cicap_all_types, cicap_all_types)
manage_fifo_files_pattern(system_cronjob_t, cicap_all_types, cicap_all_types)