Skip to content

Commit

Permalink
feat(clustering/rpc): add support for cert details (#14050)
Browse files Browse the repository at this point in the history
Follow up of #14046

KAG-6084
  • Loading branch information
chronolaw authored Dec 30, 2024
1 parent d303ae6 commit 0ebc358
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 8 additions & 2 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ end


-- CP => DP
function _M:_handle_meta_call(c)
function _M:_handle_meta_call(c, cert)
local data, typ, err = c:recv_frame()
if err then
return nil, err
Expand Down Expand Up @@ -226,11 +226,17 @@ function _M:_handle_meta_call(c)
end
end

-- values in cert_details must be strings
local cert_details = {
expiry_timestamp = cert:get_not_after(),
}

-- store DP's ip addr
self.client_info[node_id] = {
ip = ngx_var.remote_addr,
version = info.kong_version,
labels = labels,
cert_details = cert_details,
}

return node_id
Expand Down Expand Up @@ -450,7 +456,7 @@ function _M:handle_websocket()
end

-- if timeout (default is 5s) we will close the connection
local node_id, err = self:_handle_meta_call(wb)
local node_id, err = self:_handle_meta_call(wb, cert)
if not node_id then
ngx_log(ngx_ERR, _log_prefix, "unable to handshake with client: ", err)
return ngx_exit(ngx.HTTP_CLOSE)
Expand Down
1 change: 1 addition & 0 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function _M:init_cp(manager)
ip = node_info.ip, -- get the correct ip
version = node_info.version, -- get from rpc call
labels = node_info.labels, -- get from rpc call
cert_details = node_info.cert_details, -- get from rpc call
sync_status = CLUSTERING_SYNC_STATUS.NORMAL,
config_hash = fmt("%032d", default_namespace_version),
rpc_capabilities = rpc_peers and rpc_peers[node_id] or {},
Expand Down
12 changes: 2 additions & 10 deletions spec/02-integration/09-hybrid_mode/01-sync_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,7 @@ describe("CP/DP cert details(cluster_mtls = shared) #" .. strategy, function()

for _, v in pairs(json.data) do
if v.ip == "127.0.0.1" then
-- TODO: The API output does include labels and certs when the
-- rpc sync is enabled.
if rpc_sync == "off" then
assert.equal(1888983905, v.cert_details.expiry_timestamp)
end
assert.equal(1888983905, v.cert_details.expiry_timestamp)
return true
end
end
Expand Down Expand Up @@ -930,11 +926,7 @@ describe("CP/DP cert details(cluster_mtls = pki) #" .. strategy, function()

for _, v in pairs(json.data) do
if v.ip == "127.0.0.1" then
-- TODO: The API output does include labels and certs when the
-- rpc sync is enabled.
if rpc_sync == "off" then
assert.equal(1897136778, v.cert_details.expiry_timestamp)
end
assert.equal(1897136778, v.cert_details.expiry_timestamp)
return true
end
end
Expand Down

1 comment on commit 0ebc358

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Bazel Build

Docker image available kong/kong:0ebc358063569cb08bba8e8bdf1586c2146ed9a0
Artifacts available https://github.com/Kong/kong/actions/runs/12540931073

Please sign in to comment.