Git
Clone and fetch from a forge through the proxy’s Git upstream, over HTTPS or
SSH. The examples use the upstream name github; replace it with the name your
operator gave the upstream (what you need).
| Upstream type | git |
| Package source | https://proxy.example.com/v1/github/<owner>/<repository>.git |
| Clients | git (and everything that runs it: Go, Terraform, Composer, cargo, pip with VCS requirements) |
| Tested | git 2.49 over HTTPS: in CI on every push and in the client lab. The SSH endpoint: by the proxy’s integration tests, not with these scripts. |
Configure
Rewrite the forge’s address once
One insteadOf rule sends every https://github.com/ URL through the proxy —
existing clone URLs, submodules, and the Git dependencies of other package
managers — without editing any of them:
git config --global url."https://proxy.example.com/v1/github/".insteadOf "https://github.com/"
git clone https://github.com/octocat/Hello-World.git repo
The checkout keeps recording the forge’s own URL (git config --get
remote.origin.url prints https://github.com/octocat/Hello-World.git); the
rewrite happens each time the URL is used, and git remote -v shows the
rewritten address.
Or name the proxy explicitly
git clone https://proxy.example.com/v1/github/octocat/Spoon-Knife.git explicit
SSH
Where the operator runs the proxy’s SSH endpoint (it needs mirror mode on the
proxy), the repository path is <upstream>/<owner>/<repository>.git:
git clone ssh://git@proxy.example.com:2222/github/octocat/Hello-World.git
Authentication is by public key only; pin the proxy’s host key in
~/.ssh/known_hosts.
Authenticate
Only when the proxy has access control switched on. Hand Git your proxy token — an API token, or the token of your personal cache link — once, scoped to the proxy, and keep clone URLs free of it:
git config --global http."https://proxy.example.com/".extraHeader "Authorization: Bearer <token>"
A credential helper works as well — the platform’s keychain, or store,
which keeps the credential in a plain file. The proxy challenges Git with HTTP
Basic, and Git answers with what its helper holds for the proxy: any user name,
the token as the password. With store, that is one line of
~/.git-credentials:
git config --global credential.helper store
printf 'https://pullthrough:%s@proxy.example.com\n' "<token>" > "$HOME/.git-credentials"
(With a helper and a terminal, Git asks for the user name and password the first time the proxy challenges it, and the helper keeps what you type.)
Without access control, a personal link is used as part of the address
instead — with the same insteadOf rule, pointing at
https://proxy.example.com/u/<link>/v1/github/.
Trust a private CA
Scoped to the proxy’s host:
git config --global http."https://proxy.example.com/".sslCAInfo /etc/ssl/corp-ca.pem
Check that it works
git -C repo fetch origin
GIT_CURL_VERBOSE=1 git ls-remote https://github.com/octocat/Hello-World.git
shows the host each request goes to.
Good to know
-
Read-only. The proxy serves fetch and clone (
git-upload-pack, wire protocol v0, v1 and v2);git pushneeds the forge itself. AninsteadOfrule rewrites push URLs too, so a checkout that also pushes needs a second rule that keeps its push URL on the forge (git remote get-url --push originshows the result):git config --global url."https://github.com/".pushInsteadOf "https://github.com/" - Other tools inherit the rule. Anything that shells out to
gituses it: Terraform modules with Git sources (Terraform), Go modules fetched from their VCS, Composer--prefer-source, pipgit+https://requirements. - Git LFS works without configuration when the operator has enabled it
(
git.lfs.enabled):git lfs pullnegotiates through the proxy and objects are cached by their SHA-256. - A clone is not gated like a package. Commits are scanned by the proxy’s commit scanner for watched repositories, and the verdict gates the packages built from them; a clone itself is not refused (security model).
- With a personal cache link use it in an
insteadOfrule of your global configuration, not in a clone URL: clone URLs,.git/configand.gitmodulesthen keep naming the forge. A URL given togit cloneis stored in that checkout’s.git/config, link included — and the link works like a password.
On the proxy
upstreams:
github:
type: git
url: https://github.com
With git.mirrorDir set the proxy keeps bare mirrors and serves from them
(and can serve SSH, server.sshAddr); without it, requests are passed through
(ref advertisements can be cached for a short time with git.infoRefsTtl; by
default they are not). Upstream credentials let clients
clone private repositories without holding forge tokens. Details:
backends: git.