SELinux的apache模块有两个相似的布尔参数: httpd_read_user_content和httpd_enable_homedirs 。
手册页说,前者允许httpd读取用户内容 ,后者允许httpd读取主目录 。
他们有什么区别?
如果我想允许httpd读取/home/foo目录中的文件,我应该设置哪个参数为true?
httpd_read_user_content允许任何受限的Web服务器读取/home中的用户主目录中的文件。
httpd_enable_homedirs允许Apache使用它的UserDir指令(即,看起来像http://www.example.com/~username/ URL)。
如果您只是将域名映射到用户的目录,启用第一个httpd_read_user_content就足够了,但如果要使用Apache用户目录,则应同时启用这两个目录。
我自己做了一些研究后,使用sesearch命令研究了它们之间的差异:
$ sesearch --allow -s httpd_t -b httpd_read_user_content
find5个语义规则:
允许httpd_t user_home_dir_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t user_home_t:文件{ioctl读取getattrlocking打开};
允许httpd_t user_home_t:dir {ioctl读getattr锁search打开};
允许httpd_t home_root_t:dir {getattr search open};
允许httpd_t home_root_t:lnk_file {read getattr};
$ sesearch --allow -s httpd_t -b httpd_enable_homedirs
发现了15个语义规则:
允许httpd_t user_home_dir_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t user_home_dir_t:lnk_file {read getattr};
允许httpd_t autofs_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t cifs_t:file {ioctl read getattr lock open};
允许httpd_t cifs_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t cifs_t:lnk_file {read getattr};
允许httpd_t nfs_t:file {ioctl read getattr lock open};
允许httpd_t nfs_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t nfs_t:lnk_file {read getattr};
允许httpd_t user_home_t:文件{ioctl读取getattrlocking打开};
允许httpd_t user_home_t:dir {ioctl读getattr锁search打开};
允许httpd_t user_home_type:dir {getattr search open};
允许httpd_t user_home_type:lnk_file {read getattr};
允许httpd_t home_root_t:dir {ioctl读取getattrlockingsearch打开};
允许httpd_t home_root_t:lnk_file {read getattr};
http_read_user_content所有规则都包含在httpd_t -b httpd_enable_homedirs 。 也就是说,后者的范围比前者广泛。
正如Michael所说的,如果我们只想将文档根目录放在用户的主目录下,我们应该只启用第一个。