Skip to content

Commit

Permalink
Fix bug when auth req is enabled(external authentication) (#2280)
Browse files Browse the repository at this point in the history
* set proxy_upstream_name correctly when auth_req module is used

* log a more meaningful message when backend is not found
  • Loading branch information
ElvinEfendi authored and aledbf committed Mar 30, 2018
1 parent bcb162a commit 931e541
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/file/bindata.go

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion rootfs/etc/nginx/lua/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ end

local function get_current_backend()
local backend_name = ngx.var.proxy_upstream_name
return backends:get(backend_name)
local backend = backends:get(backend_name)

if not backend then
ngx.log(ngx.WARN, "no backend configuration found for " .. tostring(backend_name))
end

return backend
end

local function get_current_lb_alg()
Expand Down
6 changes: 5 additions & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ stream {
{{ if $authPath }}
location = {{ $authPath }} {
internal;
set $proxy_upstream_name "external-authentication";

# ngx_auth_request module overrides variables in the parent request,
# therefore we have to explicitly set this variable again so that when the parent request
# resumes it has the correct value set for this variable so that Lua can pick backend correctly
set $proxy_upstream_name "{{ buildUpstreamName $server.Hostname $all.Backends $location }}";

proxy_pass_request_body off;
proxy_set_header Content-Length "";
Expand Down

0 comments on commit 931e541

Please sign in to comment.