私はすでに同様の設定を構成しました。
まず、Apache2を使用してユーザーを認証しました。
mod_sslを有効にする必要があり、(グローバルに)定義する必要があります:
- SSLCertificateFile:PEMでエンコードされたサーバー証明書を指します;
- SSLCertificateKeyFile:PEMでエンコードされたサーバーキーを指します;
- SSLCertificateChainFile:CA証明書のPEMリストを指します;
- SSLCACertificatePath:すべてのPEMCA証明書を含むフォルダーを指します;
- SSLCACertificateFile:CA証明書を指します(SSLCertificateChainFileと同じ値である必要があります);
- SSLCARevocationPath:すべてのCRLを含むフォルダーを指します;
- SSLCARevocationFile:取り消された証明書のリスト(ca-bundle.crl)を指します
- SSLCARevocationCheckチェーン。
これで、サーバーはクライアントX.509証明書を検証する準備が整いました。
apache2をフロントWebサーバーとして使用したくない場合は、mod_proxyを有効にしてリバースプロキシとして設定できます。
次のように仮想ホストを定義する必要があります。
<VirtualHost *:443>
ServerName test.example.com:443
ServerAdmin webmaster@example.com
RequestHeader set Front-End-Https "On"
# Here I define two headers, Auth-User and Remote-User
# They will contain the key SSL_CLIENT_S_DN_CN which is the name of the
# client certificate's owner.
<If "-n %{SSL_CLIENT_S_DN_CN}">
# If the key doesn't exist, it means that the certificate wasn't sent or
# it was revoked.
RequestHeader set Auth-User "%{SSL_CLIENT_S_DN_CN}s"
RequestHeader set Remote-User "%{SSL_CLIENT_S_DN_CN}s"
</If>
# Now enable SSL, and SSL via the proxy
SSLEngine on
SSLProxyEngine on
## Require a client certificate
# SSLVerifyClient require
## NB: I prefer set it to optional, in order to allow the user
## to connect to my application with a degraded mode (login+password)
## It's easy to detect if the user was authenticated by apache by looking
## at HTTP_AUTH_USER or HTTP_REMOTE_USER
SSLVerifyClient optional
# Maximum depth of CA Certificates in Client Certificate verification
SSLVerifyDepth 4
# Now, I pass all of this to my application, which is runned in nginx for example :
<Location />
ProxyPass http://<applciation host>
ProxyPassReverse http://<applciation host>
ProxyPreserveHost on
# Send all informations about the client/server certificates to the application
SSLOptions +StdEnvVars +ExportCertData
</Location>
</VirtualHost>
そして今、djangoでは、ここで説明するようにリモート認証バックエンドを有効にする必要があります。
クライアント証明書から抽出されたすべての情報はアプリケーションに送信されるため、リクエストオブジェクト(および/またはミドルウェア)を使用してそれらを使用できます。
お役に立てば幸いです。