Git can't resolve external host names

Viewed 81

Git on our Jenkins server can't resolve host names that point outside of the local network for it's proxy(our DMZ).

This was fine when we only had the master node since our GitLab server shares the same proxy and is therefore accessible locally, but it causes problems with new build agents are not located in the DMZ and that have no reason to be proxied and therefore need to use the public URL to access our GitLab server.

I have tried checking the DNS settings and they are fine. I have also tried looking up the GitLab URL using dig and it worked. using git with the URL works on other machines.

2 Answers

I accomplished a similar task by exporting the environment variabile no_proxy with a command separated list of host name patterns.

E.g:

export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

Git 2.37 (Q3 2022) adds an alternative, with the new http.curloptResolve configuration: the CURLOPT_RESOLVE mechanism that allows cURL based applications to use pre-resolved IP addresses for the requests is exposed to the scripts.

See commit 511cfd3 (16 May 2022) by Christian Couder (chriscool).
(Merged by Junio C Hamano -- gitster -- in commit 60be293, 30 May 2022)

http: add custom hostname to IP address resolutions

Signed-off-by: Christian Couder

Libcurl has a CURLOPT_RESOLVE easy option that allows the result of hostname resolution in the following format to be passed:

[+]HOST:PORT:ADDRESS[,ADDRESS]

This way, redirects and everything operating against the HOST+PORT will use the provided ADDRESS(s).

The following format is also allowed to stop using hostname resolutions that have already been passed:

-HOST:PORT

See https://curl.se/libcurl/c/CURLOPT_RESOLVE.html for more details.

Let's add a corresponding "http.curloptResolve" config option that takes advantage of CURLOPT_RESOLVE.

Each value configured for the "http.curloptResolve" key is passed "as is" to libcurl through CURLOPT_RESOLVE, so it should be in one of the above 2 formats.
This keeps the implementation simple and makes us consistent with libcurl's CURLOPT_RESOLVE, and with curl's corresponding --resolve command line option.

The implementation uses CURLOPT_RESOLVE only in get_active_slot() which is called by all the HTTP request sending functions.

git config now includes in its man page:

http.curloptResolve

Hostname resolution information that will be used first by libcurl when sending HTTP requests.
This information should be in one of the following formats:

  • [+]HOST:PORT:ADDRESS[,ADDRESS]
  • -HOST:PORT

With:

  • The first format redirects all requests to the given HOST:PORT to the provided ADDRESS(s).
  • The second format clears all previous config values for that HOST:PORT combination.

To allow easy overriding of all the settings inherited from the system config, an empty value will reset all resolution information to the empty list.

Related