ruby - Authenticate_with_http_basic 块未执行
问题描述
我在我的 Rails 5.2 应用程序中观察到一些奇怪的行为,其中基本身份验证部分被跳过并且总是错误的。
此代码在本地开发环境下运行得非常好,但authenticate_with_http_basic
在 kubernetes 部署下永远不会遇到块。
Kubernetes 应用程序部署由 nginx 代理前置
class ApplicationController < ActionController::Base
before_action :authenticate
def authenticate
if _valid_credentials?
# never gets to this part
true
else
# enters the else block
request_http_basic_authentication
end
end
def _valid_credentials?
Rails.logger.debug("Function is entered")
authenticate_with_http_basic do |username, password|
cred = "#{username}|#{password}"
# Nothing is printed with Rails.logger.debug
Rails.logger.debug("Received credentials: #{cred}")
# Running rails console reveals the correct ::Configuration.credentials
SecureCompare.compare(cred, ::Configuration.credentials)
end
end
end
Kubernetes 日志:
nginx xxx.xxx.xx.xx 0.004 0.002930 - test_user [18/Jun/2019:20:11:26 +0000] "GET / HTTP/1.1" 401 38 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3829.0 Safari/537.36" b9af3f83-b2b8-43e1-bee7-1603f5ada6c2 -
app-deployment-name Processing by XXXController#index as HTML
app-deployment-name Function is entered
app-deployment-name Filter chain halted as :authenticate rendered or redirected
app-deployment-name Completed 401 Unauthorized in 0ms (ActiveRecord: 0.0ms)
欢迎任何想法或建议。
谢谢。
解决方案
推荐阅读
- reactjs - 反应让道具进入孩子
- c# - 使用类 Map 的字典在 C# 中使用多态性
- react-native - 有什么办法可以将 TabBar 放在我的标题上
- mongodb - 如何避免集合中的重复条目?
- bash - 用 MAKEFLAGS 覆盖包含空格的 make 变量
- sql - 需要帮助从 sql 内部联接获取 SUM 数据
- python - 比较熊猫组中的不同行
- gradle - 在 gradle 中解压 rpm
- apache-spark - 从数据块中的 mlflow-registry 加载模型时出现 InvalidMountException
- python - 如何使用 Kivy/Buildozer 在 Android 上请求 ACCESS_SURFACE_FLINGER 权限?