Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
您将如何在Nginx代理后的Django应用程序上管理X509身份验证?_Django_Nginx_X509certificate_X509 - Fatal编程技术网

您将如何在Nginx代理后的Django应用程序上管理X509身份验证?

您将如何在Nginx代理后的Django应用程序上管理X509身份验证?,django,nginx,x509certificate,x509,Django,Nginx,X509certificate,X509,我想使用X509客户端身份验证进行安全API访问 X509证书由我们的CA(memberca)生成 目的是: 客户端使用SSL连接API 拥有我们memberca的有效X509证书的人可以访问它 我们使用CRL检查证书是否已被吊销 我想,我可以在Nginx配置中直接管理它。 我该怎么做 我可以用Django吗?那我该怎么办呢? 我可以用这两种解决方案之一向用户发送证书吗 例如,Nginx是否可以将一些证书数据映射到WSGI头,这样我就可以匹配我的用户?我们正在使用Apache,通过让mod_ss

我想使用X509客户端身份验证进行安全API访问

X509证书由我们的CA(memberca)生成

目的是:

  • 客户端使用SSL连接API
  • 拥有我们memberca的有效X509证书的人可以访问它
  • 我们使用CRL检查证书是否已被吊销
  • 我想,我可以在Nginx配置中直接管理它。 我该怎么做

    我可以用Django吗?那我该怎么办呢? 我可以用这两种解决方案之一向用户发送证书吗


    例如,Nginx是否可以将一些证书数据映射到WSGI头,这样我就可以匹配我的用户?

    我们正在使用Apache,通过让mod_ssl负责证书验证和吊销检查。如果证书有效且未被撤销,我们只需将证书的CN放入HTTP头中,然后使用Django进行检索并与我们的用户数据库进行匹配。

    我已经配置了类似的设置

    首先,我使用Apache2对用户进行身份验证

    您需要启用mod_ssl,并且必须(全局)定义:

    • SSLCertificateFile:指向PEM编码的服务器证书
    • SSLCertificateKeyFile:指向PEM编码的服务器密钥
    • SSLCertificateChainFile:指向您的PEM CA证书列表
    • SSLCACertificatePath:指向包含所有PEM CA证书的文件夹
    • SSLCatertificateFile:指向您的CA证书(应具有与SSLCertificateChainFile相同的值)
    • SSLCareconcationPath:指向包含所有CRL的文件夹
    • sslcavocationfile:指向已吊销证书的列表(您的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>
    
    
    ServerName test.example.com:443
    服务器管理员webmaster@example.com
    RequestHeader将前端Https设置为“开”
    #这里我定义了两个头,Auth User和Remote User
    #它们将包含密钥SSL\u CLIENT\u S\u DN\u CN,即
    #客户端证书的所有者。
    #如果密钥不存在,则表示未发送或删除证书
    #它被撤销了。
    RequestHeader设置身份验证用户“%{SSL\U客户端\U S\U DN\U CN}S”
    RequestHeader设置远程用户“%{SSL\U客户端\U S\U DN\U CN}S”
    #现在启用SSL,并通过代理启用SSL
    斯伦金安
    SSLProxyEngine打开
    ##需要客户端证书
    #SSLVerifyClient要求
    ##注意:我更喜欢将其设置为可选,以便允许用户
    ##以降级模式(登录+密码)连接到我的应用程序
    ##通过查看,很容易检测用户是否通过apache身份验证
    ##在HTTP\u AUTH\u用户或HTTP\u远程用户
    SSLVerifyClient可选
    #客户端证书验证中CA证书的最大深度
    SSLVerifyDepth 4
    #现在,我将所有这些传递给我的应用程序,该应用程序在nginx中运行,例如:
    ProxyPass http://

    从客户端证书提取的所有信息都会发送到应用程序,因此使用请求对象(和/或中间件)可以使用它们


    我希望它能帮助你。

    这真的很有趣,非常感谢。我将检查Nginx是否可以使用类似的解决方案。我刚刚开始实现它。