无法通过雅典Go 模块代理对私有模块进行身份验证

如何解决无法通过雅典Go 模块代理对私有模块进行身份验证

我在本地使用 docker 测试 Athens,尝试设置身份验证,以便雅典能够访问公司的私有模块。我按照指南 here 和命令 go get github.com/SomeCompany/someprivatemodule 成功地将该库的最新版本拉到了我的本地。但是有一些奇怪的东西。

  1. 那些配置文件(.gitconfig、.ssh/config 和 .ssh/id_rsa)没有使该命令起作用。相反,由我的 GitHub 令牌组成的 .netrc 文件使其工作。我尝试在不挂载这些配置文件的情况下运行 docker 映像,并且该命令仍然有效;但是,如果我删除了本地中的 ~/.netrc,go get 命令将失败。似乎 go get 仍然取决于本地配置而不是雅典。

go get command fails when .netrc removed

  1. go get 命令确实从 GitHub 拉取私有模块。但是,在athens_disK_STORAGE_ROOT下,我只能找到github.com/SomeCompany/someprivatemodule依赖的那些公共模块,而那些私有模块只能在GOPATH下找到/pkg/mod.雅典不是应该将私有模块下载到athens_disK_STORAGE_ROOT,这样一旦 GitHub/gitlab 关闭用户仍然可以从雅典下载这些私有模块吗?

Missing private module in Athens dir

这是我的设置:

goproxy=127.0.0.1:3000,which is the exposed port of athens. GOPRIVATE="github.com/SomeCompany"
GOnopROXY="github.com/SomeCompany"
GONOSUMDB="github.com/SomeCompany"

~/.netrc

machine github.com login some_personal_access_token

.gitconfig

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
    insteadOf = https://gitlab.com/

.ssh/配置

Host github.com
Hostname github.com
StrictHostKeyChecking no
IdentityFile /root/.ssh/id_rsa

运行docker镜像命令

docker run -d -v $athens_STORAGE:/var/lib/athens -e athens_disK_STORAGE_ROOT=/var/lib/athens -e athens_STORAGE_TYPE=disk -v $PWD/.gitconfig:/root/.gitconfig -v @PWD/.ssh:/root/.ssh --name athens-proxy --restart always -p 3000:3000 gomods/athens:v0.11.0

第一次编辑

通过将 GOPRIVATE 设置为空,GOnopROXY 和 GONOSUMDB 会自动取消设置。我尝试使用原始设置重新运行 docker,但出现 404 错误

404 error in my terminal

Docker 日志:

INFO[2:35PM]: Exporter not specified. Traces won't be exported

2021-05-29 14:35:11.957339 I | Starting application at port :3000

INFO[2:35PM]: exit status 1: go list -m: github.com/SomeCompany@latest: invalid github.com/ import path "github.com/SomeCompany"

http-method=GET http-path=/github.com/SomeCompany/@v/list kind=Not Found module= operation=download.ListHandler ops=[download.ListHandler pool.List protocol.List vcslister.List] request-id=3660faa3-256f-43fb-9937-f29565e7afa9 version=

INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/@v/list http-status=404 request-id=3660faa3-256f-43fb-9937-f29565e7afa9

INFO[2:35PM]: exit status 1: go list -m: github.com@latest: unrecognized import path "github.com": parse https://github.com/?go-get=1: no go-import Meta tags ()

http-method=GET http-path=/github.com/@v/list kind=Not Found module= operation=download.ListHandler ops=[download.ListHandler pool.List protocol.List vcslister.List] request-id=4d6659d2-710d-445f-b07f-7407aa4f2e3e version=

INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/@v/list http-status=404 request-id=4d6659d2-710d-445f-b07f-7407aa4f2e3e

INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/list http-status=200 request-id=e8d95d77-81dc-46fe-9523-e35f6dc8201f

DEBUG[2:35PM]: saving github.com/SomeCompany/someprivatemodule@v1.0.5 to storage... http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52

INFO[2:35PM]: github.com/SomeCompany/someprivatemodule@v1.0.5/go.mod: verifying module: github.com/SomeCompany/someprivatemodule@v1.0.5/go.mod: reading https://sum.golang.org/lookup/github.com/SomeCompany/someprivatemodule@v1.0.5: 410 Gone

server response: not found: github.com/SomeCompany/someprivatermodule@v1.0.5: invalid version: unkNown revision v1.0.5 http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info kind=Not Found module=github.com/SomeCompany/someprivatemodule operation=download.InfoHandler ops=[download.InfoHandler pool.Info protocol.Info protocol.processDownload stash.Pool stasher.Stash stasher.fetchModule goGetFetcher.Fetch module.downloadModule] request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52 version=v1.0.5

INFO[2:35PM]: incoming request http-method=GET http-path=/github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info http-status=404 request-id=24964b9c-b0b2-450a-bd9a-9d59f60a5c52

雅典似乎试图从 sum.golang.org 中查找软件包。所以我尝试使用正确的凭据挂载 .netrc 文件并设置 athens_NETRC_PATH。这仍然给我同样的错误

一个事实:使用 v0.11.0,我无法使用 go get 下载任何内容。但是,使用 v0.2.0 版本的雅典 docker 镜像,我能够下载部分模块。 docker 日志(v0.2.0)如下所示:

buffalo: Unless you set SESSION_SECRET env variable,your session storage is not protected!

time="2021-05-29T19:39:20Z" level=info msg="Exporter not specified. Traces won't be exported"

buffalo: Starting application at :3000

time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go list -m github.com/SomeCompany: invalid github.com/ import path \"github.com/SomeCompany\"\n" http-method=GET http-path="/github.com/SomeCompany/@v/list/" http-url="/github.com/SomeCompany/@v/list/" kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcslister.List]" version=

handler: GET /github.com/SomeCompany/@v/list/ [500]

time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go list -m github.com: unrecognized import path \"github.com\" (parse https://github.com?go-get=1: no go-import Meta tags ())\n" http-method=GET http-path=/github.com/@v/list/ http-url=/github.com/@v/list/ kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcslister.List]" version=

handler: GET /github.com/@v/list/ [500]

handler: GET /github.com/SomeCompany/someprivatemodule/@v/list/ [200]

time="2021-05-29T19:39:26Z" level=error msg="exit status 1: go: finding github.com/SomeCompany/someprivatemodule/somefile latest\ngo list -m github.com/SomeCompany/someprivatemodule/somefile: no matching versions for query \"latest\"\n" http-method=GET http-path="/github.com/SomeCompany/someprivatemodule/somefile/@v/list/" http-url="/github.com/SomeCompany/someprivatemodule/somefile/@v/list/" kind="Internal Server Error" module= operation=download.ListHandler ops="[download.ListHandler pool.List protocol.List vcslister.List]" version=

handler: GET /github.com/SomeCompany/someprivatemodule/ratelimit/@v/list/ [500]

handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.info [200]

handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.mod [200]

handler: GET /github.com/SomeCompany/someprivatemodule/@v/v1.0.5.zip [200]

显然这仍然不起作用,因为它缺少模块的一部分。

编辑:通过添加 GONOSUM_PATTERNS 解决


解决方法

我只是尝试了雅典。它用作 Go 模块缓存。 当您启动 athens 并设置 GOPROXY=127.0.0.1:3000 时,go get 命令将尝试使用以下序列获取模块:

  1. 检查 GOPATH/pkg/mod
  2. 来自 GOPROXY 的请求

这里您的 GOPROXY 是 athens 服务器,因此您的本地 go get 将向 athens 发送请求。然后athens会检查模块是否在ATHENS_DISK_STORAGE_ROOT中;如果没有,请从 github.com 或它应该在的任何地方获取代理。

您可以尝试walkthrough该过程。

关于你的问题,

我注意到您在 GONOPROXY 中设置了 github.com/SomeCompany,因此此存储库中的所有模块都不会使用 GOPROXY,并且雅典将无法正常工作。

这就是为什么在问题 1 中使用了您的 .netrc;而在问题 2 中,只有 github.com/SomeCompany/someprivatemodule 所依赖的模块是从 athens 下载的,而模块本身不是。

移除 GONOPROXY 并重试,看看发生了什么。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?