Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide 5xx error message from client #6982

Merged
merged 18 commits into from May 5, 2022
Merged
3 changes: 2 additions & 1 deletion apisix/plugins/authz-casbin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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