2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPress と Shibboleth SP を同居させる場合の設定

Posted at

概要

https://example.net/Shibboleth.sso/SAML2/POST に対するアクセスが、WordPress によって横取りされないように、/var/www/.htaccess の先頭に近い場所に以下を記述しておくこと。

/var/www/.htaccess
RewriteCond %{REQUEST_URI} ^/Shibboleth.sso(/|$)
RewriteRule . - [L]

原因

WordPress では permalink を実現するために、/var/www/.htaccess に以下のような設定をしておくことが一般的である。

/var/www/.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

これは、実在するファイルやディレクトリに対するアクセスでなければ WordPress の index.php に処理を依頼するという指定である。

サーバ側設定ファイルで、ScriptAlias ディレクティブや Alias ディレクティブなどを使っている場合は、/var/www/.htaccess の RewriteRule ディレクティブの影響を受けない。

/etc/apache2/sites-available/default-ssl.conf
<Location /shibboleth-sp>
    Allow from all
</Location>
Alias /shibboleth-sp/main.css /usr/share/shibboleth/main.css

しかし、Apache2 の shibboleth モジュールが担当している /Shibboleth.sso/ 以下に対するアクセスは、上記の RewriteRule ディレクティブの影響を受ける1ため、SAML 応答が WordPress に渡されることになってしまう。これは WordPress にとっては理解不能なアクセスであるから、Apache2 の動作ログには、以下のような 404 の記録が残ることになる。

192.0.2.20 - - [20/Aug/2020:02:37:36 +0900] "POST /Shibboleth.sso/SAML2/POST HTTP/1.1" 404 13927 "https://idp.example.net/idp/profile/SAML2/Redirect/SSO?SAMLRequest=xxx&RelayState=cookie%yyy" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" -

この問題を回避するには、本稿の先頭に書いた通り、回避用の RewriteRule を挿入しておく必要がある。

  1. mod_shib モジュールと mod_rewrite モジュールの評価順序を勘違いしていたばかりに、この原因に辿りつくまでに半日かかりました…orz。mod_shib モジュールが mod_rewrite モジュールよりも優先して処理されるわけじゃなかったんですね。/var/www/.htaccess が原因だということは、/var/www/.htaccess を削除してみると正常動作するので、かなり早くに気付いたのですが、問題は WordPress のセキュリティ対策プラグインが生成した RewriteRule の大群。初見ではまったく解読できなかったので、他の場所から調べ始めたのが運のつきでした。最終的には RewriteRule を解読するしかなかったものなあ…ああ疲れた。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?