Skip to content
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

fix: fix and optimize tls in upstream_schema #10269

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,10 @@ local upstream_schema = {
},
},
dependencies = {
client_cert = {
required = {"client_key"},
["not"] = {required = {"client_cert_id"}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove the not condition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulbird please help to check this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The not condition is not required at both places client_cert and client_cert_id, having the not in clien_cert_id is enough to make both fields mutually exclusive. @monkeyDluffy6017

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Revolyssup said, there should only be the following three cases of the three properties(client_cert_id, client_cert, client_key) here:

  1. None of them exist
  2. Only client_cert, client_key
  3. Only client_cert_id
    The modified conditions can ensure that "client_cert" and "client_key" must exist at the same time, and three properties will not exist at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some test cases to cover these conditions?

},
client_key = {
required = {"client_cert"},
["not"] = {required = {"client_cert_id"}}
},
client_cert = {required = {"client_key"}},
client_key = {required = {"client_cert"}},
client_cert_id = {
["not"] = {required = {"client_client", "client_key"}}
["not"] = {required = {"client_cert", "client_key"}}
}
}
},
Expand Down
98 changes: 98 additions & 0 deletions t/core/schema_def.t
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,101 @@ qr/ok: false err: property "(id|plugins)" is required/
GET /t
--- response_body
passed



=== TEST 4: sanity check upstream_schema
--- config
location /t {
content_by_lua_block {
local schema_def = require("apisix.schema_def")
local core = require("apisix.core")
local t = require("lib.test_admin")
local ssl_cert = t.read_file("t/certs/apisix.crt")
local ssl_key = t.read_file("t/certs/apisix.key")
local upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1,
client_cert = ssl_cert,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)

upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)

upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert = ssl_cert,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)

upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)

upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert = ssl_cert
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)

upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)

ngx.say("passed")
}
}
--- response_body
passed