vsftpd 和 samba 的 SELinux 写访问权限

vsftpd 和 samba 的 SELinux 写访问权限

我认为这应该很容易,但我是 SELinux 的新手。我有一个 CentOS 6 文件服务器。我在 /var/media 中有一些 LVM 文件系统,我想使用 Samba 和 FTP 与 Windows 计算机共享它们。我正在使用 ACL,以便权限在 Windows 中正常工作(我有一个两个用户网络)。我发现 Samba 虽然可以工作,但文件传输速度很慢,所以我想尝试一下 FTP。

我想继续使用 SELinux 来保证安全,但我在通过 FTP 访问文件时遇到了麻烦。我可以读取文件并写入我的主目录。但是我无法写入 /var/media 中的文件(使用 samba_share_t 上下文)。

我认为这allow_ftpd_use_cifs应该可以解决这个问题。我可以让它与 一起工作allow_ftpd_full_access,但我宁愿避免这种情况。我缺少什么?

以下是相关信息:

[mdurak@srv ~]$ ls -Z /var/media
drwxrwxr-x+ mdurak admins system_u:object_r:samba_share_t:s0 docs
drwxrwxr-x+ mdurak admins system_u:object_r:samba_share_t:s0 library
drwxrwxr-x+ mdurak admins system_u:object_r:samba_share_t:s0 photos
drwxrwxr-x+ mdurak admins system_u:object_r:samba_share_t:s0 projects

[mdurak@srv ~]$ sudo semanage boolean -l | grep ftp
ftp_home_dir                   (on   ,   on)  Allow ftp to read and write files in the user home directories
tftp_anon_write                (off  ,  off)  Allow tftp to modify public files used for public file transfer services.
allow_ftpd_full_access         (off  ,  off)  Allow ftp servers to login to local users and read/write all files on the system, governed by DAC.
allow_ftpd_use_cifs            (on   ,   on)  Allow ftp servers to use cifs used for public file transfer services.
allow_ftpd_use_nfs             (off  ,  off)  Allow ftp servers to use nfs used for public file transfer services.
allow_ftpd_anon_write          (on   ,   on)  Allow ftp servers to upload files,  used for public file transfer services. Directories must be labeled public_content_rw_t.
ftpd_use_passive_mode          (off  ,  off)  Allow ftp servers to use bind to all unreserved ports for passive mode
ftpd_connect_db                (off  ,  off)  Allow ftp servers to use connect to mysql database
httpd_enable_ftp_server        (off  ,  off)  Allow httpd to act as a FTP server by listening on the ftp port.

[mdurak@srv ~]$ sudo semanage boolean -l | grep samba
samba_domain_controller        (off  ,  off)  Allow samba to act as the domain controller, add users, groups and change passwords.
samba_portmapper               (off  ,  off)  Allow samba to act as a portmapper
samba_enable_home_dirs         (on   ,   on)  Allow samba to share users home directories.
samba_export_all_ro            (off  ,  off)  Allow samba to share any file/directory read only.
samba_export_all_rw            (off  ,  off)  Allow samba to share any file/directory read/write.
use_samba_home_dirs            (off  ,  off)  Support SAMBA home directories
samba_create_home_dirs         (off  ,  off)  Allow samba to create new home directories (e.g. via PAM)
cdrecord_read_content          (off  ,  off)  Allow cdrecord to read various content. nfs, samba, removable devices, user temp and untrusted content files
allow_smbd_anon_write          (off  ,  off)  Allow samba to modify public files used for public file transfer services.  Files/Directories must be labeled public_content_rw_t.
samba_share_fusefs             (off  ,  off)  Allow samba to export ntfs/fusefs volumes.
samba_share_nfs                (off  ,  off)  Allow samba to export NFS volumes.
samba_run_unconfined           (off  ,  off)  Allow samba to run unconfined scripts
sanlock_use_samba              (off  ,  off)  Allow sanlock to manage cifs files
virt_us

e_samba (off , off) 允许 virt 管理 cifs 文件

/etc/vsftpd/vsftpd.conf

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
chroot_list_enable=YES
# mdurak is in the chroot_list
chroot_list_file=/etc/vsftpd/chroot_list
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
pasv_enable=YES
local_root=/var/media

尝试在 FTP 中创建目录(审核日志中也有一条拒绝消息,因此我知道这是 SELinux 问题)。

Command:    CWD /var/media/library/music
Response:   250 Directory successfully changed.
Command:    MKD sdff
Response:   550 Create directory operation failed.
Command:    MKD /var/media/library/music/sdff
Response:   550 Create directory operation failed.

答案1

我从这里想通了:http://selinuxproject.org/page/SambaRecipes

必须将文件夹上下文设置为public_content_rw_t并执行

setsebool -P allow_smbd_anon_write=1

现在我可以通过Samba和FTP进行写入(以后支持其他域也会很容易)

相关内容