Skip to content

Commit 27a65fe

Browse files
committed
apache: allow nginx -t
nginx needs to be executable by system administrators to be able to run various actions, including the critical test option -t. This provides appropriate execution authority to do so. Signed-off-by: Antonio Enrico Russo <aerusso@aerusso.net>
1 parent 145d2c4 commit 27a65fe

File tree

4 files changed

+213
-3
lines changed

4 files changed

+213
-3
lines changed

policy/modules/admin/logrotate.te

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ optional_policy(`
150150

151151
optional_policy(`
152152
apache_read_config(logrotate_t)
153-
apache_domtrans(logrotate_t)
153+
apache_ctl_domtrans(logrotate_t)
154+
apache_ctl_domtrans_from_httpd(logrotate_t)
154155
apache_signull(logrotate_t)
155156
')
156157

policy/modules/services/apache.fc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ HOME_DIR/((www)|(web)|(public_html))(/.*)?/logs(/.*)? gen_context(system_u:obje
3939
/usr/.*\.cgi -- gen_context(system_u:object_r:httpd_sys_script_exec_t,s0)
4040

4141
/usr/bin/apache(2)? -- gen_context(system_u:object_r:httpd_exec_t,s0)
42-
/usr/bin/apache(2)?ctl -- gen_context(system_u:object_r:httpd_exec_t,s0)
42+
/usr/bin/apache(2)?ctl -- gen_context(system_u:object_r:httpd_ctl_exec_t,s0)
4343
/usr/bin/apache-ssl(2)? -- gen_context(system_u:object_r:httpd_exec_t,s0)
4444
/usr/bin/cgi-wrapper -- gen_context(system_u:object_r:httpd_exec_t,s0)
4545
/usr/bin/cherokee -- gen_context(system_u:object_r:httpd_exec_t,s0)
@@ -74,7 +74,7 @@ HOME_DIR/((www)|(web)|(public_html))(/.*)?/logs(/.*)? gen_context(system_u:obje
7474
/usr/libexec/httpd-ssl-pass-dialog -- gen_context(system_u:object_r:httpd_passwd_exec_t,s0)
7575

7676
/usr/sbin/apache(2)? -- gen_context(system_u:object_r:httpd_exec_t,s0)
77-
/usr/sbin/apache(2)?ctl -- gen_context(system_u:object_r:httpd_exec_t,s0)
77+
/usr/sbin/apache(2)?ctl -- gen_context(system_u:object_r:httpd_ctl_exec_t,s0)
7878
/usr/sbin/apache-ssl(2)? -- gen_context(system_u:object_r:httpd_exec_t,s0)
7979
/usr/sbin/cgi-wrapper -- gen_context(system_u:object_r:httpd_exec_t,s0)
8080
/usr/sbin/cherokee -- gen_context(system_u:object_r:httpd_exec_t,s0)

policy/modules/services/apache.if

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ template(`apache_role',`
134134
type httpd_user_content_t, httpd_user_htaccess_t;
135135
type httpd_user_script_t, httpd_user_script_exec_t;
136136
type httpd_user_ra_content_t, httpd_user_rw_content_t;
137+
attribute_role httpd_ctl_roles;
137138
')
138139

139140
role $4 types httpd_user_script_t;
@@ -156,6 +157,10 @@ template(`apache_role',`
156157
allow $2 httpd_user_script_exec_t:file { manage_file_perms relabel_file_perms };
157158
allow $2 httpd_user_script_exec_t:lnk_file { manage_lnk_file_perms relabel_lnk_file_perms };
158159

160+
roleattribute $4 httpd_ctl_roles;
161+
apache_ctl_domtrans($3)
162+
apache_ctl_domtrans_from_httpd($3)
163+
159164
userdom_user_home_dir_filetrans($2, httpd_user_content_t, dir, "public_html")
160165
userdom_user_home_dir_filetrans($2, httpd_user_content_t, dir, "web")
161166
userdom_user_home_dir_filetrans($2, httpd_user_content_t, dir, "www")
@@ -1416,6 +1421,7 @@ interface(`apache_admin',`
14161421
type httpd_runtime_t, httpd_passwd_t, httpd_suexec_t;
14171422
type httpd_suexec_tmp_t, httpd_tmp_t, httpd_rotatelogs_t;
14181423
type httpd_initrc_exec_t, httpd_keytab_t;
1424+
attribute_role httpd_ctl_roles;
14191425
')
14201426

14211427
allow $1 { httpd_script_domains httpd_t httpd_helper_t }:process { ptrace signal_perms };
@@ -1424,6 +1430,9 @@ interface(`apache_admin',`
14241430
ps_process_pattern($1, { httpd_rotatelogs_t httpd_suexec_t httpd_passwd_t })
14251431

14261432
init_startstop_service($1, $2, httpd_t, httpd_initrc_exec_t)
1433+
roleattribute $2 httpd_ctl_roles;
1434+
apache_ctl_domtrans($1)
1435+
apache_ctl_domtrans_from_httpd($1)
14271436

14281437
apache_manage_all_content($1)
14291438
miscfiles_manage_public_files($1)
@@ -1466,3 +1475,43 @@ interface(`apache_rw_runtime_files',`
14661475

14671476
allow $1 httpd_runtime_t:file rw_file_perms;
14681477
')
1478+
1479+
########################################
1480+
## <summary>
1481+
## Allow domain transitions to httpd_ctl_d
1482+
## from httpd_ctl_exec_t
1483+
## </summary>
1484+
## <param name="domain">
1485+
## <summary>
1486+
## Domain allowed to transition.
1487+
## </summary>
1488+
## </param>
1489+
#
1490+
interface(`apache_ctl_domtrans',`
1491+
gen_require(`
1492+
type httpd_ctl_t, httpd_ctl_exec_t;
1493+
')
1494+
1495+
corecmd_search_bin($1)
1496+
domtrans_pattern($1, httpd_ctl_exec_t, httpd_ctl_t)
1497+
')
1498+
1499+
########################################
1500+
## <summary>
1501+
## Allow domain transitions to httpd_ctl_d
1502+
## from httpd_exec_t
1503+
## </summary>
1504+
## <param name="domain">
1505+
## <summary>
1506+
## Domain allowed to transition.
1507+
## </summary>
1508+
## </param>
1509+
#
1510+
interface(`apache_ctl_domtrans_from_httpd',`
1511+
gen_require(`
1512+
type httpd_ctl_t, httpd_exec_t;
1513+
')
1514+
1515+
corecmd_search_bin($1)
1516+
domtrans_pattern($1, httpd_exec_t, httpd_ctl_t)
1517+
')

policy/modules/services/apache.te

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,19 @@ attribute httpd_script_domains;
269269
attribute_role httpd_helper_roles;
270270
roleattribute system_r httpd_helper_roles;
271271

272+
attribute_role httpd_ctl_roles;
273+
roleattribute system_r httpd_ctl_roles;
274+
272275
type httpd_t;
273276
type httpd_exec_t;
274277
init_daemon_domain(httpd_t, httpd_exec_t)
275278

279+
type httpd_ctl_t;
280+
type httpd_ctl_exec_t;
281+
application_domain(httpd_ctl_t, httpd_ctl_exec_t)
282+
allow httpd_ctl_t httpd_exec_t:file entrypoint;
283+
role httpd_ctl_roles types httpd_ctl_t;
284+
276285
type httpd_cache_t;
277286
files_type(httpd_cache_t)
278287

@@ -903,6 +912,157 @@ optional_policy(`
903912
sympa_read_var_files(httpd_t)
904913
')
905914

915+
########################################
916+
#
917+
# httpd_ctl local policy
918+
#
919+
920+
allow httpd_ctl_t self:capability { chown kill };
921+
# dac_override is required to read files owned by www-data, e.g., error.log
922+
allow httpd_ctl_t self:capability dac_override;
923+
dontaudit httpd_ctl_t self:capability net_admin;
924+
allow httpd_ctl_t httpd_t:process { getattr getcap getpgid getrlimit getsched getsession noatsecure rlimitinh setcap setkeycreate setpgid setsched setsockcreate share siginh signal_perms };
925+
userdom_use_inherited_user_terminals(httpd_ctl_t)
926+
927+
manage_dirs_pattern(httpd_ctl_t, httpd_cache_t, httpd_cache_t)
928+
mmap_manage_files_pattern(httpd_ctl_t, httpd_cache_t, httpd_cache_t)
929+
manage_lnk_files_pattern(httpd_ctl_t, httpd_cache_t, httpd_cache_t)
930+
files_var_filetrans(httpd_ctl_t, httpd_cache_t, dir)
931+
932+
allow httpd_ctl_t httpd_config_t:dir list_dir_perms;
933+
read_files_pattern(httpd_ctl_t, httpd_config_t, httpd_config_t)
934+
read_lnk_files_pattern(httpd_ctl_t, httpd_config_t, httpd_config_t)
935+
936+
allow httpd_ctl_t httpd_htaccess_type:file read_file_perms;
937+
938+
allow httpd_ctl_t httpd_ro_content:dir list_dir_perms;
939+
allow httpd_ctl_t httpd_ro_content:file { map read_file_perms };
940+
allow httpd_ctl_t httpd_ro_content:lnk_file read_lnk_file_perms;
941+
942+
allow httpd_ctl_t httpd_keytab_t:file read_file_perms;
943+
944+
allow httpd_ctl_t httpd_lock_t:dir manage_dir_perms;
945+
allow httpd_ctl_t httpd_lock_t:file manage_file_perms;
946+
files_lock_filetrans(httpd_ctl_t, httpd_lock_t, { file dir })
947+
948+
manage_dirs_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
949+
append_files_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
950+
create_files_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
951+
read_files_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
952+
setattr_files_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
953+
read_lnk_files_pattern(httpd_ctl_t, httpd_log_t, httpd_log_t)
954+
logging_log_filetrans(httpd_ctl_t, httpd_log_t, file)
955+
956+
allow httpd_ctl_t httpd_modules_t:dir list_dir_perms;
957+
mmap_exec_files_pattern(httpd_ctl_t, httpd_modules_t, httpd_modules_t)
958+
read_files_pattern(httpd_ctl_t, httpd_modules_t, httpd_modules_t)
959+
read_lnk_files_pattern(httpd_ctl_t, httpd_modules_t, httpd_modules_t)
960+
961+
allow httpd_ctl_t httpd_rotatelogs_t:process signal_perms;
962+
963+
manage_dirs_pattern(httpd_ctl_t, httpd_squirrelmail_t, httpd_squirrelmail_t)
964+
mmap_manage_files_pattern(httpd_ctl_t, httpd_squirrelmail_t, httpd_squirrelmail_t)
965+
manage_lnk_files_pattern(httpd_ctl_t, httpd_squirrelmail_t, httpd_squirrelmail_t)
966+
967+
allow httpd_ctl_t httpd_suexec_exec_t:file read_file_perms;
968+
969+
allow httpd_ctl_t httpd_sys_script_t:unix_stream_socket connectto;
970+
allow httpd_ctl_t httpd_sys_script_t:process signull;
971+
972+
973+
manage_dirs_pattern(httpd_ctl_t, httpd_tmp_t, httpd_tmp_t)
974+
manage_files_pattern(httpd_ctl_t, httpd_tmp_t, httpd_tmp_t)
975+
allow httpd_ctl_t httpd_tmp_t:file map;
976+
manage_sock_files_pattern(httpd_ctl_t, httpd_tmp_t, httpd_tmp_t)
977+
manage_lnk_files_pattern(httpd_ctl_t, httpd_tmp_t, httpd_tmp_t)
978+
files_tmp_filetrans(httpd_ctl_t, httpd_tmp_t, { file dir lnk_file sock_file })
979+
userdom_user_tmp_filetrans(httpd_ctl_t, httpd_tmp_t, dir)
980+
981+
manage_dirs_pattern(httpd_ctl_t, httpd_tmpfs_t, httpd_tmpfs_t)
982+
manage_files_pattern(httpd_ctl_t, httpd_tmpfs_t, httpd_tmpfs_t)
983+
manage_lnk_files_pattern(httpd_ctl_t, httpd_tmpfs_t, httpd_tmpfs_t)
984+
manage_fifo_files_pattern(httpd_ctl_t, httpd_tmpfs_t, httpd_tmpfs_t)
985+
manage_sock_files_pattern(httpd_ctl_t, httpd_tmpfs_t, httpd_tmpfs_t)
986+
fs_tmpfs_filetrans(httpd_ctl_t, httpd_tmpfs_t, { dir file lnk_file sock_file fifo_file })
987+
988+
manage_dirs_pattern(httpd_ctl_t, httpd_var_lib_t, httpd_var_lib_t)
989+
mmap_manage_files_pattern(httpd_ctl_t, httpd_var_lib_t, httpd_var_lib_t)
990+
manage_lnk_files_pattern(httpd_ctl_t, httpd_var_lib_t, httpd_var_lib_t)
991+
files_var_lib_filetrans(httpd_ctl_t, httpd_var_lib_t, { dir file })
992+
993+
setattr_dirs_pattern(httpd_ctl_t, httpd_runtime_t, httpd_runtime_t)
994+
manage_dirs_pattern(httpd_ctl_t, httpd_runtime_t, httpd_runtime_t)
995+
manage_files_pattern(httpd_ctl_t, httpd_runtime_t, httpd_runtime_t)
996+
manage_sock_files_pattern(httpd_ctl_t, httpd_runtime_t, httpd_runtime_t)
997+
files_runtime_filetrans(httpd_ctl_t, httpd_runtime_t, { file sock_file dir })
998+
999+
manage_dirs_pattern(httpd_ctl_t, squirrelmail_spool_t, squirrelmail_spool_t)
1000+
manage_files_pattern(httpd_ctl_t, squirrelmail_spool_t, squirrelmail_spool_t)
1001+
manage_lnk_files_pattern(httpd_ctl_t, squirrelmail_spool_t, squirrelmail_spool_t)
1002+
1003+
can_exec(httpd_ctl_t, httpd_exec_t)
1004+
1005+
kernel_read_kernel_sysctls(httpd_ctl_t)
1006+
kernel_read_vm_sysctls(httpd_ctl_t)
1007+
kernel_read_vm_overcommit_sysctl(httpd_ctl_t)
1008+
kernel_read_network_state(httpd_ctl_t)
1009+
kernel_read_system_state(httpd_ctl_t)
1010+
kernel_search_network_sysctl(httpd_ctl_t)
1011+
1012+
# nginx -t checks that it can bind to ports
1013+
corenet_tcp_bind_generic_node(httpd_ctl_t)
1014+
corenet_tcp_bind_http_port(httpd_ctl_t)
1015+
corenet_tcp_bind_http_cache_port(httpd_ctl_t)
1016+
optional_policy(`
1017+
tunable_policy(`httpd_mod_auth_ntlm_winbind',`
1018+
samba_domtrans_winbind_helper(httpd_ctl_t)
1019+
')
1020+
')
1021+
tunable_policy(`httpd_enable_ftp_server',`
1022+
corenet_tcp_bind_ftp_port(httpd_ctl_t)
1023+
')
1024+
1025+
dev_read_sysfs(httpd_ctl_t)
1026+
dev_read_rand(httpd_ctl_t)
1027+
dev_read_urand(httpd_ctl_t)
1028+
dev_rwx_zero(httpd_ctl_t)
1029+
1030+
domain_use_interactive_fds(httpd_ctl_t)
1031+
1032+
fs_getattr_all_fs(httpd_ctl_t)
1033+
fs_search_auto_mountpoints(httpd_ctl_t)
1034+
1035+
fs_read_iso9660_files(httpd_ctl_t)
1036+
1037+
files_dontaudit_getattr_all_runtime_files(httpd_ctl_t)
1038+
files_read_usr_files(httpd_ctl_t)
1039+
files_map_usr_files(httpd_ctl_t)
1040+
files_list_mnt(httpd_ctl_t)
1041+
files_search_spool(httpd_ctl_t)
1042+
files_read_var_symlinks(httpd_ctl_t)
1043+
files_read_var_lib_files(httpd_ctl_t)
1044+
files_search_home(httpd_ctl_t)
1045+
files_getattr_home_dir(httpd_ctl_t)
1046+
files_read_etc_runtime_files(httpd_ctl_t)
1047+
files_read_var_lib_symlinks(httpd_ctl_t)
1048+
files_map_etc_files(httpd_ctl_t)
1049+
1050+
auth_use_nsswitch(httpd_ctl_t)
1051+
1052+
init_rw_inherited_script_tmp_files(httpd_ctl_t)
1053+
1054+
libs_exec_lib_files(httpd_ctl_t)
1055+
1056+
logging_send_syslog_msg(httpd_ctl_t)
1057+
1058+
miscfiles_read_localization(httpd_ctl_t)
1059+
miscfiles_read_fonts(httpd_ctl_t)
1060+
miscfiles_read_public_files(httpd_ctl_t)
1061+
miscfiles_read_generic_certs(httpd_ctl_t)
1062+
miscfiles_read_generic_tls_privkey(httpd_ctl_t)
1063+
miscfiles_read_tetex_data(httpd_ctl_t)
1064+
1065+
seutil_dontaudit_search_config(httpd_ctl_t)
9061066

9071067
########################################
9081068
#

0 commit comments

Comments
 (0)