| 1 |
################## |
| 2 |
# Author: Konstantin Ryabitsev <[email protected]> |
| 3 |
# |
| 4 |
policy_module(grokmirror, 1.1.1) |
| 5 |
|
| 6 |
require { |
| 7 |
type gitosis_var_lib_t; |
| 8 |
type git_sys_content_t; |
| 9 |
type net_conf_t; |
| 10 |
type httpd_t; |
| 11 |
type ssh_home_t; |
| 12 |
type passwd_file_t; |
| 13 |
type postfix_etc_t; |
| 14 |
} |
| 15 |
|
| 16 |
################## |
| 17 |
# Declarations |
| 18 |
|
| 19 |
type grokmirror_t; |
| 20 |
type grokmirror_exec_t; |
| 21 |
init_daemon_domain(grokmirror_t, grokmirror_exec_t) |
| 22 |
|
| 23 |
type grokmirror_var_lib_t; |
| 24 |
files_type(grokmirror_var_lib_t) |
| 25 |
|
| 26 |
type grokmirror_log_t; |
| 27 |
logging_log_file(grokmirror_log_t) |
| 28 |
|
| 29 |
type grokmirror_var_run_t; |
| 30 |
files_pid_file(grokmirror_var_run_t) |
| 31 |
|
| 32 |
type grokmirror_tmpfs_t; |
| 33 |
files_tmpfs_file(grokmirror_tmpfs_t) |
| 34 |
|
| 35 |
gen_tunable(grokmirror_connect_ssh, false) |
| 36 |
gen_tunable(grokmirror_connect_all_unreserved, false) |
| 37 |
|
| 38 |
# Uncomment to put these domains into permissive mode |
| 39 |
permissive grokmirror_t; |
| 40 |
|
| 41 |
################## |
| 42 |
# Daemons policy |
| 43 |
|
| 44 |
domain_use_interactive_fds(grokmirror_t) |
| 45 |
files_read_etc_files(grokmirror_t) |
| 46 |
miscfiles_read_localization(grokmirror_t) |
| 47 |
|
| 48 |
# Logging |
| 49 |
append_files_pattern(grokmirror_t, grokmirror_log_t, grokmirror_log_t) |
| 50 |
create_files_pattern(grokmirror_t, grokmirror_log_t, grokmirror_log_t) |
| 51 |
setattr_files_pattern(grokmirror_t, grokmirror_log_t, grokmirror_log_t) |
| 52 |
logging_log_filetrans(grokmirror_t, grokmirror_log_t, { file dir }) |
| 53 |
logging_send_syslog_msg(grokmirror_t) |
| 54 |
|
| 55 |
# Allow managing anything grokmirror_var_lib_t |
| 56 |
manage_dirs_pattern(grokmirror_t, grokmirror_var_lib_t, grokmirror_var_lib_t) |
| 57 |
manage_files_pattern(grokmirror_t, grokmirror_var_lib_t, grokmirror_var_lib_t) |
| 58 |
manage_lnk_files_pattern(grokmirror_t, grokmirror_var_lib_t, grokmirror_var_lib_t) |
| 59 |
manage_sock_files_pattern(grokmirror_t, grokmirror_var_lib_t, grokmirror_var_lib_t) |
| 60 |
|
| 61 |
# Allow managing git repositories |
| 62 |
manage_files_pattern(grokmirror_t, gitosis_var_lib_t, gitosis_var_lib_t) |
| 63 |
manage_lnk_files_pattern(grokmirror_t, gitosis_var_lib_t, gitosis_var_lib_t) |
| 64 |
manage_dirs_pattern(grokmirror_t, gitosis_var_lib_t, gitosis_var_lib_t) |
| 65 |
manage_sock_files_pattern(grokmirror_t, gitosis_var_lib_t, gitosis_var_lib_t) |
| 66 |
|
| 67 |
manage_files_pattern(grokmirror_t, git_sys_content_t, git_sys_content_t) |
| 68 |
manage_lnk_files_pattern(grokmirror_t, git_sys_content_t, git_sys_content_t) |
| 69 |
manage_dirs_pattern(grokmirror_t, git_sys_content_t, git_sys_content_t) |
| 70 |
manage_sock_files_pattern(grokmirror_t, git_sys_content_t, git_sys_content_t) |
| 71 |
|
| 72 |
# Allow executing bin (for git, mostly) |
| 73 |
corecmd_exec_bin(grokmirror_t) |
| 74 |
libs_exec_ldconfig(grokmirror_t) |
| 75 |
|
| 76 |
# Allow managing httpd content in case the manifest is stored there |
| 77 |
apache_manage_sys_content(grokmirror_t) |
| 78 |
|
| 79 |
# git wants to access system state and other bits |
| 80 |
kernel_dontaudit_read_system_state(grokmirror_t) |
| 81 |
|
| 82 |
# Allow connecting to http, git |
| 83 |
corenet_tcp_connect_http_port(grokmirror_t) |
| 84 |
corenet_tcp_connect_git_port(grokmirror_t) |
| 85 |
corenet_tcp_bind_generic_node(grokmirror_t) |
| 86 |
corenet_tcp_sendrecv_generic_node(grokmirror_t) |
| 87 |
|
| 88 |
# git needs to dns-resolve |
| 89 |
sysnet_dns_name_resolve(grokmirror_t) |
| 90 |
|
| 91 |
# Allow reading .netrc files |
| 92 |
read_files_pattern(grokmirror_t, net_conf_t, net_conf_t) |
| 93 |
|
| 94 |
# Post-hooks can use grep, which requires execmem |
| 95 |
allow grokmirror_t self:process execmem; |
| 96 |
|
| 97 |
fs_getattr_tmpfs(grokmirror_t) |
| 98 |
manage_files_pattern(grokmirror_t, grokmirror_tmpfs_t, grokmirror_tmpfs_t) |
| 99 |
fs_tmpfs_filetrans(grokmirror_t, grokmirror_tmpfs_t, file) |
| 100 |
|
| 101 |
# Listener socket file |
| 102 |
manage_dirs_pattern(grokmirror_t, grokmirror_var_run_t, grokmirror_var_run_t) |
| 103 |
manage_files_pattern(grokmirror_t, grokmirror_var_run_t, grokmirror_var_run_t) |
| 104 |
manage_sock_files_pattern(grokmirror_t, grokmirror_var_run_t, grokmirror_var_run_t) |
| 105 |
files_pid_filetrans(grokmirror_t, grokmirror_var_run_t, { dir file sock_file }) |
| 106 |
|
| 107 |
# allow httpd to write to the listener socket |
| 108 |
allow httpd_t grokmirror_t:unix_stream_socket connectto; |
| 109 |
|
| 110 |
# Some bogus dontaudits |
| 111 |
# ssh tries to open /etc/mailname, which the postfix module labels oddly |
| 112 |
dontaudit grokmirror_t postfix_etc_t:file { getattr open read }; |
| 113 |
|
| 114 |
tunable_policy(`grokmirror_connect_all_unreserved',` |
| 115 |
corenet_sendrecv_all_client_packets(grokmirror_t) |
| 116 |
corenet_tcp_connect_all_unreserved_ports(grokmirror_t) |
| 117 |
') |
| 118 |
|
| 119 |
tunable_policy(`grokmirror_connect_ssh',` |
| 120 |
corenet_sendrecv_ssh_client_packets(grokmirror_t) |
| 121 |
corenet_tcp_connect_ssh_port(grokmirror_t) |
| 122 |
corenet_tcp_sendrecv_ssh_port(grokmirror_t) |
| 123 |
|
| 124 |
ssh_exec(grokmirror_t) |
| 125 |
ssh_read_user_home_files(grokmirror_t) |
| 126 |
|
| 127 |
# for the controlmaster socket |
| 128 |
manage_sock_files_pattern(grokmirror_t, ssh_home_t, ssh_home_t) |
| 129 |
allow grokmirror_t self:unix_stream_socket connectto; |
| 130 |
allow grokmirror_t passwd_file_t:file { getattr open read }; |
| 131 |
') |