Skip to content

Commit 727de7f

Browse files
windmgcgithub-actions[bot]
authored andcommitted
fix(vault): let vault entity cache key not containing workspace id (#13610)
This PR modifies the `cache_key` function of the vault entity to always generate a cache key without workspace id. Vault entity is workspace-able, but our secret rotation timer always run without workspace settings(thus the default workspace is being used), so during secret rotation, the code https://github.com/Kong/kong/blob/4e38b965b922f57febe8652fb96b7d74aeab591a/kong/pdk/vault.lua#L620-L621 will generate a duplicate vault cache with default workspace id for each non-default workspace vault entity, and those cache will never be refreshed. The result of this issue is that when you update a vault entity's configuration inside a non-default workspace, it will never take effect in the secret rotation. Since the prefix of vault entity is unique across workspaces, it should be safe to only use one cache key without workspace id, so that the correct cache is used during secret rotation. FTI-6152 (cherry picked from commit 3455151)
1 parent c983384 commit 727de7f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
message: |
2+
**Vault**: Fixed an issue where updating a vault entity in a non-default workspace will not take effect.
3+
type: bugfix
4+
scope: Core

kong/db/dao/vaults.lua

+10
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,14 @@ function Vaults:load_vault_schemas(vault_set)
8484
end
8585

8686

87+
function Vaults:cache_key(prefix)
88+
if type(prefix) == "table" then
89+
prefix = prefix.prefix
90+
end
91+
92+
-- Always return the cache_key without a workspace because prefix is unique across workspaces
93+
return "vaults:" .. prefix .. ":::::"
94+
end
95+
96+
8797
return Vaults

spec/02-integration/13-vaults/01-vault_spec.lua

+5
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,10 @@ for _, strategy in helpers.each_strategy() do
175175
assert.is_equal("{vault://unknown/missing-key}", certificate.key_alt)
176176
assert.is_nil(certificate["$refs"])
177177
end)
178+
179+
it("generate correct cache key", function ()
180+
local cache_key = db.vaults:cache_key("test")
181+
assert.equal("vaults:test:::::", cache_key)
182+
end)
178183
end)
179184
end

0 commit comments

Comments
 (0)