Skip to content

Commit

Permalink
add env support
Browse files Browse the repository at this point in the history
  • Loading branch information
soulbird committed Apr 7, 2023
1 parent f18e6b2 commit 804d4ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,15 @@ _M.ssl = {
},
cert = {
oneOf = {
{ type = "string", minLength = 128, maxLength = 64*1024},
certificate_scheme,
-- TODO: uniformly define the schema of secret_uri
{ type = "string", pattern = "^\\$secret://"}
{ type = "string", pattern = "^\\$(secret|env)://"}
}
},
key = {
oneOf = {
{ type = "string", minLength = 128, maxLength = 64*1024},
{ type = "string", pattern = "^\\$secret://"}
private_key_schema,
{ type = "string", pattern = "^\\$(secret|env)://"}
}
},
sni = {
Expand Down
3 changes: 2 additions & 1 deletion apisix/secret.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ local function check_secret_uri(secret_uri)
return false, "error secret_uri type: " .. type(secret_uri)
end

if not string.has_prefix(secret_uri, PREFIX) then
if not string.has_prefix(upper(secret_uri), PREFIX) and
not string.has_prefix(upper(secret_uri), core.env.PREFIX) then
return false, "error secret_uri prefix: " .. secret_uri
end

Expand Down
6 changes: 3 additions & 3 deletions apisix/ssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ function _M.check_ssl_conf(in_dp, conf)
end
end

-- if the certificate uses a secret reference, we only verify it when using it
if not secret.check_secret_uri(conf.cert) and
-- if the certificate or key uses a secret reference, we only verify it when using it
if not secret.check_secret_uri(conf.cert) or
not secret.check_secret_uri(conf.key) then

local ok, err = validate(conf.cert, conf.key)
Expand All @@ -274,7 +274,7 @@ function _M.check_ssl_conf(in_dp, conf)
end

for i = 1, numcerts do
if not secret.check_secret_uri(conf.cert[i]) and
if not secret.check_secret_uri(conf.cert[i]) or
not secret.check_secret_uri(conf.key[i]) then

local ok, err = validate(conf.certs[i], conf.keys[i])
Expand Down
2 changes: 1 addition & 1 deletion t/router/radixtree-sni2.t
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ GET /t
local code, body = t('/apisix/admin/ssls/1',
ngx.HTTP_PUT,
[[{
"cert": "$secret://vault/test1/ssl/test2.com.crt",
"cert": "$secret://vault/test1/ssl/test2.com.crt",
"key": "$secret://vault/test1/ssl/test2.com.key",
"sni": "test2.com"
}]]
Expand Down

0 comments on commit 804d4ec

Please sign in to comment.