Make Go mod and Git to use specify .netrc

Background

I want to make a private goproxy, direct lookup with gitlab.

This service should be stateless, use user’s gitlab token. It works with

1
GOPROXY='https://username:accesstoken@private.goproxy.example.com' go mod get private.org/abc

Hot to do

Go document said that to use authenticate over HTTPS, we can use .netrc file.

But, by default, Git will only use $HOME/.netrc (supported by CURL).

Go vcs (cmd/go/internal/vcs) will follow NETRC env, but is not enough. We need make Git to use NETRC too.

Git contrib provider git-credential-netrc.

We can configure Git to use it.

1
2
3
wget -O /usr/local/bin/git-credential-netrc https://raw.githubusercontent.com/git/git/master/contrib/credential/netrc/git-credential-netrc.perl
chmod +x /usr/local/bin/git-credential-netrc
git config --global credential.helper 'netrc -f $NETRC'

Then, Go mod and Git and both works with NETRC env


Make Go mod and Git to use specify .netrc
https://hunsh.net/20240505/Make-go-mod-and-git-to-use-specify-netrc/
发布于
2024年5月5日
许可协议