一般ユーザのウェブ表示

Apache の設定

 一般ユーザのウェブを公開するには Apache の設定ファイルである httpd.conf の調整、ディレクトリの作成が必要です。加えて SELinux を有効にしている場合、一般ユーザのウェブ表示を行うときには注意が必要です。

 httpd.conf の 340 行目前後を書き換えます。

<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir disable

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    #UserDir public_html

</IfModule>

 【 UserDir disable 】と初期状態では一般ユーザのウェブ表示が不許可です。
 許可するためには disable の行をコメントし、【 UserDir pubic_html 】を有効にしなくてはいけません。ここは環境や好みに応じて UserDir www 等、適時変更下さい。

変更後)

<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disable

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    UserDir public_html

</IfModule>

 また、この状態ではウェブの公開ができても CGI や SSI の許可がされません。.htaccess を扱うことができるように 360 行目前後を適時書き換えます。以下は設定例です。

<Directory /home/*/public_html>
    AllowOverride All
    Options MultiViews -Indexes SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

 httpd.conf の編集が終わったら Apache の再起動を実行し、設定を反映させます。

# /sbin/service httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中:                                            [  OK  ]

ディレクトリの確認

 次にユーザディレクトリのパーミッションを確認します。
 ユーザが追加された時点でのホームディレクトリのパーミッションは 755(rwxr-xr-x) です。このままではウェブの表示をさせることが出来ますが、もし違っている場合は変更が必要です。

# chmod o+x /home/アカウント名

 こちらのコマンドを実行して、「その他」のユーザ権限に対して「実行(x)」を許可します。

 次に公開用ディレクトリを作成します。

$ mkdir public_html
$ echo test > public_html/test.html

 あとはブラウザから http://192.168.11.253/~アカウント名/test.html として表示できる事が確認できれば問題ありません。

SELinux 導入時の注意点

 もし SELinux が有効になっている場合は【 Forbidden 】とエラーが出てしまいます。You don't have permission to access 対象ファイル、のエラーです。

 Apache のエラーログにも以下のような記録が残ります。

[Sun Jun 19 21:05:42 2005] [error] [client 192.168.11.102] (13)Permission denied: access to /~akane/test.html denied

 原因は SELinux の【 タイプ遷移 】によるセキュリティーポリシーの制限を受けるからです。SELinux では新しくディレクトリを作成すると、その親ディレクトリのセキュリティコンテキストを継承します。

$ ls -lZ

 こちらのコマンドを実行すると、ディレクトリ内のセキュリティコンテキストが表示されます。以下は akane アカウントのホームディレクトリ「 /home/akane 」のリストです。

$ ls -alZ /home/akane/
drwxr-xr-x  akane    users    root:object_r:user_home_dir_t    .
drwxr-xr-x  root     root     system_u:object_r:home_root_t    ..
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bash_logout
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bash_profile
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bashrc
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .canna
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .emacs
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .gtkrc
drwxr-xr-x  akane    users    user_u:object_r:user_home_t      .kde
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .zshrc
drwxr-xr-x  akane    users    user_u:object_r:user_home_t      public_html

 public_html には user_u:object_r:user_home_t というセキュリティコンテキストが割り当てられています。apache ではルール上、public_html を表示出来ません。

# /sbin/ausearch -m AVC

 こちらのコマンドを実行して SELinux のログを見ると、実行できない旨のエラーが確認できます。

time->Sun Jun 19 21:05:42 2005
type=AVC msg=audit(1119182742.782:6278950): avc:  denied  { getattr } for 
 pid=6090 comm="httpd" name=public_html dev=dm-1 ino=5625101  
scontext=root:system_r:httpd_t tcontext=user_u:object_r:user_home_t tclass=dir
type=SYSCALL msg=audit(1119182742.782:6278950): arch=40000003 syscall=196
success=no exit=-13 a0=95e58a0 a1=bfca1564 a2=32cff4 a3=bfca1564 items=1
pid=6090 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48
sgid=48 fsgid=48 comm="httpd" exe="/usr/sbin/httpd"
type=AVC_PATH msg=audit(1119182742.782:6278950):  
path="/home/akane/public_html"
type=PATH msg=audit(1119182742.782:6278950): item=0 
name="/home/akane/public_html" inode=5625101 dev=fd:01 mode=040755 ouid=501
 ogid=100 rdev=00:00

 Fedora Core 4 では予め /home/ユーザ名/public_html に対するセキュリティコンテキストが設定されています。/sbin/restorecon コマンドを用いて、public_html へ適切なラベルを割り当てなくてはいけません。  今回の例では /home/akane/ 以下を適切にラベル割り当てをしたいので、

$ /sbin/restorecon -R /home/akane 

 このようにコマンドを実行します。コマンド実行後、再度 ls に Z オプションをつけてセキュリティコンテキストを確認すると、次のようにセキュリティコンテキストの"タイプ"が先ほどの「user_home_t」から「httpd_user_content_t」に変更されている事が確認できます。

# ls -alZ /home/akane/
drwxr-xr-x  akane    users    root:object_r:user_home_dir_t    .
drwxr-xr-x  root     root     system_u:object_r:home_root_t    ..
-rw-------  akane    users    user_u:object_r:user_home_t      .bash_history
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bash_logout
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bash_profile
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .bashrc
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .canna
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .emacs
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .gtkrc
drwxr-xr-x  akane    users    user_u:object_r:user_home_t      .kde
-rw-r--r--  akane    users    user_u:object_r:user_home_t      .zshrc
drwxr-xr-x  akane    users    user_u:object_r:httpd_user_content_t public_html

 少々面倒ですが、SELinux を有効にして一般ユーザのウェブ表示を行うときには注意が必要です。


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: Mon, 15 May 2006 01:33:18 JST (6549d)