Repository navigation
Conversation
Reads $secret://file/<id>/<key> from <base_path>/<key>, for secrets mounted as files like a Kubernetes Secret volume. Keys can't be absolute or contain '..' segments, and one trailing newline is dropped. Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
| - [HashiCorp Vault](#使用-vault-管理密钥) | ||
| - [AWS Secrets Manager](#使用-aws-secrets-manager-管理密钥) | ||
| - [GCP Secrets Manager](#使用-gcp-secrets-manager-管理密钥) | ||
| - [文件](#使用文件管理密钥) |
There was a problem hiding this comment.
| - [文件](#使用文件管理密钥) | |
| - [File Secrets Manager](#使用文件管理密钥) |
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
There was a problem hiding this comment.
documentation and comments in English please
There was a problem hiding this comment.
The code and comments are in English. The zh file is the Chinese mirror of the English secret doc, like the other secret managers have, so I kept it in Chinese. Happy to drop it if you'd rather.
There was a problem hiding this comment.
Thanks for the explanation, as I could not read it, it was hard to determine if it contained info that was relevant.
| end | ||
|
|
||
| local path = base_path .. key | ||
| local content, err = core.io.get_file(path) |
There was a problem hiding this comment.
An empty file will lead to en empty string in LUA. So the get() will return succes. The content var will be "".
The if not content is a nill check not a empty string check. Adding a check for a emtpty string is an improvement for safety.
local content, err = core.io.get_file(path)
if not content then
return nil, "failed to read secret file: " .. (err or path .. ": no content")
end
if sub(content, -2) == "\r\n" then
content = sub(content, 1, -3)
elseif sub(content, -1) == "\n" then
content = sub(content, 1, -2)
end
if content == "" then
return nil, "secret file is empty: " .. path
end
There was a problem hiding this comment.
Good point, an empty file now returns an error (500cad9).
| two-lf: YWJjCg== | ||
| multi-line: bGluZTEKbGluZTI= | ||
|
|
||
|
|
There was a problem hiding this comment.
Added in 500cad9, empty file and a file with only a newline.
There was a problem hiding this comment.
Some extra test could be nice for completenes
- a test for a kubernetes symlink
- empty file see inline
- pointing a key to a directory
- file without permissions
There was a problem hiding this comment.
Added cases for a Kubernetes style symlink, an empty file and a directory in 500cad9. I skipped the no-permission one since CI usually runs as root and it wouldn't fail there. I couldn't run the Test::Nginx suite locally, so CI will be the first run.
There was a problem hiding this comment.
do we consider a empty file with a line ending as an empty file?
if sub(content, -2) == "\r\n" then
content = sub(content, 1, -3)
elseif sub(content, -1) == "\n" then
content = sub(content, 1, -2)
end
There was a problem hiding this comment.
Yes, the trailing newline is stripped first, so a file with just "\n" or "\r\n" ends up empty and is rejected the same way. The only-newline case in TEST 4b covers that.
jjansenvr
left a comment
There was a problem hiding this comment.
Nice work, looks solid!
Some minor remarks made but thanks for the work
…and directories Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
|
Yes, the newline gets stripped first and then the empty check runs, so a file with only a line ending is treated as empty. There's a test for that case too. |
Description
Adds a
filesecret manager so APISIX can read secrets that are mounted as files, like a Kubernetes Secret volume, instead of going through environment variables or an external manager. You add/apisix/admin/secrets/file/<id>with abase_path, and$secret://file/<id>/<key>resolves to the content of<base_path>/<key>.The key can point into subdirectories, but it can't start with
/or contain..segments, so a reference can't read outsidebase_path. One trailing newline is dropped since most tools add one. Values go through the normal secret LRU cache, so a rotated Secret is picked up after the TTL without a restart.Tests are in
t/secret/file.t(schema, key checks, reads, newline handling,fetch_by_uri, and key-auth with a file-backed key). Docs are in both en and zhterminology/secret.md, and the Admin API spec has aFileSecretschema withadmin-api.jsonregenerated bymake bundle-admin-api-spec.validate-admin-api.pyandt/openapipass.Which issue(s) this PR fixes:
Fixes #14099
Checklist