From 58097f865d648bbaef062bfbd8ab035b2a5f00e6 Mon Sep 17 00:00:00 2001 From: wmgit Date: Fri, 3 Oct 2025 16:41:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=E2=9C=A8=20docker:=20?= =?UTF-8?q?Support=20basic=20auth=20for=20docker=20hub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.toml | 9 +++++++-- src/config/config.go | 5 +++++ src/handlers/docker.go | 10 +++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/config.toml b/src/config.toml index 18e8c2d..866a153 100644 --- a/src/config.toml +++ b/src/config.toml @@ -46,19 +46,24 @@ blackList = [ # 无认证: socks5://127.0.0.1:1080 # 有认证: socks5://username:password@127.0.0.1:1080 # 留空不使用代理 -proxy = "" +proxy = "" [download] # 批量下载离线镜像数量限制 maxImages = 10 +# Docker Hub 认证信息,留空则匿名拉取 +[dockerHubAuth] +username = "" # e.g., user1 +token = "" # e.g., dckr_pat_*** + # Registry映射配置,支持多种镜像仓库上游 [registries] # GitHub Container Registry [registries."ghcr.io"] upstream = "ghcr.io" -authHost = "ghcr.io/token" +authHost = "ghcr.io/token" authType = "github" enabled = true diff --git a/src/config/config.go b/src/config/config.go index ceaf9de..5ab4ffe 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -48,6 +48,11 @@ type AppConfig struct { MaxImages int `toml:"maxImages"` } `toml:"download"` + DockerHubAuth struct { + Username string `toml:"username"` + Token string `toml:"token"` + } `toml:"dockerHubAuth"` + Registries map[string]RegistryMapping `toml:"registries"` TokenCache struct { diff --git a/src/handlers/docker.go b/src/handlers/docker.go index 63a740b..4b35bbc 100644 --- a/src/handlers/docker.go +++ b/src/handlers/docker.go @@ -68,10 +68,18 @@ func InitDockerProxy() { } options := []remote.Option{ - remote.WithAuth(authn.Anonymous), remote.WithUserAgent("hubproxy/go-containerregistry"), remote.WithTransport(utils.GetGlobalHTTPClient().Transport), } + dockerHubAuth := config.GetConfig().DockerHubAuth + if dockerHubAuth.Token != "" && dockerHubAuth.Username != "" { + options = append(options, remote.WithAuth(&authn.Basic{ + Username: dockerHubAuth.Username, + Password: dockerHubAuth.Token, + })) + } else { + options = append(options, remote.WithAuth(authn.Anonymous)) + } dockerProxy = &DockerProxy{ registry: registry, -- 2.49.1 From 405348171480b2a3fd9349ecf6c14fb3c2ab3d25 Mon Sep 17 00:00:00 2001 From: wmgit Date: Fri, 3 Oct 2025 16:48:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A7=20config:=20Default=20config?= =?UTF-8?q?=20field=20for=20docker=20hub=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/config.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/config/config.go b/src/config/config.go index 5ab4ffe..bd98245 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -113,6 +113,13 @@ func DefaultConfig() *AppConfig { }{ MaxImages: 10, }, + DockerHubAuth: struct { + Username string `toml:"username"` + Token string `toml:"token"` + }{ + Username: "", + Token: "", + }, Registries: map[string]RegistryMapping{ "ghcr.io": { Upstream: "ghcr.io", -- 2.49.1