Skip to content

Commit d1d7134

Browse files
authored
Merge branch 'master' into release/1.17-pre
2 parents 38d9ad0 + 66936c9 commit d1d7134

File tree

7 files changed

+378
-5
lines changed

7 files changed

+378
-5
lines changed

src/apisix/ci/Dockerfile.apisix-test-busted

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|
1313
RUN yum install -y sudo make gcc curl wget unzip git valgrind
1414

1515
ARG APISIX_VERSION
16-
RUN curl https://raw.githubusercontent.com/apache/apisix/${APISIX_VERSION}/utils/linux-install-luarocks.sh | bash
16+
RUN wget https://raw.githubusercontent.com/apache/apisix/${APISIX_VERSION}/utils/linux-install-luarocks.sh && sed -i 's/3.8.0/3.12.0/g' linux-install-luarocks.sh && bash linux-install-luarocks.sh
1717
# lock the version of luasystem, otherwise the busted won't be installed success
1818
RUN luarocks install https://luarocks.org/manifests/lunarmodules/luasystem-0.2.1-0.rockspec
1919
RUN luarocks install https://github.com/lunarmodules/busted/releases/download/v2.1.1/busted-2.1.1-1.rockspec

src/apisix/ci/Dockerfile.apisix-test-nginx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG APISIX_VERSION="3.2.1"
22
FROM apache/apisix:$APISIX_VERSION-centos
33

44
# note: uncomment below if it's slow to build image
5-
# RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
5+
# RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
66
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo && \
77
# yum clean all
88

@@ -24,10 +24,10 @@ RUN sed -i 's#yum install -y openresty openresty-debug openresty-openssl111-debu
2424
RUN sed -i 's|https://registry.npm.taobao.org|https://registry.npmmirror.com|g' ${CODE_DIR}/t/plugin/grpc-web/package-lock.json
2525
# fix archived libs in luarocks
2626
RUN sed -i 's|lualdap = 1.2.6-1|lualdap = 1.4.0-1|g' ${CODE_DIR}/rockspec/apisix-master-0.rockspec
27-
RUN cd ${CODE_DIR} && bash ./ci/centos7-ci.sh install_dependencies
27+
RUN cd ${CODE_DIR} && sed -i 's/3.8.0/3.12.0/g' utils/linux-install-luarocks.sh && bash ./ci/centos7-ci.sh install_dependencies
2828
RUN cp -r ${CODE_DIR}/t /usr/local/apisix/
2929

30-
# the t/APISIX.pm:add_cleanup_handler will call it if the FLUSH_ETCD=1
30+
# the t/APISIX.pm:add_cleanup_handler will call it if the FLUSH_ETCD=1
3131
RUN ln -s /usr/local/apisix/deps/bin /usr/local/apisix/bin
3232

3333
# install etcd, we need to run in the container

src/apisix/plugins/bk-auth-verify.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ local function get_auth_params_from_header(ctx)
7171

7272
local auth_params = core.json.decode(authorization)
7373
if type(auth_params) ~= "table" then
74-
core.log.error("the invalid X-Bkapi-Authorization: ", core.json.delay_encode(authorization))
74+
core.log.warn("the invalid X-Bkapi-Authorization: ", core.json.delay_encode(authorization))
7575
return nil, "request header X-Bkapi-Authorization is not a valid JSON"
7676
end
7777

src/apisix/plugins/bk-auth-verify/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
local pl_types = require("pl.types")
2020
local access_token_verifier = require("apisix.plugins.bk-auth-verify.access-token-verifier")
2121
local jwt_verifier = require("apisix.plugins.bk-auth-verify.jwt-verifier")
22+
local inner_jwt_verifier = require("apisix.plugins.bk-auth-verify.inner-jwt-verifier")
2223
local legacy_verifier = require("apisix.plugins.bk-auth-verify.legacy-verifier")
2324
local bk_user_define = require("apisix.plugins.bk-define.user")
2425
local setmetatable = setmetatable
@@ -69,13 +70,17 @@ end
6970
function _M.get_real_verifier(self)
7071
local jwt_token = self.auth_params:get_string("jwt")
7172
local access_token = self.auth_params:get_string("access_token")
73+
local inner_jwt_token = self.auth_params:get_string("inner_jwt")
7274

7375
if not pl_types.is_empty(jwt_token) then
7476
return jwt_verifier.new(jwt_token, access_token)
7577

7678
elseif not pl_types.is_empty(access_token) then
7779
return access_token_verifier.new(access_token, self.bk_app)
7880

81+
elseif not pl_types.is_empty(inner_jwt_token) then
82+
return inner_jwt_verifier.new(inner_jwt_token)
83+
7984
else
8085
return legacy_verifier.new(self.bk_app, self.bk_api_auth, self.auth_params)
8186

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
--
2+
-- TencentBlueKing is pleased to support the open source community by making
3+
-- 蓝鲸智云 - API 网关(BlueKing - APIGateway) available.
4+
-- Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5+
-- Licensed under the MIT License (the "License"); you may not use this file except
6+
-- in compliance with the License. You may obtain a copy of the License at
7+
--
8+
-- http://opensource.org/licenses/MIT
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software distributed under
11+
-- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
-- either express or implied. See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- We undertake not to change the open source license (MIT license) applicable
16+
-- to the current version of the project delivered to anyone in the future.
17+
--
18+
19+
20+
-- verified the inner jwt token signed by bk-apigateway
21+
-- X-Bkapi-Authorization: {"inner_jwt": ""}
22+
-- currently it only be used in the mcp-proxy, which will proxy the request from agent to the real apigateway api
23+
-- so, after the bk-apigateway verified the app and user, it generate the inner_jwt and call the real apigateway api
24+
-- the app_code in inner_jwt is not the real app_code, but a virtual app_code(like v_mcp_{mcp_service_id}_{app_code})
25+
-- so the permission can be controlled by the virtual app_code,
26+
-- which not exists in the real PaaS, so no security concern.
27+
-- NOTE: the design of verifier is not so good, so here we parse_bk_jwt_token twice
28+
-- only refactor it if the performance is a problem
29+
30+
local bk_app_define = require("apisix.plugins.bk-define.app")
31+
local bk_user_define = require("apisix.plugins.bk-define.user")
32+
local jwt_utils = require("apisix.plugins.bk-auth-verify.jwt-utils")
33+
local string_format = string.format
34+
local setmetatable = setmetatable
35+
36+
local _M = {
37+
name = "inner-jwt",
38+
}
39+
40+
local mt = {
41+
__index = _M,
42+
}
43+
44+
function _M.new(inner_jwt_token)
45+
return setmetatable(
46+
{
47+
jwt_token = inner_jwt_token,
48+
}, mt
49+
)
50+
end
51+
52+
function _M.verify_app(self)
53+
local jwt_obj, err = jwt_utils.parse_bk_jwt_token(self.jwt_token)
54+
if jwt_obj == nil then
55+
return nil, string_format("parameter jwt is invalid: %s", err)
56+
end
57+
58+
if jwt_obj.header.kid ~= "bk-apigateway" then
59+
return nil, "invalid kid, only bk-apigateway is supported"
60+
end
61+
62+
local app_info = jwt_obj.payload.app
63+
if app_info == nil then
64+
return nil, "parameter jwt does not indicate app information"
65+
end
66+
if app_info.verified ~= true then
67+
return nil, "the app indicated by jwt is not verified"
68+
end
69+
70+
return bk_app_define.new_app(
71+
{
72+
app_code = app_info.app_code,
73+
exists = true,
74+
verified = true,
75+
}
76+
)
77+
end
78+
79+
function _M.verify_user(self)
80+
local jwt_obj, err = jwt_utils.parse_bk_jwt_token(self.jwt_token)
81+
if jwt_obj == nil then
82+
return nil, string_format("parameter jwt is invalid: %s", err)
83+
end
84+
85+
if jwt_obj.header.kid ~= "bk-apigateway" then
86+
return nil, "invalid kid, only bk-apigateway is supported"
87+
end
88+
89+
local user_info = jwt_obj.payload.user
90+
if user_info == nil then
91+
return bk_user_define.new_anonymous_user(
92+
"auth parameter does not indicate user information, verified by inner-jwt-verifier"
93+
)
94+
end
95+
96+
if user_info.verified ~= true then
97+
return bk_user_define.new_anonymous_user(
98+
"the user indicated by auth parameter is not verified, verified by inner-jwt-verifier"
99+
)
100+
end
101+
102+
return bk_user_define.new_user(
103+
{
104+
username = user_info.username,
105+
verified = true,
106+
source_type = "inner_jwt",
107+
}
108+
)
109+
end
110+
111+
return _M

src/apisix/tests/bk-auth-verify/test-init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ describe(
162162
end
163163
)
164164

165+
it(
166+
"inner-jwt-verifier", function()
167+
auth_params.inner_jwt = "fake-inner-jwt"
168+
169+
local verifier = bk_auth_verify:get_real_verifier()
170+
assert.is_equal(verifier.name, "inner-jwt")
171+
end
172+
)
173+
165174
it(
166175
"legacy verifier", function()
167176
local verifier = bk_auth_verify:get_real_verifier()

0 commit comments

Comments
 (0)