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(llm): delete unused request header when ai upstream provider is a… #14009

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/ai-proxy-azure-headers-limit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**ai-proxy**: Fixed an issue where Azure service limit the request customer headers number was not being respected from kong."
type: bugfix
scope: Plugin
19 changes: 19 additions & 0 deletions kong/llm/drivers/azure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ local string_gsub = string.gsub
local DRIVER_NAME = "azure"
--

local do_not_clear_headers = {
["host"] = true,
["content-length"] = true,
["transfer-encoding"] = true,
["connection"] = true,
["accept-encoding"] = true,
["content-type"] = true,
["accept"] = true,
["user-agent"] = true,
Copy link
Contributor

@tysoekong tysoekong Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many auth headers that also should not be cleared.

This change worries me. I think we gotta make sure all Azure auth mechanisms still work.

}


_M.from_format = openai_driver.from_format
_M.to_format = openai_driver.to_format
_M.header_filter_hooks = openai_driver.header_filter_hooks
Expand Down Expand Up @@ -140,6 +152,13 @@ function _M.configure_request(conf)
end
end

local request_headers = kong.request.get_headers()
for k, _ in pairs(request_headers) do
if not do_not_clear_headers[k] and k ~= auth_header_name then
kong.service.request.clear_header(k)
end
end


local query_table = kong.request.get_query()

Expand Down
6 changes: 6 additions & 0 deletions spec/03-plugins/38-ai-proxy/05-azure_integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ for _, strategy in helpers.all_strategies() do
local pl_file = require "pl.file"
local json = require("cjson.safe")

local headers = ngx.req.get_headers()
ngx.header["X-request-headers"] = json.encode(headers)

local token = ngx.req.get_headers()["api-key"]
if token == "azure-key" then
ngx.req.read_body()
Expand Down Expand Up @@ -452,6 +455,7 @@ for _, strategy in helpers.all_strategies() do
headers = {
["content-type"] = "application/json",
["accept"] = "application/json",
["X-NEED-DELETED"] = "deleted",
},
body = pl_file.read("spec/fixtures/ai-proxy/openai/llm-v1-chat/requests/good.json"),
})
Expand All @@ -471,6 +475,8 @@ for _, strategy in helpers.all_strategies() do
content = "The sum of 1 + 1 is 2.",
role = "assistant",
}, json.choices[1].message)
--- check that the request headers wired header was clear from kong process
assert.is_nil(r.headers["X-NEED-DELETED"])
end)

it("good request with client right auth", function()
Expand Down
Loading