由于SELinux,httpd无法写入文件夹/文件


30

有谁知道哪个sebool允许对/ home / user / html的httpd写入访问权限?当我禁用SELinux时,echo 0 > /selinux/enforce我可以写,所以我的问题肯定与SELinux有关。我只是不知道哪一个是正确的方法而没有开一个大漏洞,而Google并没有太大的帮助。

#[/home]ls -Z
drwxr-x---. user       apache     unconfined_u:object_r:user_home_dir_t:s0 user

#sestatus -b
Policy booleans:
abrt_anon_write                             off
abrt_handle_event                           off
allow_console_login                         on
allow_cvs_read_shadow                       off
allow_daemons_dump_core                     on
allow_daemons_use_tcp_wrapper               off
allow_daemons_use_tty                       on
allow_domain_fd_use                         on
allow_execheap                              off
allow_execmem                               on
allow_execmod                               on
allow_execstack                             on
allow_ftpd_anon_write                       off
allow_ftpd_full_access                      off
allow_ftpd_use_cifs                         off
allow_ftpd_use_nfs                          off
allow_gssd_read_tmp                         on
allow_guest_exec_content                    off
allow_httpd_anon_write                      off
allow_httpd_mod_auth_ntlm_winbind           off
allow_httpd_mod_auth_pam                    off
allow_httpd_sys_script_anon_write           off
allow_java_execstack                        off
allow_kerberos                              on
allow_mount_anyfile                         on
allow_mplayer_execstack                     off
allow_nsplugin_execmem                      on
allow_polyinstantiation                     off
allow_postfix_local_write_mail_spool        on
allow_ptrace                                off
allow_rsync_anon_write                      off
allow_saslauthd_read_shadow                 off
allow_smbd_anon_write                       off
allow_ssh_keysign                           off
allow_staff_exec_content                    on
allow_sysadm_exec_content                   on
allow_unconfined_nsplugin_transition        off
allow_user_exec_content                     on
allow_user_mysql_connect                    off
allow_user_postgresql_connect               off
allow_write_xshm                            off
allow_xguest_exec_content                   off
allow_xserver_execmem                       off
allow_ypbind                                off
allow_zebra_write_config                    on
authlogin_radius                            off
cdrecord_read_content                       off
clamd_use_jit                               off
cobbler_anon_write                          off
cobbler_can_network_connect                 off
cobbler_use_cifs                            off
cobbler_use_nfs                             off
condor_domain_can_network_connect           off
cron_can_relabel                            off
dhcpc_exec_iptables                         off
domain_kernel_load_modules                  off
exim_can_connect_db                         off
exim_manage_user_files                      off
exim_read_user_files                        off
fcron_crond                                 off
fenced_can_network_connect                  off
fenced_can_ssh                              off
ftp_home_dir                                on
ftpd_connect_db                             off
ftpd_use_passive_mode                       off
git_cgit_read_gitosis_content               off
git_session_bind_all_unreserved_ports       off
git_system_enable_homedirs                  off
git_system_use_cifs                         off
git_system_use_nfs                          off
global_ssp                                  off
gpg_agent_env_file                          off
gpg_web_anon_write                          off
httpd_builtin_scripting                     on
httpd_can_check_spam                        off
httpd_can_network_connect                   off
httpd_can_network_connect_cobbler           off
httpd_can_network_connect_db                on
httpd_can_network_memcache                  off
httpd_can_network_relay                     off
httpd_can_sendmail                          on
httpd_dbus_avahi                            on
httpd_enable_cgi                            on
httpd_enable_ftp_server                     off
httpd_enable_homedirs                       on
httpd_execmem                               off
httpd_manage_ipa                            off
httpd_read_user_content                     off
httpd_setrlimit                             off
httpd_ssi_exec                              off
httpd_tmp_exec                              off
httpd_tty_comm                              on
httpd_unified                               on
httpd_use_cifs                              off
httpd_use_gpg                               off
httpd_use_nfs                               off
httpd_use_openstack                         off
icecast_connect_any                         off
init_upstart                                on
irssi_use_full_network                      off
logging_syslogd_can_sendmail                off
mmap_low_allowed                            off
mozilla_read_content                        off
mysql_connect_any                           off
named_write_master_zones                    off
ncftool_read_user_content                   off
nscd_use_shm                                on
nsplugin_can_network                        on
openvpn_enable_homedirs                     on
piranha_lvs_can_network_connect             off
pppd_can_insmod                             off
pppd_for_user                               off
privoxy_connect_any                         on
puppet_manage_all_files                     off
puppetmaster_use_db                         off
qemu_full_network                           on
qemu_use_cifs                               on
qemu_use_comm                               off
qemu_use_nfs                                on
qemu_use_usb                                on
racoon_read_shadow                          off
rgmanager_can_network_connect               off
rsync_client                                off
rsync_export_all_ro                         off
rsync_use_cifs                              off
rsync_use_nfs                               off
samba_create_home_dirs                      off
samba_domain_controller                     off
samba_enable_home_dirs                      off
samba_export_all_ro                         off
samba_export_all_rw                         off
samba_run_unconfined                        off
samba_share_fusefs                          off
samba_share_nfs                             off
sanlock_use_nfs                             off
sanlock_use_samba                           off
secure_mode                                 off
secure_mode_insmod                          off
secure_mode_policyload                      off
sepgsql_enable_users_ddl                    on
sepgsql_unconfined_dbadm                    on
sge_domain_can_network_connect              off
sge_use_nfs                                 off
smartmon_3ware                              off
spamassassin_can_network                    off
spamd_enable_home_dirs                      on
squid_connect_any                           on
squid_use_tproxy                            off
ssh_chroot_rw_homedirs                      off
ssh_sysadm_login                            off
telepathy_tcp_connect_generic_network_ports off
tftp_anon_write                             off
tor_bind_all_unreserved_ports               off
unconfined_login                            on
unconfined_mmap_zero_ignore                 off
unconfined_mozilla_plugin_transition        off
use_fusefs_home_dirs                        off
use_lpd_server                              off
use_nfs_home_dirs                           on
use_samba_home_dirs                         off
user_direct_dri                             on
user_direct_mouse                           off
user_ping                                   on
user_rw_noexattrfile                        on
user_setrlimit                              on
user_tcp_server                             off
user_ttyfile_stat                           off
varnishd_connect_any                        off
vbetool_mmap_zero_ignore                    off
virt_use_comm                               off
virt_use_fusefs                             off
virt_use_nfs                                off
virt_use_samba                              off
virt_use_sanlock                            off
virt_use_sysfs                              on
virt_use_usb                                on
virt_use_xserver                            off
webadm_manage_user_files                    off
webadm_read_user_files                      off
wine_mmap_zero_ignore                       off
xdm_exec_bootloader                         off
xdm_sysadm_login                            off
xen_use_nfs                                 off
xguest_connect_network                      on
xguest_mount_media                          on
xguest_use_bluetooth                        on
xserver_object_manager                      off


Answers:


32

他们都没有,至少不是一个人。您必须为目录结构提供的上下文httpd_sys_rw_content_t,或者为它们提供的上下文,public_content_rw_t并启用allow_httpd_anon_write和/或allow_httpd_sys_script_anon_write。有关httpd_selinux(8)详细信息,请参见手册页。


5
好吧,我跑了chcon -R -t httpd_sys_rw_content_t user,它奏效了。只是有点担心,因为我已替换掉user_home_dir_t了它的含义。
基督教徒

2
它替换了现有的上下文。但是,除非您运行严格的策略,否则这并不重要,因为用户进程在中运行unconfined_t,只要具有适当的* nix权限,用户进程就可以访问所有上下文。
伊格纳西奥·巴斯克斯

嗨Inacio。虽然我现在能够运行没有任何问题的网站,我无法通过FTP上传,除非我设置chconuser_home_dir_t。任何其他想法:)我正在使用vsftpd
基督教徒

1
运行restorecon命令,它现在正在工作:)
Christian

16
我运行了chcon -R -t httpd_sys_rw_content_t /path它并起作用了,然后semanage fcontext -a -t httpd_sys_rw_content_t "/path(/.*)?"根据Centos Documentation
DWils

9

尽管最好httpd_sys_rw_content_t在需要的位置标记文件和文件夹,但为完整起见httpd_unified,我想我要提到的是,您也可以将seboolean更改为1,以使SELinux忽略此特定的上下文要求,这比禁用SELinux更好。互联网上的许多人会建议。

从手册页:

可以将httpd配置为不根据上下文区分文件控件,即,标记为httpd上下文的所有文件都可以读取/写入/执行。将此布尔值设置为false允许您设置安全策略,以使一个httpd服务不会干扰另一个。

setsebool -P httpd_unified 0


0

您可以在redHat的selinux上找到非常好的文档,可以下载180页.pdf手册,但是处理selinux问题的最佳方法是打开终端并使用自动化工具进行键入。

尝试:

aureport -a(作为根)

然后重复引起问题的问题。您将很好地显示该问题以及可能要考虑解决的方法(在我的情况下,这是apache无法写入的文件夹)。

aureport启动报告程序,当出现问题时,它将为您提供多种选择。会说英语的人会清楚地解释它们。我花了几个小时解决selinux问题,然后在redhat文档中找到了这个小问题,并在30秒内解决了该问题。选择之一就是当场。

/ Len


-3
semanage permissive -a httpd_t

为我做了把戏


3
欢迎来到U&L SE。请您编辑您的答案以解释更多信息。那是怎么工作的?少量信息会很有用,特别是对于以后遇到您答案的其他人。
roaima

这只是为Apache关闭安全性。除非您在临时环境中工作,否则这是个坏主意。
gbtimmon
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.