Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

私有仓库配置如何配置http协议? #1872

Open
lcfang opened this issue Mar 10, 2025 · 2 comments
Open

私有仓库配置如何配置http协议? #1872

lcfang opened this issue Mar 10, 2025 · 2 comments

Comments

@lcfang
Copy link
Contributor

lcfang commented Mar 10, 2025

higress-gateway加载wasm默认使用https协议与仓库建连,尝试添加环境变量WASM_INSECURE_REGISTRIES,或在oci URL的镜像仓库上添加80端口,均无法解决,想问一下有什么办法可以将默认协议修改为http的嘛?

Image

Image

@CH3CHO
Copy link
Collaborator

CH3CHO commented Mar 10, 2025

找到了个参考资料:google/go-containerregistry#1874

@CH3CHO
Copy link
Collaborator

CH3CHO commented Mar 11, 2025

现在网关用来拉取镜像的代码摘录如下:

https://github.com/higress-group/istio/blob/istio-1.19/pkg/wasm/imagefetcher.go#L93

ref, err := name.ParseReference(url) // <------ #1
if err != nil {
	err = fmt.Errorf("could not parse url in image reference: %v", err)
	return
}
wasmLog.Infof("fetching image %s from registry %s with tag %s", ref.Context().RepositoryStr(),
	ref.Context().RegistryStr(), ref.Identifier())

// fallback to http based request, inspired by [helm](https://github.com/helm/helm/blob/12f1bc0acdeb675a8c50a78462ed3917fb7b2e37/pkg/registry/client.go#L594)
// only deal with https fallback instead of attributing all other type of errors to URL parsing error
desc, err := remote.Get(ref, o.fetchOpts...)
if err != nil && strings.Contains(err.Error(), "server gave HTTP response") { // <------ #2
	wasmLog.Infof("fetching image with plain text from %s", url)
	ref, err = name.ParseReference(url, name.Insecure)
	if err == nil {
		desc, err = remote.Get(ref, o.fetchOpts...)
	}
}

可以看到在 1 号位置,是按照默认配置来解析 url 的,即需要使用 HTTPS 协议来访问。如果访问报错,且报错信息中包含 server gave HTTP response 字样(见 2 号位置),说明实际访问的是 HTTP 服务器。这时再改用 HTTP 协议访问一次。

我在本地使用 registry:latest 镜像部署了个本地仓库,并使用 docker pull 命令来尝试拉取镜像,可以看到报错是包含 server gave HTTP response 内容的:

Image

而按照上面贴的日志,服务端是直接关闭了连接。这个行为似乎不符合预期:

Image

建议从这个角度来分析。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants