来自HAProxy或Apache mod_代理的OAuth令牌验证

来自HAProxy或Apache mod_代理的OAuth令牌验证,oauth,oauth-2.0,haproxy,mod-proxy,Oauth,Oauth 2.0,Haproxy,Mod Proxy,我在HAProxy负载均衡器后面的3个节点上部署了一个微服务,所有这些都在内部网络中。这些服务使用OAuth2 API授权服务器进行保护。现在,我想把HAProxy移动到DMZ。我想拒绝头中没有auth令牌的请求,并通过调用OAuth REST API来验证auth令牌 在HAProxy,我找不到一个方法来做到这一点。有一个可用于健康检查的选项httpchk。我正在寻找一个类似的功能,可以用来验证每个传入的请求 有谁能帮我建议一下如何使用HAProxy或Apache mod_proxy实现这一点

我在HAProxy负载均衡器后面的3个节点上部署了一个微服务,所有这些都在内部网络中。这些服务使用OAuth2 API授权服务器进行保护。现在,我想把HAProxy移动到DMZ。我想拒绝头中没有auth令牌的请求,并通过调用OAuth REST API来验证auth令牌

在HAProxy,我找不到一个方法来做到这一点。有一个可用于健康检查的
选项httpchk
。我正在寻找一个类似的功能,可以用来验证每个传入的请求


有谁能帮我建议一下如何使用HAProxy或Apache mod_proxy实现这一点吗?

有一个Apache模块
mod_auth_openidc
,它允许您根据授权服务器验证OAuth 2.0令牌,请参阅:。该模块可以与mod_proxy结合使用,以实现您想要的功能

在HAProxy,我找不到一个方法来做到这一点

作为记录,从2021年起,你可以。这里有一篇关于使用OAuth的HAProxy官方博客文章

TL;DR:安装,然后您可以像下面这个代码片段一样生成conf

frontend api_gateway
   # Always use HTTPS to protect the secrecy of the token
   bind :443 ssl crt /usr/local/etc/haproxy/pem/test.com.pem

   # Accept GET requests and skip further checks
   http-request allow if { method GET }
   
   # Deny the request if it's missing an Authorization header
   http-request deny unless { req.hdr(authorization) -m found }
   
   # Verify the token by invoking the jwtverify Lua script 
   http-request lua.jwtverify
   
   # Deny the request unless 'authorized' is true
   http-request deny unless { var(txn.authorized) -m bool }
   
   # (Optional) Deny the request if it's a POST/DELETE to a 
   # path beginning with /api/hamsters, but the token doesn't 
   # include the "write:hamsters" scope
   http-request deny if { path_beg /api/hamsters } { method POST DELETE } ! { var(txn.oauth_scopes) -m sub write:hamsters }
   
   # If no problems, send to the apiservers backend
   default_backend apiservers

杰出的您是否有任何与整合的计划?另外,您是否为CentOS/RHEL编译过二进制文件(rpm)?谢谢二进制文件位于“发布”部分;我将调查OAuth API,并让您知道您应该能够配置mod_auth_openidc,以便它能够针对OAuth API工作;使用
OIDCOAuthIntrospectionEndpointMethod GET
,在
OIDCOAuthClientID
中设置密钥,在
OIDCOAuthClientSecret
中设置密钥,将
OIDCOAuthIntrospectionEndpoint访问令牌设置为
https:///v1/tokeninfo
,请参阅:谢谢。我试试这个。