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

feat: add proxy_ssl_server_name #3084

Closed
wants to merge 2 commits into from
Closed

feat: add proxy_ssl_server_name #3084

wants to merge 2 commits into from

Conversation

whitehatboxer
Copy link

@whitehatboxer whitehatboxer commented Dec 21, 2020

What this PR does / why we need it:

fix: #2988

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@whitehatboxer whitehatboxer changed the title feature: add proxy_ssl_server_name to support carry SNI while doing SSL handshaking with upstream feature: add proxy_ssl_server_name Dec 21, 2020
@juzhiyuan juzhiyuan changed the title feature: add proxy_ssl_server_name feat: add proxy_ssl_server_name Dec 21, 2020
@@ -174,6 +174,8 @@ nginx_config: # config for render the template to generate n
# lua_shared_dicts: # add custom shared cache to nginx.conf
# ipc_shared_dict: 100m # custom shared cache, format: `cache-key: cache-size`

proxy_ssl_server_name: false # disable passing of the server name through tls
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be enabled by default.

Copy link
Author

Choose a reason for hiding this comment

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

I will fix it later.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

conf/config-default.yaml Outdated Show resolved Hide resolved
@membphis membphis requested a review from tokers January 11, 2021 10:16
@@ -174,6 +174,8 @@ nginx_config: # config for render the template to generate n
# lua_shared_dicts: # add custom shared cache to nginx.conf
# ipc_shared_dict: 100m # custom shared cache, format: `cache-key: cache-size`

proxy_ssl_server_name: true # disable passing of the server name through tls
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is not right. Just reference the Nginx doc:

Enables or disables passing of the server name through TLS Server Name Indication extension (SNI, RFC 6066) when establishing a connection with the proxied HTTPS server.

Copy link
Author

Choose a reason for hiding this comment

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

I will fix it later.

Copy link
Author

Choose a reason for hiding this comment

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

Already replace it.

@tokers
Copy link
Contributor

tokers commented Jan 20, 2021

@unbeatablekb Should have test cases for it, you can prepare a keypair that the SNI is not matched with the backend server and assert the proxy is aborted.

@whitehatboxer
Copy link
Author

@tokers Thanks for giving help. I will add test for it after learning nginx test which would be done within this weeks.

@spacewander
Copy link
Member

@unbeatablekb
You need to add proxy_ssl_server_name in t/APISIX.pm.
You can take a look at

=== TEST 8: set route(rewrite host + scheme)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"proxy-rewrite": {
"uri": "/plugin_proxy_rewrite",
"scheme": "https",
"host": "test.com"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1983": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 9: rewrite host + scheme
--- request
GET /hello HTTP/1.1
--- response_body
uri: /plugin_proxy_rewrite
host: test.com
scheme: https
--- no_error_log
[error]
and write your own one.

@whitehatboxer
Copy link
Author

@spacewander Thanks for your advice. I will do it.

@whitehatboxer
Copy link
Author

@tokers @spacewander
The deadline took effect. I try to learn the test architecture about apisix at last weekends.

Finally I add test cases in t/core. I'm willing to hear your advice and I will modify it in the day.

@membphis
Copy link
Member

@tokers @spacewander
The deadline took effect. I try to learn the test architecture about apisix at last weekends.

Finally I add test cases in t/core. I'm willing to hear your advice and I will modify it in the day.

if you need any help, please let us know

@tokers
Copy link
Contributor

tokers commented Jan 26, 2021

@unbeatablekb CI failed.

t/APISIX.pm Outdated
@@ -384,6 +384,24 @@ _EOC_
}
}

server {
listen 1985 ssl;
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this. We already have a HTTPS backend:

listen 1983 ssl;

You just need to pass a wrong host header.

Copy link
Author

@whitehatboxer whitehatboxer Jan 26, 2021

Choose a reason for hiding this comment

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

Thanks. I used to create a new server block because I want to add server_name to new block. Now I think this make no sense after thinking about it.

But you said I could write a new one in APISIX.pm. What does that means?

image

@whitehatboxer
Copy link
Author

whitehatboxer commented Jan 26, 2021

@tokers @spacewander
I need your help. I run my test locally but failed.

The TEST2's output all failed. But I don't know what's wrong wit it.

I already pushed the code and details of the output of running test are show blow.

image

GET /hello
--- error_code: 502
--- error_log
ssl
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how you assert the 502 is due to SSL handshaking failure.

Copy link
Author

Choose a reason for hiding this comment

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

Got it.

@spacewander
Copy link
Member

Only enable proxy_ssl_server_name doesn't pass the correct SNI to the backend.
See #2988 (comment).

I have submitted a new one to surpass this PR: #3420

@unbeatablekb
Your contribution is still counted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Carry SNI while doing SSL handshaking with upstream
4 participants