feat: use env var instead of plain text for vault token#8866
Conversation
| - id: vault/1 | ||
| prefix: kv/apisix | ||
| token: root | ||
| token: "$ENV://VAULT_TOKEN" |
There was a problem hiding this comment.
So we can no longer use such a configuration?
token: root
There was a problem hiding this comment.
Yes, we won't be able to use such a configuration. Let me fix that quickly.
| export_or_prefix | ||
| make init | ||
| set_coredns | ||
| export VAULT_TOKEN="root" |
There was a problem hiding this comment.
| --- response_body | ||
| 0 | ||
| --- error_log | ||
| property "uri" validation failed: failed to match pattern "^[^\\/]+:\\/\\/([\\da-zA-Z.-]+|\\[[\\da-fA-F:]+\\])(:\\d+)?" |
There was a problem hiding this comment.
Why add this test case? It doesn't look like it has anything to do with your modification?
There was a problem hiding this comment.
I just duplicated all the test cases containing the token with just one change: replace the token with the environment variable. Let me do something better. 😂
| --- response_body | ||
| 0 | ||
| --- error_log | ||
| secret manager not exits |
| prefix: kv/apisix | ||
| token: $ENV://VAULT_TOKEN | ||
| uri: http://127.0.0.1:8200 | ||
|
|
There was a problem hiding this comment.
There is no need to add this test
|
|
||
|
|
||
|
|
||
| === TEST 21: secret.fetch_by_uri, no sub key value with the token in an env var |
There was a problem hiding this comment.
This test case already exists
| } | ||
| } | ||
| --- response_body | ||
| passed |
There was a problem hiding this comment.
You only configured the route, you also need to verify whether the route is effective
| # limitations under the License. | ||
| # | ||
| BEGIN { | ||
| $ENV{VAULT_TOKEN} = "root"; |
|
IMO, just adding a test case for t/secret/vault.t is enough. The test cases under t/plugin seem redundant, don't you think? |
I thought the same. But then I thought they would provide better safety from potential nasty bugs in the future. |
ok |
| local sub = core.string.sub | ||
| local rfind_char = core.string.rfind_char | ||
|
|
||
| local env = require("apisix.core.env") |
There was a problem hiding this comment.
Can't we import it like core.string.sub?
| @@ -26,6 +26,7 @@ local norm_path = require("pl.path").normpath | |||
| local sub = core.string.sub | |||
| local rfind_char = core.string.rfind_char | |||
|
|
|||
There was a problem hiding this comment.
We can avoid the blank line here? Other files don't add a blank line among localized variables.
Description
Currently, we use plain text to add
vaultas a secret resource. Like so:This PR implements a feature that would allow the use of environment variables in the following format:
$ENV://NAME_OF_ENV_VAR.This is the final outcome:
A part of #8319
cc: @soulbird
Checklist