【发布时间】:2021-12-23 02:50:58
【问题描述】:
我有一个我无法控制的后端,它使用魔术链接工作。如果我使用魔术链接,我不必登录。我想在不暴露实际密钥的情况下在外部共享魔术链接,因为密钥会不时更改,我希望使用 haproxy 作为反向代理。我不希望链接对整个互联网开放,并且也希望使用基本身份验证。我面临的问题是后端覆盖了 Authorization 标头(它是魔术链接工作所必需的),我陷入了一个循环,每次都需要登录
我的解决方法:
- 在第一次请求时,我请求基本身份验证(有效)
- 然后我将其写入 cookie(这部分有效)
- 在每个后续请求中,如果 cookie 存在,我会读取 cookie 并将 Authorization 标头设置为 cookie 值(这部分不起作用)
- 然后我运行 http_auth,在我看来它现在应该可以工作了,因为我已经覆盖了标题
但它不起作用。有什么建议吗?
userlist auth-list
user myuser insecure-password mypass
frontend myfrontend
bind *:80
mode http
acl is-path path -i -m beg /publiclink
acl has_cookie req.hdr(X-MyAuth) -m found
http-request set-header Authorization %[req.hdr(X-MyAuth)] if has_cookie
http-request auth unless { http_auth(auth-list) }
http-request set-var(txn.myhostheader) req.hdr(Authorization) if { http_auth(auth-list) !has_cookie }
default_backend node
backend node
mode http
server dcnode1 192.168.0.1:8000 check
http-response set-header set-cookie "X-MyAuth=%[var(txn.myhostheader)]; Path=/" if { var(txn.myhostheader) -m found }
http-request replace-path /publiclink1(.*) /magiclink\1
http-request set-header Authorization "Key magiclink"
【问题讨论】:
标签: haproxy