Our company has a webserver with CentOS 7 and our customers manage their websites through FTP (vsftpd). SELinux is in enforcing mode.
The issue is that data created/uploadad through VSFTPD is not inheriting the appropriate SELinux context. Let me explain.
For example, for WordPress sites the server has, out of the box, already a couple of rules that can be seen using semanage fcontext -l |grep '/var/www'
, which are:
/var/www/html(/.*)?/uploads(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
So, when I copy a WordPress site let's say from another server into a directory in /var/www/html/
by SSH, the folders wp-content/
and wp-content/uploads/
have the proper httpd_sys_rw_content_t
security context. HOWEVER, when those folders are created through FTP, the context they get is httpd_sys_content_t
(no rw). This means that the sites our customers upload to the server can't write into those directories even if they give write permissions to the apache user/group, so the WordPress admin doesn't work. So, when they upload a site they have to request support from us to fix this, which is a waste of time for all involved.
Let's say the customer uploaded their site into httpdocs
, if through SSH I do mv httpdocs/ httpdocs.2/ && cp -pr httpdocs.2/ httpdocs/ && rm httpdocs.2/ -fr
the issue is solved, so there's nothing wrong with the data.
I can also do restorecon -Rv httpdocs/
to have the issue fixed.
So, the question is: How can I have the directories created/uploaded through VSFTPD inherit the proper SELinux contexts just like they are inherited when the directories are created/uploaded through SSH?
Существует разница между маркировкой по умолчанию, которая происходит во время выполнения, и регулярным выражением на основе Политика пост-маркировки, которая применяется на сервере.
Что вы здесь отмечаете:
/var/www/html(/.*)?/uploads(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
Это политика маркировки постов.
То, что вы обсуждаете в своей проблеме, на самом деле относится к политике времени выполнения.
Когда запись создается в каталоге с помощью SELinux, правила, определяющие, какой меткой окажется файл или каталог, не продиктованы регулярными выражениями, которые вы цитируете, а другими правилами (я считаю, что это правильный порядок, но, возможно, что-то упустил).
type_transition
. t ype_transition
правило. default_context
. Итак, когда я копирую сайт WordPress, скажем, с другого сервера на каталог в / var / www / html / по SSH, папки wp-content / и wp-content / uploads / имеют надлежащую безопасность httpd_sys_rw_content_t context.
Итак, да, он делает это, но не по той причине, по которой вы думаете. Конечно, не из-за политики маркировки постов.
Это происходит потому, что существует определенное правило с именем type_transition
, которое обеспечивает такое поведение.
$ sesearch -C -T -s unconfined_t -t httpd_sys_content_t -c dir
Found 4 named file transition filename_trans:
type_transition unconfined_t httpd_sys_content_t : dir httpd_sys_rw_content_t "wp-content";
type_transition unconfined_t httpd_sys_content_t : dir httpd_sys_rw_content_t "smarty";
type_transition unconfined_t httpd_sys_content_t : dir httpd_sys_rw_content_t "uploads";
type_transition unconfined_t httpd_sys_content_t : dir httpd_sys_rw_content_t "upgrade";
По сути, это говорит.
unlimited_t
и httpd_sys_content_t
и httpd_sys_rw_content_t
Причина, по которой это работает для SSHD, заключается в том, что после входа в систему вам предоставляется исходный контекст unlimited_t
, для которого применяется это правило.
Это не работает для службы FTP, потому что исходным контекстом этой службы, скорее всего, является ftpd_t
, для которого нет правила сопоставления.
Таким образом,вам нужно будет изменить политику, чтобы изменить поведение SELinux, чтобы также учитывать правила именованных файлов, которые вы видите и в других записях для FTP.
По крайней мере, в Fedora 23 существует интерфейс, позволяющий это, политика
policy_module(local_ftpd, 7.2.0)
require {
type ftpd_t;
}
apache_filetrans_named_content(ftpd_t)
Вы можете загрузить его, убедившись, что пакет selinux-policy-devel
установлен и работает make -f / usr / share / selinux / devel / Makefile нагрузка
.