LazyDreamy

관리자 | 글쓰기

LazyDreamy » Search » Results » Articles

selinux와 관련된 글 4개

  1. 2009/09/23 SeLinux httpd use nfs files
  2. 2009/09/22 SeLinux 관련 펌
  3. 2009/09/22 php 외부 db 서버 (또는 기타 호스트) 접속 문제 (1)
  4. 2009/09/22 CentOS 5 vsftpd 500 OOPS: cannot change directory

LazyDreamy » Computer/Linux

SeLinux httpd use nfs files

드림 | 2009/09/23 12:02

selinux 설정 체크

[root@dev1 web]# /usr/sbin/getsebool -a | grep nfs
allow_ftpd_use_nfs --> off
allow_nfsd_anon_write --> off
httpd_use_nfs --> off
nfs_export_all_ro --> on
nfs_export_all_rw --> on
nfsd_disable_trans --> off
samba_share_nfs --> off
use_nfs_home_dirs --> off
virt_use_nfs –> off


httpd_use_nfs 를 on 으로 바꿔준다.

[root@dev1 web]# setsebool -P httpd_use_nfs 1

2009/09/23 12:02 2009/09/23 12:02


태그 , , ,

(go to top)

LazyDreamy » Computer/Linux

SeLinux 관련 펌

드림 | 2009/09/22 20:44

  • 끄고 켜기
    • 끄기

      # setenforce 0

    • 켜기

      # setenforce 1

    • 꺼버리면 대부분의 문제가 해결됩니다.. -_-;
  • 파일의 권한 보기
    • SELinux 아래에선 기존의 퍼미션과 별도로 security tag가 파일이나 디렉마다 설정됩니다. 이는 다음 명령어로 볼 수 있습니다.

      $ ls -Z
      (중략..)
      -rw-r--r--  root root  system_u:object_r:etc_t          csh.login
      drwxr-xr-x  root lp    system_u:object_r:cupsd_etc_t    cups
      drwxr-xr-x  root root  system_u:object_r:dbusd_etc_t    dbus-1
      (후략..)

  • 임의 디렉터리의 권한 설정하기
    • /etc/selinux/targeted/contexts/files/file_contexts.local 파일을 수정해 해당 디렉터리에 대해 설정해줍니다. 설정 방법은 /etc/selinux/targeted/contexts/files/file_contexts 을 참고하거나 메뉴얼 페이지를 참고하세요. 이 후에는 restorecon 이 이 설정 기준으로 먹습니다.
  • symbolic link 파일의 설정
    • chcon -h 를 해줘야 먹습니다. 링크의 경우..
  • apache (httpd)와 트러블
    • 기본 웹 디렉터리에서는 기본적으로 문제 없게 설정되어 있습니다. /var/www 쪽이나 유저의 홈디렉 아래에 public_html, www, web 등등 일반적인 경로 기준입니다.
    • OS 업그레이드 후 기본 웹 디렉에서 403 Permission error 가 떨어질때:
      • 보통 백업했던 해당 디렉을 복구하면서 태그가 붙지 않은 경우입니다.

        Forbidden

        You don't have permission to access / on this server.

      • /var/log/audit/audit.log 에 다음과 같이 에러가 뜹니다.

        type=AVC msg=audit(1177139220.333:330): avc:  denied  { getattr } for  pid=4337 comm="httpd" name="phpMyAdmin-2.9.1.1-all-languages" dev=dm-0 ino=6418532 scontext=root:system_r:httpd_t:s0 tcontext=root:object_r:user_home_t:s0 tclass=dir
        type=SYSCALL msg=audit(1177139220.333:330): arch=40000003 syscall=196 success=no exit=-13 a0=91d5f38 a1=bf90d63c a2=265ff4 a3=2008171 items=0 ppid=4332 pid=4337 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=root:system_r:httpd_t:s0 key=(null)
        type=AVC_PATH msg=audit(1177139220.333:330):  path="/var/www/html/somedir"

      • 이 때는 restorecon 명령어를 사용하면 원하는 파일과 디렉을 기본 설정값대로 만들 수 있습니다.

        # restorecon -rv /home

      • ~someuser/public_html 같은 디렉터리는 기본 설정이 문제 없는거니 관련 디렉을 restorecon 하면 되지만, 특이한 위치에 웹페이지가 있다면 다음 파일들을 수정하면 되지 않을까 싶습니다.

        /etc/selinux/targeted/contexts/files/homedir_template
        /etc/selinux/targeted/contexts/files/file_contexts.homedirs

      • template 을 수정하지 않고 웹 접근을 설정할 수도 있긴 합니다. root 가 아닌 일반 유저나 특별한 예외 상황에서는 이런 접근을 해야 하죠. 설정 전 설정은 다음과 같이 보입니다.

        $ ls -Z
        drwxrwxrwx  imo imo   root:object_r:user_home_t        pds
        drwxr-xr-x  imo imo   user_u:object_r:httpd_sys_content_t public_html

        여기서 public_html 은 httpd 접속이 가능하기 때문에 웹에서 보이지만, pds 는 403이 떨어집니다. chcon 명령어로 속성을 추가해줍니다.

        $ chcon -R -t httpd_sys_content_t pds

        그러면 해당 디렉의 설정이 바뀌게 되고 접속 가능해집니다.

        $ ls -Z
        drwxrwxrwx  imo imo   root:object_r:httpd_sys_content_t pds
        drwxr-xr-x  imo imo   user_u:object_r:httpd_sys_content_t public_html

    • php 에서 외부 데이터베이스 연결이 되지 않습니다. mysql_connect 로 다른 호스트 연결이 되지 않는다는가 하는 경우죠. 쉘에서 mysql 등으로는 연결이 잘 되기 때문에 원인 파악이 쉽지 않습니다.
      • 웹에서는 다음과 같은 에러 메시지를 확인할 수 있고,

        Can't connect to MySQL server on 'yyy.yyy.yyy.yyy' (13)

      • error_log 에는 다음과 같은 에러가 떨어지며..

        [Thu May 10 00:39:53 2007] [error] [client xxx.xxx.xxx.xxx] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on 'yyy.yyy.yyy.yyy' (13) in /home/someuser/public_html/file.php on line 2

      • /var/log/message 에서 원인을 파악할 수 있습니다.

        May 10 00:39:53 server kernel: audit(1178725193.534:53): avc:  denied  { name_connect } for  pid=4178 comm="httpd" dest=3306 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:mysqld_port_t:s0 tclass=tcp_socket

      • 해결 방법은 다음의 bool 값을 켜주면 됩니다.
        -P (대문자) 옵션을 주면 설정이 저장되어서 리붓해도 이 설정이 적용됩니다.

        # setsebool -P httpd_can_network_connect_db on

        원인을 파악하기 힘들어 당황스러운 에러였습니다.


출처 : http://arcy.org/tc/entry/SELinux-%EC%84%A4%EC%A0%95

2009/09/22 20:44 2009/09/22 20:44


태그 ,

(go to top)

LazyDreamy » Computer/Linux

php 외부 db 서버 (또는 기타 호스트) 접속 문제

드림 | 2009/09/22 18:55

해결하고보니.. SeLinux 문제. 확 꺼버릴까 고민을 orz

[root@dev1 /]# setsebool -P httpd_can_network_connect=1


SeLinux 관련 참조 : http://arcy.org/tc/entry/SELinux-%EC%84%A4%EC%A0%95

2009/09/22 18:55 2009/09/22 18:55


태그 , ,

(go to top)

LazyDreamy » Computer/Linux

CentOS 5 vsftpd 500 OOPS: cannot change directory

드림 | 2009/09/22 15:42

권한문제가 대부분이다 selinux 활성화 문제일 확률이 높다.


[root@dev1 vsftpd]# setsebool -P ftp_home_dir 1

2009/09/22 15:42 2009/09/22 15:42


태그 , , ,

(go to top)