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

request help: how to proxy grpc to grpcs. #1833

Closed
houshunwei opened this issue Jul 13, 2020 · 9 comments
Closed

request help: how to proxy grpc to grpcs. #1833

houshunwei opened this issue Jul 13, 2020 · 9 comments
Assignees

Comments

@houshunwei
Copy link
Contributor

houshunwei commented Jul 13, 2020

Issue description

I use Apisix as multi-cluster ingress as following picture shows. But I cannot go through ②,because apisix uses http to request upsterams by default。 Even I use proxy-rewrite plugins to force use https, it has the same error log in APISIX2 Cluster:

172.20.56.141 - - [13/Jul/2020:11:02:36 +0800] - "PRI * HTTP/2.0" - - 400 154 0.020 "-" "-" - - -

image

Client request has the following different flows:
cross cluster request: ① --> ② --> ④
same cluster request: ③ --> ④

What should I do? Can any one give me some hint?

I have some thoughts:
Thought One: do not use https when proxying grpc. but how to config?
Thought Two: trust cert of upsteram(it's APISIX2 here) but how?

Environment

  • apisix version (cmd: apisix version): 1.4
  • OS: docker, centos 7
@houshunwei houshunwei changed the title request help: request help: how can apisix trust cert of upstream (like insecure request). Jul 13, 2020
@houshunwei houshunwei changed the title request help: how can apisix trust cert of upstream (like insecure request). request help: how can apisix trust cert of upstream (like insecure request to upstream). Jul 13, 2020
@houshunwei
Copy link
Contributor Author

houshunwei commented Jul 13, 2020

I found this:proxy_ssl_verify off. I am testing it now.
---- I added it into location @grpc_pass of apisix bin file. but it does not work.

@houshunwei
Copy link
Contributor Author

actually,it's because following in apisix bin file:

grpc_pass         grpc://apisix_backend;

@membphis , do you has any hint to change so i can support grpc:// and grpcs:// according to route setting?

@houshunwei houshunwei changed the title request help: how can apisix trust cert of upstream (like insecure request to upstream). request help: how to proxy grpc to grpcs. Jul 13, 2020
@houshunwei
Copy link
Contributor Author

houshunwei commented Jul 13, 2020

I have resolved this problem:

First Try: extend proxy-rewrite(add grpc and grpcs scheme) and change apisix bin file:

location @grpc_pass {
            set $upstream_scheme             'grpc';
            access_by_lua_block {
                apisix.grpc_access_phase()
            }

            grpc_set_header   Content-Type application/grpc;
            grpc_socket_keepalive on;
            grpc_pass         $upstream_scheme://apisix_backend;
...

Problem: grpc_pass is different form proxy_pass, it cannot accept variable( which you defined by set).
Result: Failed.

Second Try:add other block in apisix bin file. and change judgement in init.lua

location @grpc_pass_ssl {
            access_by_lua_block {
                apisix.grpc_access_phase()
            }

            grpc_set_header   Content-Type application/grpc;
            grpc_socket_keepalive on;
            grpc_pass         grpcs://apisix_backend;
...

Result: It works!

I will close this issue now.

@membphis
Copy link
Member

welcome PR ^_^

@membphis membphis reopened this Jul 13, 2020
@houshunwei
Copy link
Contributor Author

welcome PR ^_^

The problem is: I use a tricky judgement in init.lua, which is not common.

Do you have any hint? Should I add a field to upstream to label it is grpcs?

@membphis
Copy link
Member

@houshunwei we can support the grpcs in this way:

https://github.com/apache/incubator-apisix/blob/master/apisix/init.lua#L280

we can take a look at this PR: #410

@houshunwei
Copy link
Contributor Author

@houshunwei we can support the grpcs in this way:

https://github.com/apache/incubator-apisix/blob/master/apisix/init.lua#L280

we can take a look at this PR: #410

It's not good to extend route.value.service_protocol enum. Because Route is more like 'Traffic Income' and Upstream is more like 'Traffic Out' 。 So if proxying to grpcs, it's better to use plugins or upstream?

above is what i confused about.

@membphis
Copy link
Member

grpc or grpcs is very different for route.value.service_protocol. I think it is fine.

we can not change the protocol dynamically in Nginx. we have to use the different location for this case.

@spacewander
Copy link
Member

Surpassed by #3344.

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

No branches or pull requests

3 participants