All things are difficult before they are easy. 没有软件的裸机是一具僵尸,没有硬件的软件是一个幽灵。2012,专注于Linux和C语言,关注自动化、性能测试,关注开源社区和开源测试工具、方法,尝试测试团队管理!

一个Apache访问权限问题(万恶的SELinux)

上一篇 / 下一篇  2011-06-25 10:57:20 / 个人分类:Linux

原文见我的博客:http://renyongjie668.blog.163.com/blog/static/160053120115942137511/

前几天,我搞了个准备一些git或者hg的repositories,为了网页访问的方便,我找到了其中一 个工具,Git自带的gitweb,但是当我把它作为CGI让apache调用它去发布/home/repo/pub目录时,不管怎样都访问不到 /home/repo/pub下面的东西,与此同时,在/var/www目录下的文件和目录,通过apache访问是正常的。而且,我不通过 apache,而直接运行gitweb.cgi程序,是可以访问/home/repo/pub目录下的git repository的。经过很长时间来排查原因,终于,明白了,万恶的selinux啊,权限问题。
其实,原因是我的机器SElinux处于开启状态,而SELinux默认的策略,apache的进程默认只能访问/var/www目录。
解决方法:
1. 关掉SELinux,并重启系统让其生效。
    修改/etc/selinux/config配置文件,设置SELINUX=disabled
    如果不想重启系统,使用命令:setenforce 0
    (也可在grub.conf修改kernel启动参数,添加selinux=0。当然需要重启系统)
2. 或者,修改SELinux的设置,让apache进程可以访问了我的目录。
     命令为:chcon –t var_t /home/repo;       chcon –R –t httpd_sys_content_t pub
当我们把SELinux的权限问题解决后,重启了Apache,就一切正常了,我的GitWeb就可以正常运行了。
我们在局域网中使用,网络环境相对安全,所以实际测试过程中一般都disable SELinux的。当然,为了安全也是可以开启的。


下面,再简单一下SELinux相关的知识吧。
查看selinux状态:/usr/bin/setstatus -v
查看和设置SELinux的当前工作模式 :getenforce/setenforce
查看和设置当前Policy(策略)的布尔值:getsebool/setsebool
查看文件(夹)、进程和用户的SELinx属性:ls -Z / ps -Z / id -Z
改变文件或文件夹的content标记:chcon

SELinux 全称是Security Enhanced Linux,由美国国家安全部(National Security Agency)领导开发的GPL项目,它拥有一个灵活而强制性的访问控制结构,旨在提高Linux系统的安全性,提供强健的安全保证,可防御未知攻击,据 称相当于B1级的军事安全性能。比MS NT所谓的C2等高得多。
应用SELinux后,可以减轻恶意攻击或恶意软件带来的灾难,并提供对机密性 和完整性有很高要求的信息很高的安全保障。 SELinux vs Linux 普通Linux安全和传统Unix系统一样,基于自主存取控制方法,即DAC,只要符合规定的权限,如规定的所有者和文件属性等,就可存取资源。在传统的 安全机制下,一些通过setuid/setgid的程序就产生了严重安全隐患,甚至一些错误的配置就可引发巨大的漏洞,被轻易攻击。
而SELinux则基于强制存取控制方法,即MAC,透过强制性的安全策略,应用程序或用户必须同时符合DAC及对应SELinux的MAC才能进行正常操作,否则都将遭到拒绝或失败,而这些问题将不会影响其他正常运作的程序和应用,并保持它们的安全系统结构。

Security-Enhanced Linux (SELinux) is a Linux feature that provides a mechanism for supporting access control security policies, including United States Department of Defense-style. mandatory access controls, through the use of Linux Security Modules (LSM) in the Linux kernel. It is not a Linux distribution, but rather a set of Kernel modifications and user-space tools that can be added to various Linux distributions. Its architecture strives to streamline the volume of software charged with security policy enforcement, which is closely aligned with the Trusted Computer System Evaluation Criteria (TCSEC, referred to as Orange Book) requirement for trusted computing base (TCB) minimization (applicable to evaluation classes B3 and A1) but is quite unrelated to the least privilege requirement (B2, B3, A1) as is often claimed.

参考资料:
http://hi.baidu.com/gtfcugb/blog/item/89381aeafd7de3d4d439c92e.html
http://www.eun.cn/?p=2488
http://en.wikipedia.org/wiki/Security-Enhanced_Linux

TAG: Apache apache Linux SElinux httpd SELinux linux

 

评分:0

我来说两句

smile665

smile665

Stay hungry, stay foolish. 得意之时谨记,一半命运还掌握在上帝手里;失意之时须知,一半命运还掌握在自己手里。

日历

« 2024-03-28  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 952719
  • 日志数: 220
  • 建立时间: 2008-11-06
  • 更新时间: 2012-10-06

RSS订阅

Open Toolbar