Page MenuHomePhabricator

Allow tools to use phabricator webhooks
Open, MediumPublic

Description

Phabricator has a feature for webhooks:

If you'd like to react to events in Phabricator or publish them into external systems, you can configure webhooks.

We currently don't have any tools using those webhooks, because we seem to block all outbound traffic from the phabricator application https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/modules/phabricator/data/fixed_settings.yaml#229, and seemingly also from the server that phabricator is hosted on (@thcipriani notes that netcat times out when pinging e.g. google.com from the phabricator server).

It seems that at least a few tools would benefit from being able to use webhooks: https://phabricator.wikimedia.org/search/query/rpmZZiCdW1KO/#R

I think there are few things we would need to do:

  1. Loosen the rules for the server that Phabricator is hosted on to allow for some specific domains to be reached (maybe toolforge.org for now?) Already possible
  2. Loosen the rules for Phabricator application to allow external requests to the domain(s) defined above
  3. Define a process for requesting a webhook, because currently only admins can do so

Event Timeline

@thcipriani maybe this is not worth it, from a security perspective? What do you think?

Tools that want a stream of events could implement some crude polling of the recent activity from phabricator, as an alternative.

Just coming across this. I'm noting that we allow webhook traffic from GitLab to toolforge at present. I can't really think why this would be a different case, and it would probably facilitate some useful integrations.

@Dzahn curious if you have any thoughts here...

Hello, so what I can say for now is that in general from production servers to access the web outside you have to go via proxy servers, those can be configured by setting the HTTP_PROXY/HTTPS_PROXY environment variable. But that's just a technical comment, all the other questions to be talked about.

Aklapper triaged this task as Medium priority.Jul 13 2023, 5:33 PM
Aklapper moved this task from To Triage to Infrastructure on the Phabricator board.

I can talk to en.wikipedia from the phabricator prod machine (without setting a proxy):

phab1004:~] $ curl -s https://en.wikipedia.org/wiki/Main_Page   | tail -c 128

7\/Stamp_of_India_-_1978_-_Colnect_326687_-_Amrita_Sher_Girl.jpeg","headline":"Wikimedia project page"}</script>
</body>

I can also talk to a random external wiki (with setting the proxy):

[phab1004:~] $ HTTPS_PROXY="http://url-downloader.eqiad.wikimedia.org:8080" curl -s https://spongebob.fandom.com/wiki/Encyclopedia_SpongeBobia | grep title | head -c 32

<title>Encyclopedia SpongeBobia

I can talk to en.wikipedia from the phabricator prod machine (without setting a proxy):

phab1004:~] $ curl -s https://en.wikipedia.org/wiki/Main_Page   | tail -c 128

7\/Stamp_of_India_-_1978_-_Colnect_326687_-_Amrita_Sher_Girl.jpeg","headline":"Wikimedia project page"}</script>
</body>

I can also talk to a random external wiki (with setting the proxy):

[phab1004:~] $ HTTPS_PROXY="http://url-downloader.eqiad.wikimedia.org:8080" curl -s https://spongebob.fandom.com/wiki/Encyclopedia_SpongeBobia | grep title | head -c 32

<title>Encyclopedia SpongeBobia

Hmm. At the time that I filed this, netcat to google.com from a phabricator server didn't work. Not sure what changed since then.

Hmm. At the time that I filed this, netcat to google.com from a phabricator server didn't work. Not sure what changed since then.

It's because netcat isn't really a specialized HTTP client and won't look at the HTTP_PROXY env variable. While it does have -x option to use a proxy I can't get it to work like that either:

" it expects a SOCKS or HTTPS proxy with the -x argument, specified by -X:"

" -X proxy_protocol

Requests that nc should use the specified protocol when talking
to the proxy server.  Supported protocols are “4” (SOCKS v.4),
“5” (SOCKS v.5) and “connect” (HTTPS proxy).  If the protocol is
not specified, SOCKS version 5 is used.

"

[phab1004:~] $ netcat -x url-downloader.eqiad.wikimedia.org:8080 -X connect www.google.com 80
netcat: Proxy error: "HTTP/1.1 403 Forbidden"
[phab1004:~] $ netcat -x url-downloader.eqiad.wikimedia.org:8080 -Xconnect www.google.com 443
GET index.html
...

BUT, what you can do is talk to the proxy and tell it to fetch google.com for you. This works:

[phab1004:~] $ netcat url-downloader.eqiad.wikimedia.org 8080
GET http://google.com HTTP/1.0

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/

Hmm. At the time that I filed this, netcat to google.com from a phabricator server didn't work. Not sure what changed since then.

It's because netcat isn't really a specialized HTTP client and won't look at the HTTP_PROXY env variable.

Ah. I see, thanks for clarifying.

One potential security issue is that if someone uses a webhook to subscribe to events as they occur on phab, and a task is retroactively made a security issue, that application would have access to the private task contents. That can be somewhat mitigated by auditing who is allowed to subscribe to task events and seeing how that data is stored.