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

feat: add option debug to conf headers to disable kong_debug header function #10054

Merged
merged 10 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
to `Method not allowed`, make the reponse to show more clearly that Kong do not support
TRACE method.
[#9448](https://github.com/Kong/kong/pull/9448)
- Add debug_header kong conf to disable kong_debug header function, default set to off
[#10054](https://github.com/Kong/kong/pull/10054)


### Additions
Expand Down
7 changes: 7 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,13 @@
# connection may be kept open
# indefinitely.

#debug_header = off # Enable the `kong-debug` header function
# if it is `on`, kong will add debug header
# `Kong-Route-Id` `Kong-Route-Name` `Kong-Service-Id`
# `Kong-Service-Name` when client request
# header `kong-debug = 1` is set
# default is `off`

#------------------------------------------------------------------------------
# NGINX injected directives
#------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ local CONF_INFERENCES = {
upstream_keepalive_pool_size = { typ = "number" },
upstream_keepalive_max_requests = { typ = "number" },
upstream_keepalive_idle_timeout = { typ = "number" },
debug_header = { typ = "boolean" },

headers = { typ = "array" },
trusted_ips = { typ = "array" },
Expand Down
4 changes: 4 additions & 0 deletions kong/router/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ local function add_debug_headers(var, header, match_t)
return
end

if not kong.configuration.debug_header then
return
end

local route = match_t.route
if route then
if route.id then
Expand Down
1 change: 1 addition & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ error_default_type = text/plain
upstream_keepalive_pool_size = 60
upstream_keepalive_max_requests = 100
upstream_keepalive_idle_timeout = 60
debug_header = off

nginx_user = kong kong
nginx_worker_processes = auto
Expand Down
1 change: 1 addition & 0 deletions spec/01-unit/03-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe("Configuration loader", function()
assert.same({}, conf.admin_ssl_cert_key)
assert.same({}, conf.status_ssl_cert)
assert.same({}, conf.status_ssl_cert_key)
assert.same(false, conf.debug_header)
assert.is_nil(getmetatable(conf))
end)
it("loads a given file, with higher precedence", function()
Expand Down
68 changes: 68 additions & 0 deletions spec/02-integration/05-proxy/02-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ for _, strategy in helpers.each_strategy() do
plugins = "bundled,enable-buffering",
nginx_conf = "spec/fixtures/custom_nginx.template",
stream_listen = string.format("127.0.0.1:%d ssl", stream_tls_listen_port),
debug_header = true,
}, nil, nil, fixtures))
end)

Expand Down Expand Up @@ -2278,6 +2279,7 @@ for _, strategy in helpers.each_strategy() do
nginx_worker_processes = 4,
plugins = "bundled,enable-buffering",
nginx_conf = "spec/fixtures/custom_nginx.template",
debug_header = true,
}))
end)

Expand Down Expand Up @@ -2387,6 +2389,72 @@ for _, strategy in helpers.each_strategy() do
end)
end)
end

describe("disable debug_header config" , function()
local proxy_client

lazy_setup(function()
local bp = helpers.get_db_utils(strategy, {
"routes",
"services",
"plugins",
}, {
"enable-buffering",
})

bp.routes:insert({
methods = { "GET" },
protocols = { "http" },
strip_path = false,
})

if enable_buffering then
bp.plugins:insert {
name = "enable-buffering",
protocols = { "http", "https", "grpc", "grpcs" },
}
end

assert(helpers.start_kong({
router_flavor = flavor,
database = strategy,
nginx_worker_processes = 4,
plugins = "bundled,enable-buffering",
nginx_conf = "spec/fixtures/custom_nginx.template",
}))
end)

lazy_teardown(function()
helpers.stop_kong()
end)

before_each(function()
proxy_client = helpers.proxy_client()
end)

after_each(function()
if proxy_client then
proxy_client:close()
end
end)

it("disable debug_header config", function()
for _ = 1, 1000 do
proxy_client = helpers.proxy_client()
local res = assert(proxy_client:send {
method = "GET",
path = "/get",
headers = { ["kong-debug"] = 1 },
})

assert.response(res).has_status(200)

assert.is_nil(res.headers["kong-service-name"])
assert.is_nil(res.headers["kong-route-name"])
proxy_client:close()
end
end)
end)
end
end
end