diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e9adc4..6575519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # 更新日志 +v1.4.0 +--- +- CHANGE: 优化代码结构,提升性能 +- ADD: 新增auth子模块whitelist.go,支持白名单功能 +- ADD: 新增whitelist.json文件,用于配置白名单 +- CHANGE&ADD: 在config.yaml文件中新增白名单配置块 +- FIX: 由于临时加入且未在原开发路线上计划的白名单功能,导致函数命名冲突,在此修复blacklist.go的函数命名问题 + +24w11b +--- +- PRE-RELEASE: 此版本是v1.4.0的预发布版本,请勿在生产环境中使用 +- FIX: 修复黑/白名单是否生效相关问题 + 24w11a --- - PRE-RELEASE: 此版本是v1.4.0的预发布版本,请勿在生产环境中使用 @@ -7,7 +20,7 @@ - CHANGE: 优化代码结构,提升性能 - ADD: 新增auth子模块whitelist.go,支持白名单功能 - ADD: 新增whitelist.json文件,用于配置白名单 -- FIX: 由于新加入未在原开发路线上计划的白名单功能,导致函数命名冲突,在此修复blacklist.go的函数命名问题 +- FIX: 由于临时加入且未在原开发路线上计划的白名单功能,导致函数命名冲突,在此修复blacklist.go的函数命名问题 v1.3.1 --- diff --git a/DEV-VERSION b/DEV-VERSION index ded078f..fd2ce9b 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w11a \ No newline at end of file +24w11b \ No newline at end of file diff --git a/README.md b/README.md index 3ba4bca..ca6be0f 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ git clone https://ghproxy.1888866.xyz/github.com/WJQSERVER-STUDIO/ghproxy.git - Docker-cli ``` -docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/caddy:/data/caddy/log --restart always wjqserver/ghproxy +docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/caddy:/data/caddy/log -v ./ghproxy/config:/data/ghproxy/config --restart always wjqserver/ghproxy ``` - Docker-Compose @@ -86,9 +86,14 @@ auth: # 黑名单配置 blacklist: - enabled: true + enabled: true # 是否开启黑名单 blacklistfile: "/data/ghproxy/config/blacklist.json" +# 白名单配置 +whitelist: + enabled: false # 是否开启白名单 + whitelistfile: "/data/ghproxy/config/whitelist.json" + ``` ### 黑名单配置 @@ -103,7 +108,21 @@ blacklist: "another/repo3" ] } -``` +``` + +### 白名单配置 + +白名单配置位于config/whitelist.json,格式如下: + +```json +{ + "whitelist": [ + "test/test1", + "example/repo2", + "another/repo3" + ] + } +``` ### Caddy反代配置 @@ -128,6 +147,7 @@ example.com { - [x] 改进程序效率 - [x] 用户鉴权 - [x] 仓库黑名单 +- [x] 仓库白名单 ### DEV diff --git a/SECURITY.MD b/SECURITY.MD index 1b4f7c9..7752f10 100644 --- a/SECURITY.MD +++ b/SECURITY.MD @@ -7,7 +7,7 @@ | 版本 | 是否支持 | | --- | --- | | v1.x.x | :white_check_mark: | -| **w**a/b | :warning: 这是测试版本,用于开发测试,可能存在未知的安全隐患 | +| **w**a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 | | v0.x.x | :x: 这些版本不再受支持 | ### 版本说明 diff --git a/docker/dockerfile/release/Dockerfile b/docker/dockerfile/release/Dockerfile index 8f944d9..bca9044 100644 --- a/docker/dockerfile/release/Dockerfile +++ b/docker/dockerfile/release/Dockerfile @@ -14,6 +14,7 @@ RUN VERSION=$(curl -s https://raw.githubusercontent.com/${USER}/${REPO}/main/VER wget -O /data/${APPLICATION}/${APPLICATION} https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION} RUN wget -O /data/${APPLICATION}/config.yaml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.yaml RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/blacklist.json +RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/whitelist.json RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${REPO}/main/init.sh RUN chmod +x /data/${APPLICATION}/${APPLICATION} RUN chmod +x /usr/local/bin/init.sh diff --git a/proxy/proxy.go b/proxy/proxy.go index 804f4e6..d830103 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -56,21 +56,25 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { fullrepo := fmt.Sprintf("%s/%s", username, repo) // 白名单检查 - whitelistpass := auth.CheckWhitelist(fullrepo) - if !whitelistpass { - errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo) - c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - logw(errMsg) - return + if cfg.Whitelist.Enabled { + whitelistpass := auth.CheckWhitelist(fullrepo) + if !whitelistpass { + errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo) + c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) + logw(errMsg) + return + } } // 黑名单检查 - blacklistpass := auth.CheckBlacklist(fullrepo) - if blacklistpass { - errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo) - c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - logw(errMsg) - return + if cfg.Blacklist.Enabled { + blacklistpass := auth.CheckBlacklist(fullrepo) + if blacklistpass { + errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo) + c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) + logw(errMsg) + return + } } matches = CheckURL(rawPath)