uwolfer / gerrit-intellij-plugin

Gerrit Code Review Tool Integration for the IntelliJ Platform
Apache License 2.0
495 stars 103 forks source link

Connecting to Gerrit behind Apache server as proxy? #475

Closed G-o-T-o closed 1 year ago

G-o-T-o commented 1 year ago

Hello,

is it possible that the Gerrit plugin (installed in PyCharm) accesses Gerrit server that is proxied by a front-end HTTP server (the obtained credentials are passed through to the Gerrit server)?

The reason I ask is the following:

I access my Gerrit server (port 8080) through Apache proxy server (port 8081). I succeeded (finally!) to get Gerrit Web UI appear in browser after analyzing HTTP traffic between the browser and Apache server and configuring the latter appropriately (I mean: it works now at least with the browser).

After that I configured Gerrit plugin in PyCharm with the same data as for the browser (http://host:proxy_port, username, password), but I did not succeed to connect properly to Gerrit (using "Test" button).

If this helps, I attach the HTTP message exchange between the Gerrit plugin and Apache server during testing the connection:

`

GET /login/ HTTP/1.1 Host: raspberrypi-4b.local:8081 Connection: Keep-Alive User-Agent: gerrit-intellij-plugin/1.2.6-203 using gerrit-rest-java-client/0.9.4 using Apache-HttpClient/4.5.13 (Java/11.0.15) Accept-Encoding: gzip,deflate Authorization: Basic xxxxxxxxxxxxxxxx

<<< HTTP/1.1 302 Found Date: Sat, 04 Mar 2023 00:33:19 GMT Server: Apache/2.4.38 (Raspbian) X-Frame-Options: DENY Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Location: http://raspberrypi-4b.local/ Content-Length: 0 Set-Cookie: GerritAccount=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy; Path=/; Expires=Sat, 04-Mar-2023 12:33:19 GMT; Max-Age=43200 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive

GET / HTTP/1.1 Host: raspberrypi-4b.local Connection: Keep-Alive User-Agent: gerrit-intellij-plugin/1.2.6-203 using gerrit-rest-java-client/0.9.4 using Apache-HttpClient/4.5.13 (Java/11.0.15) Cookie: GerritAccount=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Accept-Encoding: gzip,deflate

<<< HTTP/1.1 200 OK Date: Sat, 04 Mar 2023 00:33:19 GMT Server: Apache/2.4.38 (Raspbian) Last-Modified: Fri, 22 Jul 2022 20:20:33 GMT ETag: "29cd-5e46a90f6a844-gzip" Accept-Ranges: bytes Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 3041 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html

POST /login/ HTTP/1.1 Content-Length: 30 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Host: raspberrypi-4b.local:8081 Connection: Keep-Alive User-Agent: gerrit-intellij-plugin/1.2.6-203 using gerrit-rest-java-client/0.9.4 using Apache-HttpClient/4.5.13 (Java/11.0.15) Cookie: GerritAccount=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Accept-Encoding: gzip,deflate Authorization: Basic xxxxxxxxxxxxxxxx

<<< HTTP/1.1 405 Method Not Allowed Date: Sat, 04 Mar 2023 00:33:19 GMT Server: Apache/2.4.38 (Raspbian) X-Frame-Options: DENY Content-Type: text/plain;charset=iso-8859-1 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT Content-Length: 18 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive

GET /a/changes/?q=reviewer:self&n=1 HTTP/1.1 Accept: application/json Host: raspberrypi-4b.local:8081 Connection: Keep-Alive User-Agent: gerrit-intellij-plugin/1.2.6-203 using gerrit-rest-java-client/0.9.4 using Apache-HttpClient/4.5.13 (Java/11.0.15) Cookie: GerritAccount=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Accept-Encoding: gzip,deflate Authorization: Basic xxxxxxxxxxxxxxxx

<<< HTTP/1.1 401 Unauthorized Date: Sat, 04 Mar 2023 00:33:19 GMT Server: Apache/2.4.38 (Raspbian) WWW-Authenticate: Basic realm="Gerrit Code Review" Content-Type: text/plain;charset=iso-8859-1 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT Content-Length: 12 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive ` This is the end of the communication, the connection test failed.

uwolfer commented 1 year ago

It is quite hard to say what fails here. Just wondering: what are you reasons for not using a standard Gerrit setup?

G-o-T-o commented 1 year ago

Resolved.

Initially, I could not access Gerrit server at its native 8080 port for then-to-me-unknown reason, so I switched to experiment with the proxy port and specifics of the related HTTP authorization.

But looking into gerrit.config file again I saw I set httpd.listenUrl property as proxy-http://127.0.0.1:8080/, so Gerrit server was not accepting any requests from other hosts (which was the exact intention at the time I succeeded to hide Gerrit Web UI behind Apache HTTP server - they are installed at the same host). When I updated the property to proxy-http://*:8080/ and restarted the server, the connection test passed successfully.

My bad, sorry for bothering you. In the company we introduced Gerrit, so I decided to install all the relevant services at home in my local network, so I can err carefree while learning. But the installation and the usage are two different things. And I am quite a newbie in this sysadmin stuff...

I have now another question regarding Gerrit plugin, but I will ask it in a separate issue for the sake of not mixing topics.