使用haproxy捕获并转发扩展的PKI证书属性(例如UPN)

我试图拉相互authenticationscheme中的客户端证书属性,并将其设置为后端请求中的HTTP标头。 见下面的fig 1

图。1
   [用户证书正确]
                  |
                  |  1.提供具有正常v1属性的证书
                  | 有额外的“扩展”属性
                  | 含。 包含“主题名称”
                  |  “用户主要名称”(UPN看起来像一个电子邮件地址) 
                  |
      [example.com:443 haproxy] --app1 / app2 CNAMEd到example.com 
                  |
                  |  2.阅读主题备用名称
                  |  3.正则expression式或parsing出UPN
                  |  4.将REMOTE_USER头设置为UPN
                  |  5.传递给后端(S)
                  |
        ┌------------------┬
        |  |   
        |  |   
        |  |   
        |  |   
        VV [app1svr:80] [app2svr:80]    

通常,这很容易,你只需要使用内置的function就可以得到你想要的属性:

前端https
 绑定*:443名称https ssl crt ./server.pem ca-file ./ca.crtvalidation必需

  http-request set-header X-SSL-Client-DN%{+ Q} [ssl_c_s_dn]
  http-request set-header X-SSL-Client-CN%{+ Q} [ssl_c_s_dn(cn)]
  http-request set-header X-SSL-Issuer%{+ Q} [ssl_c_i_dn]
  http-request set-header X-SSL-Client-NotBefore%{+ Q} [ssl_c_notbefore]
  http-request set-header X-SSL-Client-NotAfter%{+ Q} [ssl_c_notafter]

  default_backend app1svr

后端app1svr
 服务器app1 app1svr.example.com:80

后端app2svr
 服务器app2 app2svr.example.com:80

属性列表在这里: https : //cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.4

不幸的是,从属性列表中缺less的是任何COMMON扩展属性,例如:

  • 主题替代名称
    • RFC822名称
    • 其他名字
      • 主要名称
  • CRL分发点

我似乎无法找出正确的方式来访问这些属性。 看看代码(下面的第5815行) https://github.com/haproxy/haproxy/blob/master/src/ssl_sock.c它似乎并不仅仅是一个文档问题。

这里有什么想法? (可能相关的问题): https : //stackoverflow.com/questions/22966461/reading-an-othername-value-from-a-subjectaltname-certificate-extension

作为HAProxy版本1.5.14(请参阅http://www.haproxy.org/news.html)HAProxy在ssl_c_der属性中发送整个证书。

所以,如果你在haproxyconfiguration文件中放置下面的行

 http-request set-header X-SSL-ClientCert-Base64 %{+Q}[ssl_c_der,base64] 

那么您可以通过读取X-SSL-ClientCert-Base64头来读取整个客户端证书。