web-dev-qa-db-ja.com

CentOS7、SELinux、Apache、PHP-FPM:ユーザーディレクトリへのfile_put_contentsへのアクセスが拒否されました

SELinuxが有効になっているCentOS7/Apacheマルチユーザー(userdir)セットアップがあり、次のディレクトリ構造があります。

/home/USER/public_html/resources/css

/home/USERディレクトリ全体とその下のすべては、USERが所有しています。私がhttpd_user_content_tに設定した前述のディレクトリを除いて、すべてのファイルとディレクトリのSELinuxコンテキストはhttpd_user_rw_content_tです。 ApacheサーバーはユーザーApacheで実行され、ApacheユーザーはUSERグループのメンバーです。 /home/USERの下にあるものはすべて、0775のアクセス許可(グループ書き込み可能)を持っています。私のスクリプトの1つは、phpのfile_put_contentsを使用してtest_fpc.txtディレクトリに/home/USER/public_html/resources/cssという名前のファイルを作成しますが、ディレクトリがApache:apacheによって所有されている場合にのみfile_put_contentsは成功します。ディレクトリがUSER:USERによって所有されている場合、file_put_contentsfailed to open stream: Permission denied警告で失敗します。監査ログには次の内容が含まれます。

type=SYSCALL msg=audit(1483602823.639:155208): Arch=c000003e syscall=2 success=no exit=-13 a0=7f0e5d9f1478 a1=241 a2=1b6 a3=73656372756f7365 items=2 ppid=855 pid=992 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="php-fpm" exe="/usr/sbin/php-fpm" subj=system_u:system_r:httpd_t:s0 key="Apache_user_access"
type=CWD msg=audit(1483602823.639:155208):  cwd="/home/USER/public_html"
type=PATH msg=audit(1483602823.639:155208): item=0 name="/home/USER/public_html/resources/css/" inode=65290545 dev=08:12 mode=040775 ouid=1002 ogid=1002 rdev=00:00 obj=system_u:object_r:httpd_user_rw_content_t:s0 objtype=PARENT
type=PATH msg=audit(1483602823.639:155208): item=1 name="/home/USER/public_html/resources/css/test_fpc.txt" objtype=CREATE

Sudo -u Apache bashを使用してApacheユーザーでログインし、echo "test" > /home/USER/public_html/resources/css/test_bash.txtを実行すると、機能し、監査ログの出力は次のようになります。

type=SYSCALL msg=audit(1483602552.156:155207): Arch=c000003e syscall=2 success=yes exit=3 a0=f607c0 a1=241 a2=1b6 a3=0 items=2 ppid=13539 pid=13540 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=pts0 ses=207 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="Apache_user_access"
type=CWD msg=audit(1483602552.156:155207):  cwd="/home/USER/public_html"
type=PATH msg=audit(1483602552.156:155207): item=0 name="/home/USER/public_html/resources/css/" inode=65290545 dev=08:12 mode=040775 ouid=1002 ogid=1002 rdev=00:00 obj=system_u:object_r:httpd_user_rw_content_t:s0 objtype=PARENT
type=PATH msg=audit(1483602552.156:155207): item=1 name="test_bash.txt" inode=65273889 dev=08:12 mode=0100644 ouid=48 ogid=48 rdev=00:00 obj=unconfined_u:object_r:httpd_user_rw_content_t:s0 objtype=CREATE

また、/home/USER/public_html/resources/cssディレクトリのコンテキストをhttpd_sys_rw_content_tに設定しようとしましたが、違いはありません。

現在の制限的なSELinux構成を維持したいので、setsebool -P httpd_unified 1の設定を試していませんが、SELinuxはここでは実際の問題ではないと感じています。 IS USERグループのメンバーであるApacheユーザーがグループ書き込み可能ディレクトリを書き込み可能にしない原因は何でしょうか?

2
user682180

ログアウトして再度ログインするか、システムを再起動する必要がありました。ここで手がかりを見つけました Linuxグループのアクセス許可が正しく適用されていません。

0
user682180