我正在尝试在 ELK 安装之前设置 OAuth2 授权。 我正在使用 oauth2_proxy。这个想法是使用 Google 作为 SSO,从 SSO 质询中提取用户名,将此用户名设置为基本身份验证(使用固定密码)以登录 Kibana。
我很难获取用户名并将其设置到基本身份验证字符串中。看来变量
$remote_user
没有被重视。如果我硬编码一个有效的用户名:密码,它会让我登录。
这是我到目前为止的配置:
类似这样的:
这里是conf文件:
oauth2_proxy 启动字符串
oauth2-proxy
--email-domain="example.com"
--upstream="http://127.0.0.1:8080/"
--approval-prompt="auto"
--redirect-url="https://example.com/oauth2/callback"
--cookie-secret=redacted
--set-xauthrequest=true
--pass-user-headers=true
--pass-authorization-header=true
oauth2_proxy.conf
server {
listen 443 ssl;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:4180;
}
[letsencrypt config omitted]
}
kibana.conf
server {
listen 8080;
location / {
proxy_pass http://127.0.0.1:5601;
set $auth_string "${remote_user}:<my_strong-password>";
set_encode_base64 $encoded_string $auth_string;
proxy_set_header Authorization "Basic $encoded_string";
#to manage logout redirect
rewrite /login https://example.com/oauth2/sign_in redirect;
}
}
我的问题是
${remote_user}
是空的,我该如何评估它?我也尝试过 $upstream_http_x_auth_request_user
和 $upstream_http_x_auth_request_email
但没有运气。
您发现任何明显的错误吗?
如果在 nginx 配置中指定了固定密码,为什么还需要提取用户名?
您可以在 Kibana 配置中启用匿名访问并摆脱 nginx 代理。详细请看这个答案: https://stackoverflow.com/a/75416817/3758005
对于如此严重的延误,我深表歉意;我完全忘记了分享解决方案。
/etc/openresty/sites-available/oauth2_proxy.conf
server {
listen 443 ssl;
server_name <my-elasticstack-url>;
#kibana
location / {
proxy_pass http://127.0.0.1:4180;
}
[letsencrypt config omitted]
}
/etc/openresty/sites-available/kibana.conf
server {
listen 8080;
location / {
proxy_pass http://127.0.0.1:5601;
set $email $http_x_forwarded_email;
set $username '';
set $password '<my_static_password>'; #same password for all users, configured in kibana
set $auth_string '';
set $encoded_string '';
access_by_lua_block {
ngx.var.username = ngx.var.email:match("[^@]+");
ngx.var.auth_string = ngx.var.username .. ":" .. ngx.var.password;
#function to base64 encode the header
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
ngx.var.encoded_string = enc(ngx.var.auth_string);
}
proxy_set_header Authorization "Basic $encoded_string";
rewrite /login https://<my-elasticstack-url>/oauth2/sign_in redirect;
}
}
oauth2_proxy 启动字符串
配置为服务
oauth2-proxy
--email-domain="<my_email_domain>"
--upstream="http://127.0.0.1:8080/"
--approval-prompt="auto"
--redirect-url="https://<my-elasticstack-url>/oauth2/callback"
--cookie-secret=<my_cookie_secret>
--cookie-name="_oauth2_proxy"
--cookie-secure=false
--provider=google
--client-id="<my_client_id>"
--client-secret="<my_client_secret>"
--set-xauthrequest=true