-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use env var instead of plain text for vault token #8866
feat: use env var instead of plain text for vault token #8866
Conversation
t/config-center-yaml/secret.t
Outdated
@@ -61,7 +61,7 @@ __DATA__ | |||
secrets: | |||
- id: vault/1 | |||
prefix: kv/apisix | |||
token: root | |||
token: "$ENV://VAULT_TOKEN" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can no longer use such a configuration?
token: root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we won't be able to use such a configuration. Let me fix that quickly.
ci/centos7-ci.sh
Outdated
@@ -84,6 +84,7 @@ run_case() { | |||
export_or_prefix | |||
make init | |||
set_coredns | |||
export VAULT_TOKEN="root" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t/config-center-yaml/secret.t
Outdated
--- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. 😂
t/config-center-yaml/secret.t
Outdated
--- response_body | ||
0 | ||
--- error_log | ||
secret manager not exits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
t/config-center-yaml/secret.t
Outdated
prefix: kv/apisix | ||
token: $ENV://VAULT_TOKEN | ||
uri: http://127.0.0.1:8200 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to add this test
t/config-center-yaml/secret.t
Outdated
|
||
|
||
|
||
=== TEST 21: secret.fetch_by_uri, no sub key value with the token in an env var |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case already exists
} | ||
} | ||
--- response_body | ||
passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only configured the route, you also need to verify whether the route is effective
t/config-center-yaml/secret.t
Outdated
@@ -14,6 +14,10 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
BEGIN { | |||
$ENV{VAULT_TOKEN} = "root"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apisix/secret/vault.lua
Outdated
@@ -26,6 +26,7 @@ local norm_path = require("pl.path").normpath | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we import it like core.string.sub
?
apisix/secret/vault.lua
Outdated
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
vault
as 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