higress icon indicating copy to clipboard operation
higress copied to clipboard

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

Open lcfang opened this issue 9 months ago • 2 comments

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

Image

Image

lcfang avatar Mar 10 '25 10:03 lcfang

找到了个参考资料:https://github.com/google/go-containerregistry/issues/1874

CH3CHO avatar Mar 10 '25 13:03 CH3CHO

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

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

建议从这个角度来分析。

CH3CHO avatar Mar 11 '25 05:03 CH3CHO

我也碰到这个问题,你解决了没

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

Image

Image

donyhuang avatar Apr 16 '25 10:04 donyhuang

我也碰到这个问题,你解决了没

加端口就行。oci://your.docker.registry:80/plugins/xxx:1.0.0

CH3CHO avatar Apr 16 '25 10:04 CH3CHO