2 Commits

Author SHA1 Message Date
wmgit
4053481714 🔧 config: Default config field for docker hub auth 2025-10-03 16:48:05 +08:00
wmgit
58097f865d 🔒 docker: Support basic auth for docker hub 2025-10-03 16:41:40 +08:00
3 changed files with 28 additions and 3 deletions

View File

@@ -52,6 +52,11 @@ proxy = ""
# 批量下载离线镜像数量限制
maxImages = 10
# Docker Hub 认证信息,留空则匿名拉取
[dockerHubAuth]
username = "" # e.g., user1
token = "" # e.g., dckr_pat_***
# Registry映射配置支持多种镜像仓库上游
[registries]

View File

@@ -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 {
@@ -108,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",

View File

@@ -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,