Skip to content

Commit

Permalink
fix(conf) infer vault references
Browse files Browse the repository at this point in the history
### Summary

Kong escapes e.g. `"#"` with `"\#"`, and these need to be removed before
passing them to vault functions as otherwise reference like:

```
{vault://env/pg-password#1}
```

Doesn't work as it gets past as:

```
{vault://env/pg-password\#1}
```

This fixes that.
  • Loading branch information
bungle committed May 4, 2022
1 parent 2554988 commit 79ad5fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1539,13 +1539,14 @@ local function load(path, custom_conf, opts)
local vault_conf = { loaded_vaults = loaded_vaults }
for k, v in pairs(conf) do
if sub(k, 1, 6) == "vault_" then
vault_conf[k] = v
vault_conf[k] = infer_value(v, "string", opts)
end
end

local vault = require("kong.pdk.vault").new({ configuration = vault_conf })

for k, v in pairs(conf) do
v = infer_value(v, "string", opts)
if vault.is_reference(v) then
if refs then
refs[k] = v
Expand Down
4 changes: 2 additions & 2 deletions spec/01-unit/03-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1742,11 +1742,11 @@ describe("Configuration loader", function()
helpers.setenv("PG_PORT", "5000")

local conf = assert(conf_loader(nil, {
pg_port = "{vault://env/pg-port}"
pg_port = "{vault://env/pg-port#0}"
}))

assert.equal(5000, conf.pg_port)
assert.equal("{vault://env/pg-port}", conf["$refs"].pg_port)
assert.equal("{vault://env/pg-port#0}", conf["$refs"].pg_port)
end)
end)
end)

0 comments on commit 79ad5fc

Please sign in to comment.