Skip to content

Commit

Permalink
fix: hide 5xx error message from client (apache#6982)
Browse files Browse the repository at this point in the history
Co-authored-by: 高亮亮 <gll287546@alibaba-inc.com>
  • Loading branch information
2 people authored and Liu-Junlin committed May 20, 2022
1 parent 0a8b1c7 commit 8985e7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion apisix/plugins/authz-casbin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function _M.rewrite(conf, ctx)
-- creates an enforcer when request sent for the first time
local ok, err = new_enforcer_if_need(conf)
if not ok then
return 503, {message = err}
core.log.error(err)
return 503
end

local path = ctx.var.uri
Expand Down
18 changes: 10 additions & 8 deletions apisix/plugins/authz-keycloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ local function authz_keycloak_ensure_sa_access_token(conf)

if not token_endpoint then
log.error("Unable to determine token endpoint.")
return 500, "Unable to determine token endpoint."
return 503, "Unable to determine token endpoint."
end

local session = authz_keycloak_cache_get("access-tokens", token_endpoint .. ":"
Expand Down Expand Up @@ -451,7 +451,7 @@ local function authz_keycloak_ensure_sa_access_token(conf)
if not session then
-- No session available. Create a new one.

core.log.debug("Getting access token for Protection API from token endpoint.")
log.debug("Getting access token for Protection API from token endpoint.")
local httpc = authz_keycloak_get_http_client(conf)

local params = {
Expand Down Expand Up @@ -527,7 +527,7 @@ local function authz_keycloak_resolve_resource(conf, uri, sa_access_token)
if not resource_registration_endpoint then
local err = "Unable to determine registration endpoint."
log.error(err)
return 500, err
return 503, err
end

log.debug("Resource registration endpoint: ", resource_registration_endpoint)
Expand Down Expand Up @@ -572,7 +572,7 @@ local function evaluate_permissions(conf, ctx, token)
-- Ensure discovered data.
local err = authz_keycloak_ensure_discovered_data(conf)
if err then
return 500, err
return 503, err
end

local permission
Expand All @@ -581,7 +581,8 @@ local function evaluate_permissions(conf, ctx, token)
-- Ensure service account access token.
local sa_access_token, err = authz_keycloak_ensure_sa_access_token(conf)
if err then
return 500, err
log.error(err)
return 503
end

-- Resolve URI to resource(s).
Expand All @@ -591,7 +592,8 @@ local function evaluate_permissions(conf, ctx, token)
-- Check result.
if permission == nil then
-- No result back from resource registration endpoint.
return 500, err
log.error(err)
return 503
end
else
-- Use statically configured permissions.
Expand Down Expand Up @@ -636,7 +638,7 @@ local function evaluate_permissions(conf, ctx, token)
if not token_endpoint then
err = "Unable to determine token endpoint."
log.error(err)
return 500, err
return 503, err
end
log.debug("Token endpoint: ", token_endpoint)

Expand All @@ -663,7 +665,7 @@ local function evaluate_permissions(conf, ctx, token)
if not res then
err = "Error while sending authz request to " .. token_endpoint .. ": " .. err
log.error(err)
return 500, err
return 503
end

log.debug("Response status: ", res.status, ", data: ", res.body)
Expand Down
3 changes: 3 additions & 0 deletions t/plugin/authz-keycloak.t
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ passed
}
})

ngx.status = res.status

if res.status == 200 then
ngx.say(true)
else
Expand All @@ -339,6 +341,7 @@ GET /t
false
--- error_log
Error while sending authz request to https://127.0.0.1:8443/auth/realms/University/protocol/openid-connect/token: 18: self signed certificate
--- error_code: 503



Expand Down

0 comments on commit 8985e7f

Please sign in to comment.