apache - 无法根据 Apache 虚拟主机中的路径位置编辑身份验证标头?
问题描述
Apache 作为反向代理的应用程序的行为如下:
- 它需要基本的身份验证标头才能登录。
- 对于从 开始的路径
/api/*
只需要 Bearer 令牌。 - 如果标头中有基本令牌,则应用程序返回 401,未经授权的 http 响应 - 它只需要 Bearer 令牌。
为除路径之外的所有 URL 配置了 CAS 身份验证,/api/*
并且我在 vhost 配置文件中设置了基本身份验证令牌 - 在用户通过 CAS 进行身份验证后,无需再次显示登录表单即可登录用户。
阿帕奇配置文件enterprise-search.conf
:
<VirtualHost *:80>
ServerName https://search.test.xyz
ServerAdmin john@xyz
RemoteIPHeader X-Client-IP
RemoteIPInternalProxy 10.10.10.2
LogFormat "%a %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" combined-forwarded
CustomLog ${APACHE_LOG_DIR}/enterprise-search-access.log combined-forwarded
ErrorLog ${APACHE_LOG_DIR}/enterprise-search-error.log
LogLevel debug
CASRootProxiedAs https://search.xyz
<Location />
# authn type
AuthType CAS
CASScope /
AuthName "KFUPM"
# authz
# Grant all groups access to the root
AuthGroupFile "/etc/apache2/http-authz/enterprise-search"
Require group all-enterpirse-search
# Pass REMOTE_USER header to application
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)$
RewriteRule . - [E=RU:%1,NS]
RequestHeader set REMOTE_USER %{RU}e
RequestHeader set Authorization "Basic xxxxxxxxxx"
</Location>
# authz: local_groups
<Location /all-enterpirse-search>
AuthGroupFile "/etc/apache2/http-authz/enterprise-search"
Require group all-enterprise-search all-enterpirse-search
</Location>
<Location /api/>
# authn type
AuthType none
Allow from all
Satisfy any
# authz
Require valid-user
# Pass REMOTE_USER header to application
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)$
RewriteRule . - [E=RU:%1,NS]
RequestHeader set REMOTE_USER %{RU}e
RequestHeader edit Authorization "Basic[^,]+, " ""
ProxyPass / http://localhost:3002/
ProxyPassReverse / http://localhost:3002/
</Location>
</VirtualHost>
的行为RequestHeader edit Authorization "Basic[^,]+, " ""
是替换客户端传递的基本令牌头,它工作正常。
但我真正想要的是设置 Basic 令牌<Location />
并在<Location /api/>
. 使用RequestHeader edit Authorization "Basic[^,]+, " ""
inside<Location /api/>
不会删除基本令牌,并且应用程序正在返回带有 401 响应的 API 调用。
我是 Apache 配置的新手,可能是我实现目标的方法不正确。请建议是否有更好的方法来做到这一点。
谢谢。
解决方案
没有办法解决这个问题,因为您需要授权和应用程序的代理路径。但是您可以只在前面制作您的 api,并将 CAS 路径设置为 /auth 之类的东西,然后通过您的 api 重定向到 CAS。
推荐阅读
- c++ - C++:帮助理解这行代码试图做什么
- c - 有什么方法可以阻止特权程序成功执行 unlink()?
- excel - 如何在电子邮件中添加多个附件?
- reactjs - 反应 setState 和 array.push 不起作用
- java - 将存储库或服务注入 Spring 状态机 Action 和 Guard 的正确方法
- c# - 如何使用 C# 在 SQL 数据库表中的特定索引处插入一行
- clang - 使用 C++ 在独立进程中生成 LLVM-IR
- c - 在 C 中将长 shellcode 加载到内存中
- http - 重试 http 请求 RoundTrip
- reactjs - 在 Cypress 通过 npx cypress open 运行之前删除/删除屏幕截图