You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jf...@apache.org on 2017/07/11 11:41:44 UTC

svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Author: jfclere
Date: Tue Jul 11 11:41:44 2017
New Revision: 1801594

URL: http://svn.apache.org/viewvc?rev=1801594&view=rev
Log:

Add logic to read the Upgrade header and use it in the response.
Use we you are proxying to a server that has multiple upgrade on the same IP/Port.
PR 61142

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_proxy_wstunnel.xml
    httpd/httpd/trunk/modules/proxy/mod_proxy_wstunnel.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_proxy_wstunnel.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_proxy_wstunnel.xml?rev=1801594&r1=1801593&r2=1801594&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_proxy_wstunnel.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_proxy_wstunnel.xml Tue Jul 11 11:41:44 2017
@@ -55,7 +55,9 @@ ProxyPass "/wss2/" "wss://echo.websocket
 <p>In fact the module can be used to upgrade to other protocols, you can set the <code>upgrade</code>
 parameter in the <directive type="ProxyPass" module="mod_proxy">ProxyPass</directive>
 directive to allow the module to accept other protocol.
-NONE means you bypass the check for the header but still upgrade to WebSocket.</p>
+NONE means you bypass the check for the header but still upgrade to WebSocket.
+ANY means that <code>Upgrade</code> will read in the request headers and use
+in the response <code>Upgrade</code></p>
 </summary>
 
 <seealso><module>mod_proxy</module></seealso>

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_wstunnel.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_wstunnel.c?rev=1801594&r1=1801593&r2=1801594&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_wstunnel.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_wstunnel.c Tue Jul 11 11:41:44 2017
@@ -329,6 +329,10 @@ static int proxy_wstunnel_request(apr_po
 
     if (ap_cstr_casecmp(upgrade_method, "NONE") == 0) {
         buf = apr_pstrdup(p, "Upgrade: WebSocket" CRLF "Connection: Upgrade" CRLF CRLF);
+    } else if (ap_cstr_casecmp(upgrade_method, "ANY") == 0) {
+        const char *upgrade;
+        upgrade = apr_table_get(r->headers_in, "Upgrade");
+        buf = apr_pstrcat(p, "Upgrade: ", upgrade, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
     } else {
         buf = apr_pstrcat(p, "Upgrade: ", upgrade_method, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
     }
@@ -473,7 +477,8 @@ static int proxy_wstunnel_handler(reques
     if (ap_cstr_casecmp(upgrade_method, "NONE") != 0) {
         const char *upgrade;
         upgrade = apr_table_get(r->headers_in, "Upgrade");
-        if (!upgrade || ap_cstr_casecmp(upgrade, upgrade_method) != 0) {
+        if (!upgrade || (ap_cstr_casecmp(upgrade, upgrade_method) != 0 &&
+            ap_cstr_casecmp(upgrade_method, "ANY") !=0)) {
             ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02900)
                           "declining URL %s  (not %s, Upgrade: header is %s)", 
                           url, upgrade_method, upgrade ? upgrade : "missing");



Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by jean-frederic clere <jf...@gmail.com>.
On 01/11/2019 21:15, Yann Ylavic wrote:
> Hi Jean-Frédéric,
> 
> sorry to dig up an old commit, I'm currently working on integrating
> wstunnel into mod_proxy_http and wondering what is the use case for
> upgrade=NONE. Please see below...

The upgrade=NONE was added to work around 
https://issues.jboss.org/browse/JBCS-291, I will dig again in the 
problem later today.

> 
> On Thu, Jul 13, 2017 at 2:58 PM jean-frederic clere <jf...@gmail.com> wrote:
>>
>> On 07/12/2017 07:25 PM, Jacob Champion wrote:
>>> On 07/11/2017 05:36 AM, Yann Ylavic wrote:
>>>> I think it's quite hazardous to use/allow ANY and would prefer the
>>>> upgrade_method (worker->s->upgrade) to be a list of acceptable protocols.
>>>
>>> I think both ANY *and* NONE are dangerous. Both of them turn
>>> proxy_wstunnel into a generic TCP forwarder (and NONE does so without
>>> any opt-in on the client's part).
> 
> I see some possible use of upgrade=ANY (tunnel any protocol after the
> upgrade, no restriction), but NONE is bypassing the check for the
> client Upgrade header and act as if it were Websocket. Why would we
> upgrade a connection if the client does not ask for it?
> 
>>
>> So how I have the following to proxy:
>> <request>
>> GET /jboss-websocket-hello/websocket/helloName HTTP/1.1
> [snip]
>> Connection: keep-alive, Upgrade
> [snip]
>> Upgrade: websocket
> [snip]
>> </request>
>>
>> <response>
>> HTTP/1.1 101
>> Upgrade: websocket
>> Connection: upgrade
> [snip]
>> </response>
>>
>> ...,..9e...,.$.H...W(I-.QH+..U(OM*.O.N-QH.K)...+..
>> Tomcat web socket stuff...
>>
>> So yes the HTTP/1.1 really needs to upgrade and NONE is just a work-around.
> 
> The above is some usual Websocket upgrade AFAICT, don't
> upgrade=websocket or upgrade=any or even no upgrade at all work in
> this case?
> 
> Regards,
> Yann.
> 


-- 
Cheers

Jean-Frederic

Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by Yann Ylavic <yl...@gmail.com>.
Hi Jean-Frédéric,

sorry to dig up an old commit, I'm currently working on integrating
wstunnel into mod_proxy_http and wondering what is the use case for
upgrade=NONE. Please see below..

On Thu, Jul 13, 2017 at 2:58 PM jean-frederic clere <jf...@gmail.com> wrote:
>
> On 07/12/2017 07:25 PM, Jacob Champion wrote:
> > On 07/11/2017 05:36 AM, Yann Ylavic wrote:
> >> I think it's quite hazardous to use/allow ANY and would prefer the
> >> upgrade_method (worker->s->upgrade) to be a list of acceptable protocols.
> >
> > I think both ANY *and* NONE are dangerous. Both of them turn
> > proxy_wstunnel into a generic TCP forwarder (and NONE does so without
> > any opt-in on the client's part).

I see some possible use of upgrade=ANY (tunnel any protocol after the
upgrade, no restriction), but NONE is bypassing the check for the
client Upgrade header and act as if it were Websocket. Why would we
upgrade a connection if the client does not ask for it?

>
> So how I have the following to proxy:
> <request>
> GET /jboss-websocket-hello/websocket/helloName HTTP/1.1
[snip]
> Connection: keep-alive, Upgrade
[snip]
> Upgrade: websocket
[snip]
> </request>
>
> <response>
> HTTP/1.1 101
> Upgrade: websocket
> Connection: upgrade
[snip]
> </response>
>
> ...,..9e...,.$.H...W(I-.QH+..U(OM*.O.N-QH.K)...+..
> Tomcat web socket stuff...
>
> So yes the HTTP/1.1 really needs to upgrade and NONE is just a work-around.

The above is some usual Websocket upgrade AFAICT, don't
upgrade=websocket or upgrade=any or even no upgrade at all work in
this case?

Regards,
Yann.

Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by jean-frederic clere <jf...@gmail.com>.
On 07/12/2017 07:25 PM, Jacob Champion wrote:
> On 07/11/2017 05:36 AM, Yann Ylavic wrote:
>> I think it's quite hazardous to use/allow ANY and would prefer the
>> upgrade_method (worker->s->upgrade) to be a list of acceptable protocols.
> 
> I think both ANY *and* NONE are dangerous. Both of them turn
> proxy_wstunnel into a generic TCP forwarder (and NONE does so without
> any opt-in on the client's part).

So how I have the following to proxy:
<request>
GET /jboss-websocket-hello/websocket/helloName HTTP/1.1

Host: localhost:8080

User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0)
Gecko/20100101 Firefox/53.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.7,ca;q=0.3

Accept-Encoding: gzip, deflate

Sec-WebSocket-Version: 13

Origin: http://localhost:8080

Sec-WebSocket-Extensions: permessage-deflate

Sec-WebSocket-Key: CMVwRmu3A0Ozj0og8cnrlA==

Connection: keep-alive, Upgrade

Pragma: no-cache

Cache-Control: no-cache

Upgrade: websocket


</request>

<response>
HTTP/1.1 101

Upgrade: websocket

Connection: upgrade

Sec-WebSocket-Accept: p4OcxSGQGdGqMJi7cxMnp8Sjrxc=

Sec-WebSocket-Extensions: permessage-deflate

Date: Thu, 13 Jul 2017 12:47:45 GMT


</response>

...,..9e...,.$.H...W(I-.QH+..U(OM*.O.N-QH.K)...+..
Tomcat web socket stuff...

So yes the HTTP/1.1 really needs to upgrade and NONE is just a work-around.

> 
>> The admin surely knows which protocol(s) the backend supports, the
>> issue being that otherwise most backends will ignore the Upgrade and
>> hence the connection will continue in normal HTTP (tunneled w/o any
>> protocol checking).
> 
> +1. Even once we implement the protocol list, we should still
> double-check that the protocol is actually upgraded before we start
> forwarding back and forth.

Actually the tunnel allows nearly everything.

Cheers

Jean-Frederic

> 
>> IMO the Upgrade handling should be part of mod_proxy_http (not
>> _wstunnel) and depend on whether or not the backend accepted it.
> 
> This I don't necessarily agree with as much... for now, Upgrade handling
> belongs where it's needed, and if there are duplicate pieces of code, we
> probably need to pull them into the core, not a different proxy module.
> 
>> It was already discussed in [1], well, I can't say that the idea was
>> unanimous at that time...
> 
> Yeah, I don't understand the turn that conversation took. We're talking
> about a feature that can be used for reverse-proxying, and there's
> nothing to CONNECT to.
> 
> --Jacob
> 


Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by Jacob Champion <ch...@gmail.com>.
On 07/11/2017 05:36 AM, Yann Ylavic wrote:
> I think it's quite hazardous to use/allow ANY and would prefer the 
> upgrade_method (worker->s->upgrade) to be a list of acceptable 
> protocols.

I think both ANY *and* NONE are dangerous. Both of them turn
proxy_wstunnel into a generic TCP forwarder (and NONE does so without
any opt-in on the client's part).

> The admin surely knows which protocol(s) the backend supports, the 
> issue being that otherwise most backends will ignore the Upgrade and 
> hence the connection will continue in normal HTTP (tunneled w/o any 
> protocol checking).

+1. Even once we implement the protocol list, we should still
double-check that the protocol is actually upgraded before we start
forwarding back and forth.

> IMO the Upgrade handling should be part of mod_proxy_http (not 
> _wstunnel) and depend on whether or not the backend accepted it.

This I don't necessarily agree with as much... for now, Upgrade handling
belongs where it's needed, and if there are duplicate pieces of code, we
probably need to pull them into the core, not a different proxy module.

> It was already discussed in [1], well, I can't say that the idea was 
> unanimous at that time...

Yeah, I don't understand the turn that conversation took. We're talking
about a feature that can be used for reverse-proxying, and there's
nothing to CONNECT to.

--Jacob

Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by jean-frederic clere <jf...@gmail.com>.
On 07/11/2017 02:36 PM, Yann Ylavic wrote:
> On Tue, Jul 11, 2017 at 1:41 PM,  <jf...@apache.org> wrote:
>> Author: jfclere
>> Date: Tue Jul 11 11:41:44 2017
>> New Revision: 1801594
>>
>> URL: http://svn.apache.org/viewvc?rev=1801594&view=rev
>> Log:
>>
>> Add logic to read the Upgrade header and use it in the response.
>> Use we you are proxying to a server that has multiple upgrade on the same IP/Port.
>> PR 61142
> 
> I think it's quite hazardous to use/allow ANY and would prefer the
> upgrade_method (worker->s->upgrade) to be a list of acceptable
> protocols.

Probably...

> 
> The admin surely knows which protocol(s) the backend supports, the
> issue being that otherwise most backends will ignore the Upgrade and
> hence the connection will continue in normal HTTP (tunneled w/o any
> protocol checking).
> 
> IMO the Upgrade handling should be part of mod_proxy_http (not
> _wstunnel) and depend on whether or not the backend accepted it.

Correct upgrade belongs to the HTTP protocol.

Cheers

Jean-Frederic

> 
> It was already discussed in [1], well, I can't say that the idea was
> unanimous at that time...
> The proposed patch there is probably outdated now, but I still find it
> safer than what we have now.
> 
> Regards,
> Yann.
> 
> [1] https://www.mail-archive.com/dev@httpd.apache.org/msg66204.html
> 


Re: svn commit: r1801594 - in /httpd/httpd/trunk: docs/manual/mod/mod_proxy_wstunnel.xml modules/proxy/mod_proxy_wstunnel.c

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 11, 2017 at 1:41 PM,  <jf...@apache.org> wrote:
> Author: jfclere
> Date: Tue Jul 11 11:41:44 2017
> New Revision: 1801594
>
> URL: http://svn.apache.org/viewvc?rev=1801594&view=rev
> Log:
>
> Add logic to read the Upgrade header and use it in the response.
> Use we you are proxying to a server that has multiple upgrade on the same IP/Port.
> PR 61142

I think it's quite hazardous to use/allow ANY and would prefer the
upgrade_method (worker->s->upgrade) to be a list of acceptable
protocols.

The admin surely knows which protocol(s) the backend supports, the
issue being that otherwise most backends will ignore the Upgrade and
hence the connection will continue in normal HTTP (tunneled w/o any
protocol checking).

IMO the Upgrade handling should be part of mod_proxy_http (not
_wstunnel) and depend on whether or not the backend accepted it.

It was already discussed in [1], well, I can't say that the idea was
unanimous at that time...
The proposed patch there is probably outdated now, but I still find it
safer than what we have now.

Regards,
Yann.

[1] https://www.mail-archive.com/dev@httpd.apache.org/msg66204.html