Thursday, July 21, 2011

vsftpd กับ SElinux ไม่ยอมอ่าน home directory มี error cannot change directory

อันเนื่องมาจากงาน Implement ที่บริษัทแห่งหนึ่งแถวๆบางซื่อ

โดยได้รับมอบหมายให้ติดตั้ง ftp server ในองค์กร เพื่อให้ customer ดาวน์โหลดไฟล์ แทนการ attachfile ไปกับ e-mail
เพื่อความปลอดภัย ไม่ให้ไฟล์ของบริษัทต้องรั่วใหลไปไกล..

vsftpd เมื่อ login ด้วย local user มี error ว่า cannot change directory

หากปิด SElinux ก็จะเข้าได้ปกติ ... แต่จะมีประโยชน์อันใด ถ้าหากต้องหนีปัญหาด้วยการปิดความปลอดภัย
มิสู้เปิด option ให้ SElinux อนุญาติให้ vsftpd เขียน home directory ได้มิดีกว่าหรือ

ด้วยคำสั่ง

setsebool -P ftp_home_dir=1

-P เมื่อต้องการให้การตั้งค่ามีผลหลังจาก boot เครื่องแล้ว
ตามปกติถ้าไม่ใส่ option ใด ๆ จะเป็นการเปลี่ยนแปลงค่าแบบชั่วคราวเท่านั้น

1 คือ เปิดเป็น ON


นอกจากนี้ SELinux ยังมีคำสั่งที่เกี่ยวข้องกับ vsftpd อีกคือ

allow_ftpd_anon_write –> permits the writing of files to directories configured with the public_content_rw_t setting.
allow_ftpd_use_cifs –> permits the use of files that are shared via CIFS
allow_ftpd_use_nfs –> permits the use of files that are shared via NFS
ftp_is_daemon –> required for the standalone daemon
ftp_home_directory –> permits read and write access to user home directories


ถ้าสมมติว่าเราสร้าง “file” ไว้ที่ไดเรกทอรี /var/ftp/pub สิ่งที่มองเห็นว่าเป็น SELinux ด้วย # ls -Z /var/ftp/pub ก็คือ
-rw-r–r– root root system_u:object_r:public_content_t file

system_u is used because this is a default setting for the system.
system_u:

The system object shows the context for the role.
object_r

The type describes the nature of the data. In this case this is public read only data by default.
public_content_t
If you wanted to allow users to write to the pub directory you would need to change the context. You could do that with the chcon command.

chcon -R -u ser_u -t public_content_rw_t /var/pub
The default settings for the ftp directory are set in the file /etc/selinux/targeted/contexts/files/file_contexts .

Be very careful in making changes in this file. Here is the listing for ftp.
/var/ftp(/.*)? system_u:object_r:public_content_t:s0

ที่มา :
http://beginlinux.com/blog/2008/11/vsftpd-and-selinux-on-centos/

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More