How to use Squid to redirect an incomig request to another host

PROXYrequestsquid

I'm trying to integrate an internal GitLab installation with a Slack incoming webhook but I have a problem, the machine where GitLab can only access other machines in the same network. I have VM which is in that same network and has external access.

The Slack webhook is a URL like this:

https://hooks.slack.com/services/T18QMD0NM/C09PY5XKO/52lDzmkoxL51p9NLRqxQ9Kq2

But since I cannot use that in GitLab, I've configured the Slack service on GitLab to make requests to the following URL instead:

https://192.168.1.220:3128/services/T18QMD0NM/C09PY5XKO/52lDzmkoxL51p9NLRqxQ9Kq2

192.168.1.220 is the VM IP address and 3128 is where Squid is listening.

How do I use Squid to forward all incoming requests to hooks.slack.com?

P.S: I have a clean Squid installation, didn't change any setting at all.

Best Answer

I suppose the best way to solve your issue is by directing your GitLab to use an outbound http proxy.

You can refer this link to configure the http proxy on your GitLab installation.

-- Update

#!/usr/bin/perl
use strict;

# Turn off buffering to STDOUT
$| = 1;

# Read from STDIN
while (<>) {

    my @elems = split; # splits $_ on whitespace by default

    # The URL is the first whitespace-separated element.
    my $url = $elems[0];

    # Handle local IP links and translate them to https://hooks.slack.com
    # with the rest of the URL intact (if present) and ignore warnings.
    # 192.168.1.220:3128
    if ($url =~ m#^https://192\.168\.1\.220(/.*)?#i) {

        $url = "https://hooks.slack.com${1}";

        print "$url\n";

    }    
}

Add the following line of code in your squid.conf file:

redirect_program /path/to/the/script/above/redirect_program.pl

And Finally reload/reconfigure squid using:

/path/to/executable/squid -k reconfigure
Related Topic