Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
proxy — 一个用于包注册表的轻量级缓存代理。 | Kitploit
工具/GitHubGitHub/git-pkgs/proxy
漏洞分析云安全DevSecOps供应链安全API 安全
GitHubgit-pkgs/proxy

proxy

一个用于包注册表的轻量级缓存代理。

查看仓库
15521151天前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

git-pkgs proxy

用于软件包注册表的缓存代理。通过在本地缓存构件来加速软件包下载,减少带宽占用并提升可靠性。

版本冷却

大多数供应链攻击依赖于速度:恶意版本发布后,会在几分钟内被自动化流水线拉取使用,而无人察觉。冷却功能为新发布的版本增加了一段隔离期。启用后,代理会从元数据响应中移除尚未超过可配置时间阈值的版本。```yaml cooldown: default: "3d" # hide versions published less than 3 days ago ecosystems: npm: "7d" # npm gets a longer window cargo: "0" # disable for cargo packages: "pkg:npm/lodash": "0" # exempt trusted packages

root@kitploit:~
3 天冷却期意味着当 `lodash` 发布 `4.18.0` 版本时,你的构建会继续使用 `4.17.21`,直到 3 天过去。如果新版本被证明遭到入侵,你从未暴露于风险之中。

解析顺序:包覆盖,然后是生态系统覆盖,最后是全局默认值。这让你可以设置一个保守的默认值,并为需要更快更新的包划定例外。完整配置参考请见 [docs/configuration.md](https://github.com/git-pkgs/proxy/blob/main/docs/configuration.md)。

## 制品扫描

冷却期只查看版本的发布时间戳——它从不检查实际的字节内容。制品扫描填补了这一空白:启用后,每个制品都会被暂存到存储中,并由一个或多个外部服务(trivy、ClamAV、Wiz,或任何遵循小型 HTTP/JSON 契约的服务)扫描,然后才会提交到缓存并提供给客户端。```yaml
scanning:
  enabled: true
  signing_key: ${PROXY_SCANNING_SIGNING_KEY}
  scanners:
    - name: clamav
      url: http://clamav-adapter:8080/scan
      mode: block             # a block verdict deletes the artifact and returns 403
    - name: trivy
      url: http://trivy-adapter:8081/scan
      mode: monitor            # findings are logged, never gate caching
      ecosystems: [npm, pypi]

代理从不将制品字节上传到扫描器。每个扫描器会收到包元数据以及一个短期有效的签名 URL 通知;扫描器自行从代理自身的存储中拉取字节。扫描器并发运行,第一个报告判定为不允许的 block 模式扫描器立即胜出,并取消其余扫描器。完整配置参考和扫描器 HTTP 契约请参见 docs/configuration.md。

支持的注册表

冷却需要元数据中包含发布时间戳。冷却列中没有“是”的注册表要么不暴露时间戳,要么尚未接入。

* Hex 冷却需要禁用注册表签名验证(HEX_NO_VERIFY_REPO_ORIGIN=1),因为代理会重新编码 protobuf 负载。

安装```bash

brew install git-pkgs/git-pkgs/proxy

root@kitploit:~
或者从[发布页面](https://github.com/git-pkgs/proxy/releases)下载二进制文件。

### Helm

从 GHCR 安装 chart,并设置包管理器客户端用于访问代理的公共 URL:```bash
helm install proxy oci://ghcr.io/git-pkgs/charts/proxy \
  --set config.data.base_url=https://proxy.example.com

默认 chart 部署一个副本,后端使用 10 GiB 持久卷,采用 SQLite 和位于 /data 下的文件系统制品存储。有关 ingress、外部数据库和对象存储配置选项,请参见 deploy/charts/proxy/values.yaml。

快速开始```bash

Build from source

go build -o proxy ./cmd/proxy

Run with defaults (listens on :8080)

./proxy

Run with custom settings

./proxy -listen :3000 -base-url https://proxy.example.com

root@kitploit:~
代理现已运行。配置你的包管理器以使用它。

## OpenAPI (Swagger)

本仓库使用 swaggo 从带注释的处理器生成 OpenAPI 规范。

生成规范:```bash
go install github.com/swaggo/swag/cmd/swag@latest
go generate ./internal/server

生成的文件写入 docs/swagger/。

当代理运行时,从以下地址获取实时规范:

  • http://localhost:8080/openapi.json

或将 http://localhost:8080 替换为您配置的基础 URL。此链接也会显示在仪表板上。

配置包管理器

npm

创建或编辑 ~/.npmrc:``` registry=http://localhost:8080/npm/

root@kitploit:~
或在 `.npmrc` 中按项目设置:```
registry=http://localhost:8080/npm/

或使用环境变量:```bash npm_config_registry=http://localhost:8080/npm/ npm install

root@kitploit:~
### Cargo

创建或编辑 `~/.cargo/config.toml`:```toml
[source.crates-io]
replace-with = "proxy"

[source.proxy]
registry = "sparse+http://localhost:8080/cargo/"

或在项目根目录的 .cargo/config.toml 中按项目设置。

RubyGems / Bundler

在 Gemfile 中设置 gem 源:```ruby source "http://localhost:8080/gem"

root@kitploit:~
或全局配置:```bash
gem sources --add http://localhost:8080/gem/
bundle config mirror.https://rubygems.org http://localhost:8080/gem

Go 模块

设置 GOPROXY 环境变量:```bash export GOPROXY=http://localhost:8080/go,direct

root@kitploit:~
或在你的 shell 配置文件中设置以实现持久化。

### Homebrew

将 Homebrew 的 JSON API 和制品域名指向代理:```bash
export HOMEBREW_API_DOMAIN=http://localhost:8080/homebrew
export HOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080

制品域在 /v2/homebrew/core/ 下代理清单和 bottle blob。GHCR 路由仅限于该仓库。源码归档、cask 应用程序下载、自定义 tap 制品以及旧版扁平文件 bottle 镜像使用 Homebrew 的常规回退 URL。通过不设置 HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK 来保持回退启用。

启用 cache_metadata 或设置 PROXY_CACHE_METADATA=true 以保留 Homebrew JSON API 响应以供离线回退使用。Bottle blob 及其 OCI 清单无需此设置即可缓存。

上游默认使用 https://formulae.brew.sh/api 作为 JSON API,使用 https://ghcr.io 作为制品。要将此代理链接到另一个代理,请将其 Homebrew 端点配置为上游:```yaml upstream: homebrew_api: "https://upstream-proxy.example.com/homebrew" homebrew_artifact: "https://upstream-proxy.example.com"

root@kitploit:~
对应的环境变量是 `PROXY_UPSTREAM_HOMEBREW_API` 和 `PROXY_UPSTREAM_HOMEBREW_ARTIFACT`。

### Hex (Elixir)

在 `~/.hex/hex.config` 中配置:```erlang
{default_url, <<"http://localhost:8080/hex">>}.

或设置环境变量:```bash export HEX_MIRROR=http://localhost:8080/hex

root@kitploit:~
### pub.dev (Dart/Flutter)

设置 PUB_HOSTED_URL 环境变量:```bash
export PUB_HOSTED_URL=http://localhost:8080/pub

PyPI (pip)

配置 pip 以使用代理:```bash pip install --index-url http://localhost:8080/pypi/simple/ package_name

root@kitploit:~
或在 `~/.pip/pip.conf` 中设置:```ini
[global]
index-url = http://localhost:8080/pypi/simple/

Maven

添加到你的 ~/.m2/settings.xml:```xml proxy central http://localhost:8080/maven/

root@kitploit:~
`/maven/` 端点使用 Maven Central 作为主要上游,当主要上游返回未找到时,回退到 Gradle Plugin Portal 以获取 Gradle 插件标记元数据及相关构件。

通过同一代理端点进行 Gradle 插件解析:```kotlin
pluginManagement {
  repositories {
    maven(url = "http://localhost:8080/maven/")
  }
}

Gradle HTTP 构建缓存

在 settings.gradle(.kts) 中配置:```kotlin buildCache { local { enabled = false } remote { url = uri("http://localhost:8080/gradle/") push = true } }

root@kitploit:~
### NuGet

在 `nuget.config` 中配置:```xml
<configuration>
  <packageSources>
    <clear />
    <add key="proxy" value="http://localhost:8080/nuget/v3/index.json" />
  </packageSources>
</configuration>

或使用 CLI:```bash dotnet nuget add source http://localhost:8080/nuget/v3/index.json -n proxy

root@kitploit:~
### Composer (PHP)

在 `composer.json` 中配置:```json
{
    "repositories": [
        {
            "type": "composer",
            "url": "http://localhost:8080/composer"
        }
    ]
}

或全局设置:```bash composer config -g repositories.proxy composer http://localhost:8080/composer

root@kitploit:~
### Conan (C/C++)

将代理添加为远程仓库:```bash
conan remote add proxy http://localhost:8080/conan
conan remote disable conancenter

或在 ~/.conan2/remotes.json 中配置。

Conda

在 ~/.condarc 中配置:```yaml channels:

  • http://localhost:8080/conda/main
  • http://localhost:8080/conda/conda-forge default_channels:
  • http://localhost:8080/conda/main
root@kitploit:~
或通过命令设置:```bash
conda config --add channels http://localhost:8080/conda/main

CRAN (R)

在 R 中设置仓库:```r options(repos = c(CRAN = "http://localhost:8080/cran"))

root@kitploit:~
或在 `~/.Rprofile` 中设置以持久化:```r
local({
  r <- getOption("repos")
  r["CRAN"] <- "http://localhost:8080/cran"
  options(repos = r)
})

Julia

在启动 Julia 之前设置 Pkg 服务器:```bash export JULIA_PKG_SERVER=http://localhost:8080/julia

root@kitploit:~
或在运行中的会话内:```julia
ENV["JULIA_PKG_SERVER"] = "http://localhost:8080/julia"
using Pkg; Pkg.update()

Swift

将代理配置为当前 Swift 包的默认注册表:```bash swift package-registry set --allow-insecure-http http://localhost:8080/swift

root@kitploit:~
Registry 依赖项在 `Package.swift` 中使用其作用域包标识符:```swift
dependencies: [
    .package(id: "apple.swift-argument-parser", from: "1.2.0")
]

该代理支持依赖解析和源下载。不支持使用 swift package-registry publish 进行发布。

Docker / 容器注册表

在 /etc/docker/daemon.json 中将 Docker 配置为使用该代理作为注册表镜像:```json { "registry-mirrors": ["http://localhost:8080"] }

root@kitploit:~
然后重启 Docker:```bash
sudo systemctl restart docker

或直接拉取镜像:```bash docker pull localhost:8080/library/nginx:latest

root@kitploit:~
### Helm

为每个 HTTP chart 仓库配置一个名称,然后将匹配的代理 URL 添加到 Helm:```yaml
upstream:
  helm:
    bitnami: "https://charts.bitnami.com/bitnami"

漏洞利用

root@kitploit:~
python3 exploit.py -t http://target.com -u admin -p password

功能特性

  • 支持多种目标
  • 详细的输出日志
  • 代理支持

免责声明

本工具仅供教育目的使用。```bash helm repo add bitnami http://localhost:8080/helm/bitnami helm repo update helm pull bitnami/nginx

root@kitploit:~
代理使用常规的元数据缓存设置缓存 `index.yaml`,并在根据索引验证 chart 归档的 SHA-256 摘要后对其进行缓存。

对于存储在 OCI registry 中的 chart,请配置一个命名的 OCI 上游,并将保留的 `upstream/{name}` 前缀添加到 chart 引用中:```yaml
upstream:
  oci:
    ghcr: "https://ghcr.io"

I'll analyze the request and provide the translation. However, I notice that the actual content to translate was not included in your message — the "INPUT:" section is empty.

Please provide the Markdown content for chunk 85/189 that you'd like me to translate from English to Chinese.```bash helm pull oci://localhost:8080/upstream/ghcr/owner/charts/mychart --version 1.0.0 --plain-http

root@kitploit:~
### Debian / APT

在 `/etc/apt/sources.list.d/proxy.list` 中配置 APT 以使用代理:```
deb http://localhost:8080/debian stable main contrib

替换现有的 sources.list 条目,然后:```bash sudo apt update

root@kitploit:~
上游默认使用 `http://deb.debian.org/debian`。要代理其他 APT 仓库(例如 Ubuntu),请在配置文件中设置 `upstream.debian`,或在环境变量中设置 `PROXY_UPSTREAM_DEBIAN`:```yaml
upstream:
  debian: "http://archive.ubuntu.com/ubuntu"

RPM / Yum / DNF

配置 yum/dnf 以使用 /etc/yum.repos.d/proxy.repo 中的代理:```ini [proxy-fedora] name=Fedora via Proxy baseurl=http://localhost:8080/rpm/releases/$releasever/Everything/$basearch/os/ enabled=1 gpgcheck=0

root@kitploit:~
然后:```bash
sudo dnf clean all
sudo dnf update

Alpine / apk

将 /etc/apk/repositories 指向代理。默认仓库名称 alpine 代理官方镜像(https://dl-cdn.alpinelinux.org/alpine):``` http://localhost:8080/apk/alpine/v3.22/main http://localhost:8080/apk/alpine/v3.22/community

root@kitploit:~
然后:```bash
apk update

仓库索引(v2 APKINDEX.tar.gz 和 v3 Packages.adb)、分离签名以及软件包均按字节原样提供,因此 apk 的正常签名验证功能保持可用。索引使用元数据缓存(metadata_ttl、过期回退);.apk 软件包存储在共享工件缓存中,并在上游不可达时仍然可用。

要代理其他镜像或私有仓库,请在 upstream.apk 下配置命名上游(这会替换内置默认值;如果仍需要 alpine,请重新添加):```yaml upstream: apk: alpine: "https://dl-cdn.alpinelinux.org/alpine" private: "https://apk.example.com"

root@kitploit:~
## 使用示例

### 基本用法

```bash
# 扫描单个目标
python3 cve_2025_55182.py -t https://target.example.com

# 扫描多个目标
python3 cve_2025_55182.py -f targets.txt

# 使用自定义超时时间扫描
python3 cve_2025_55182.py -t https://target.example.com --timeout 15

# 使用代理扫描
python3 cve_2025_55182.py -t https://target.example.com --proxy http://127.0.0.1:8080

# 使用自定义线程数扫描
python3 cve_2025_55182.py -f targets.txt --threads 20

# 详细输出
python3 cve_2025_55182.py -t https://target.example.com -v

# 将结果保存到文件
python3 cve_2025_55182.py -f targets.txt -o results.txt

高级用法

root@kitploit:~
# 使用自定义载荷扫描
python3 cve_2025_55182.py -t https://target.example.com --payload "custom_payload"

# 使用自定义 User-Agent 扫描
python3 cve_2025_55182.py -t https://target.example.com --user-agent "Mozilla/5.0"

# 使用自定义请求头扫描
python3 cve_2025_55182.py -t https://target.example.com --headers "X-Custom: value"

# 使用自定义 Cookie 扫描
python3 cve_2025_55182.py -t https://target.example.com --cookie "session=abc123"

# 使用自定义方法扫描
python3 cve_2025_55182.py -t https://target.example.com --method POST

# 使用自定义数据扫描
python3 cve_2025_55182.py -t https://target.example.com --data "param=value"

# 使用自定义路径扫描
python3 cve_2025_55182.py -t https://target.example.com --path "/custom/path"

# 使用自定义端口扫描
python3 cve_2025_55182.py -t https://target.example.com --port 8443

# 使用自定义协议扫描
python3 cve_2025_55182.py -t https://target.example.com --scheme https

# 使用自定义 SSL 验证扫描
python3 cve_2025_55182.py -t https://target.example.com --no-verify-ssl

# 使用自定义重定向扫描
python3 cve_2025_55182.py -t https://target.example.com --no-redirect

# 使用自定义重试次数扫描
python3 cve_2025_55182.py -t https://target.example.com --retries 3

# 使用自定义延迟扫描
python3 cve_2025_55182.py -t https://target.example.com --delay 1

# 使用自定义随机延迟扫描
python3 cve_2025_55182.py -t https://target.example.com --random-delay

# 使用自定义随机 User-Agent 扫描
python3 cve_2025_55182.py -t https://target.example.com --random-user-agent

# 使用自定义随机请求头扫描
python3 cve_2025_55182.py -t https://target.example.com --random-headers

# 使用自定义随机 Cookie 扫描
python3 cve_2025_55182.py -t https://target.example.com --random-cookie

# 使用自定义随机方法扫描
python3 cve_2025_55182.py -t https://target.example.com --random-method

# 使用自定义随机数据扫描
python3 cve_2025_55182.py -t https://target.example.com --random-data

# 使用自定义随机路径扫描
python3 cve_2025_55182.py -t https://target.example.com --random-path

# 使用自定义随机端口扫描
python3 cve_2025_55182.py -t https://target.example.com --random-port

# 使用自定义随机协议扫描
python3 cve_2025_55182.py -t https://target.example.com --random-scheme

# 使用自定义随机 SSL 验证扫描
python3 cve_2025_55182.py -t https://target.example.com --random-no-verify-ssl

# 使用自定义随机重定向扫描
python3 cve_2025_55182.py -t https://target.example.com --random-no-redirect

# 使用自定义随机重试次数扫描
python3 cve_2025_55182.py -t https://target.example.com --random-retries

# 使用自定义随机延迟扫描
python3 cve_2025_55182.py -t https://target.example.com --random-delay

# 使用自定义随机随机延迟扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-delay

# 使用自定义随机随机 User-Agent 扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-user-agent

# 使用自定义随机随机请求头扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-headers

# 使用自定义随机随机 Cookie 扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-cookie

# 使用自定义随机随机方法扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-method

# 使用自定义随机随机数据扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-data

# 使用自定义随机随机路径扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-path

# 使用自定义随机随机端口扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-port

# 使用自定义随机随机协议扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-scheme

# 使用自定义随机随机 SSL 验证扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-no-verify-ssl

# 使用自定义随机随机重定向扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-no-redirect

# 使用自定义随机随机重试次数扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-retries

# 使用自定义随机随机延迟扫描
python3 cve_2025_55182.py -t https://target.example.com --random-random-delay```
http://localhost:8080/apk/private

apk 会将架构和索引文件名附加到每个仓库行本身。

GitHub Releases / mise (aqua 后端)

配置命名的通用上游:```yaml upstream: generic: github: "https://github.com" github-api: "https://api.github.com"

root@kitploit:~
然后重写 mise 设置中的 GitHub URL(`~/.config/mise/config.toml`,mise ≥ 2025.9.3):```toml
[settings.url_replacements]
"regex:^https://github\\.com/([^/]+)/([^/]+)/releases/download/(.+)" = "http://localhost:8080/generic/github/$1/$2/releases/download/$3"
"regex:^https://api\\.github\\.com/(.*)" = "http://localhost:8080/generic/github-api/$1"

Release assets 在首次下载后会被永久缓存,并在 GitHub 宕机期间继续安装。通过 api.github.com 进行的标签查询会按 metadata_ttl 缓存,并在服务中断或触发速率限制时提供过期数据。提交 mise.lock 并使用 mise install --locked 安装,这样固定版本的安装完全不需要 API 调用。如果集群规模超过 GitHub 的匿名速率限制,请在 upstream.auth 下为 https://api.github.com 添加 bearer token。

配置

代理可以通过以下方式配置:

  1. 命令行标志(最高优先级)
  2. 环境变量
  3. 配置文件(YAML 或 JSON)

命令行标志```

-config string Path to configuration file -listen string Address to listen on (default ":8080") -base-url string Public URL of this proxy (default "http://localhost:8080") -storage-url string Storage URL (file://, s3://, gs://, azblob://) -storage-path string Path to artifact storage directory (deprecated, use -storage-url) -database-driver string Database driver: sqlite or postgres (default "sqlite") -database-path string Path to SQLite database file (default "./cache/proxy.db") -database-url string PostgreSQL connection URL -log-level string Log level: debug, info, warn, error (default "info") -log-format string Log format: text, json (default "text") -access-log string Path to the JSONL access log -version Print version and exit

root@kitploit:~
### 环境变量```bash
PROXY_LISTEN=:8080
PROXY_BASE_URL=http://localhost:8080
PROXY_UI_URL=http://localhost:8080  # Optional; defaults to PROXY_BASE_URL
PROXY_STORAGE_URL=file:///var/cache/proxy/artifacts
PROXY_DATABASE_DRIVER=sqlite
PROXY_DATABASE_PATH=./cache/proxy.db
PROXY_DATABASE_URL=postgres://user:pass@localhost/proxy?sslmode=disable
PROXY_LOG_LEVEL=info
PROXY_LOG_FORMAT=text
PROXY_ACCESS_LOG_PATH=/var/log/proxy/access.jsonl
PROXY_UPSTREAM_SWIFT=https://tuist.dev/api/registry/swift

配置文件```yaml

listen: ":8080" base_url: "http://localhost:8080"

storage: url: "file:///var/cache/proxy/artifacts" max_size: "10GB" # Optional: evict LRU when exceeded

database: driver: "sqlite" path: "/var/lib/proxy/cache.db"

log: level: "info" format: "text"

access_log: path: "/var/log/proxy/access.jsonl" # Optional JSONL activity log

Optional: override upstream URLs

upstream: npm: "https://registry.npmjs.org" cargo: "https://index.crates.io" swift: "https://tuist.dev/api/registry/swift"

Optional: version cooldown (see above)

cooldown: default: "3d"

root@kitploit:~
请参阅[配置参考](https://github.com/git-pkgs/proxy/blob/main/docs/configuration.md#upstream-registries),了解每个上游键、环境变量和默认 URL。

使用配置文件运行:```bash
./proxy -config /etc/proxy/config.yaml

PostgreSQL

SQLite 是默认选项,适用于单节点部署。对于多节点部署,或者如果你更倾向于使用托管数据库,可以切换到 Postgres:```yaml database: driver: "postgres" url: "postgres://user:password@localhost:5432/proxy?sslmode=disable"

root@kitploit:~
或通过环境变量:```bash
PROXY_DATABASE_DRIVER=postgres
PROXY_DATABASE_URL=postgres://user:password@localhost:5432/proxy?sslmode=disable

代理在首次运行时自动创建表。

S3 存储

代理可以将缓存的构件存储在 S3 或任何兼容 S3 的服务(MinIO、R2 等)中,而不是本地文件系统。```yaml storage: url: "s3://my-bucket-name?region=us-east-1"

root@kitploit:~
对于像 MinIO 这样的 S3 兼容服务:```yaml
storage:
  url: "s3://my-bucket?endpoint=http://localhost:9000&disableSSL=true&s3ForcePathStyle=true"

通过标准 AWS 环境变量(AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY、AWS_REGION)设置凭证。

Google Cloud Storage

代理可以使用 gs:// URL 方案将缓存的构件存储在 GCS 存储桶中。```yaml storage: url: "gs://my-bucket-name"

root@kitploit:~
身份验证使用 [Application Default Credentials](https://docs.cloud.google.com/docs/authentication/application-default-credentials),这意味着无需在配置或环境中嵌入任何凭据。支持的来源按顺序如下:

- **GKE Workload Identity** — 将运行代理的 Kubernetes 服务账号绑定到在存储桶上具有 `roles/storage.objectAdmin` 权限的 Google 服务账号。代理将自动使用工作负载的令牌。
- GCE、Cloud Run、Cloud Functions 等上的**附加服务账号**。
- 指向服务账号 JSON 密钥文件的 **`GOOGLE_APPLICATION_CREDENTIALS`** 环境变量。
- 用于本地开发的 **`gcloud auth application-default login`**。

#### GKE Workload Identity 设置```bash
# 1. Create a Google service account
gcloud iam service-accounts create git-pkgs-proxy \
  --project=PROJECT_ID

# 2. Grant it access to the bucket
gsutil iam ch \
  serviceAccount:git-pkgs-proxy@PROJECT_ID.iam.gserviceaccount.com:objectAdmin \
  gs://my-bucket-name

# 3. Bind the Kubernetes service account to it
gcloud iam service-accounts add-iam-policy-binding \
  git-pkgs-proxy@PROJECT_ID.iam.gserviceaccount.com \
  --role=roles/iam.workloadIdentityUser \
  --member="serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/KSA_NAME]"

# 4. Annotate the Kubernetes service account
kubectl annotate serviceaccount KSA_NAME \
  --namespace=NAMESPACE \
  iam.gke.io/gcp-service-account=git-pkgs-proxy@PROJECT_ID.iam.gserviceaccount.com

使用 Workload Identity 的直接服务(签名 URL)

当启用 direct_serve: true 时,代理会发出 HTTP 302 重定向到预签名的 GCS URL。Workload Identity 不提供私钥,因此 GCS 后端会调用 IAM Credentials signBlob API。授予服务账号对自身的 token-creator 角色:```bash gcloud iam service-accounts add-iam-policy-binding
git-pkgs-proxy@PROJECT_ID.iam.gserviceaccount.com
--role=roles/iam.serviceAccountTokenCreator
--member="serviceAccount:git-pkgs-proxy@PROJECT_ID.iam.gserviceaccount.com"

root@kitploit:~
## CLI 命令

### serve(默认)

启动代理服务器。如果未指定命令,这是默认命令。```bash
proxy serve [flags]
proxy [flags]  # same as 'proxy serve'

mirror

从 PURL、SBOM 文件或整个注册表预填充缓存。适用于确保离线可用性或在部署前预热缓存。```bash

Mirror specific package versions

proxy mirror pkg:npm/[email protected] pkg:cargo/[email protected]

Mirror all versions of a package

proxy mirror pkg:npm/lodash

Mirror from a CycloneDX or SPDX SBOM

proxy mirror --sbom sbom.cdx.json

Preview what would be mirrored

proxy mirror --dry-run pkg:npm/lodash

Control parallelism

proxy mirror --concurrency 8 pkg:npm/[email protected]

root@kitploit:~
镜像命令接受与 `serve` 相同的存储和数据库标志。已缓存的构件会被跳过。

服务器运行时,还可以使用镜像 API:```bash
# Start a mirror job
curl -X POST http://localhost:8080/api/mirror \
  -H "Content-Type: application/json" \
  -d '{"purls": ["pkg:npm/[email protected]"]}'

# Start a mirror job from an inline CycloneDX or SPDX JSON SBOM
curl -X POST http://localhost:8080/api/mirror \
  -H "Content-Type: application/json" \
  -d '{"sbom":{"bomFormat":"CycloneDX","components":[{"purl":"pkg:npm/[email protected]"}]}}'

# Check job status
curl http://localhost:8080/api/mirror/mirror-1

# Cancel a running job
curl -X DELETE http://localhost:8080/api/mirror/mirror-1

stats

在不运行服务器的情况下显示缓存统计信息。```bash

Text output

proxy stats

JSON output

proxy stats -json

Custom database path

proxy stats -database-path /var/lib/proxy/cache.db

With PostgreSQL

proxy stats -database-driver postgres -database-url postgres://user:pass@localhost/proxy

Show top 20 most popular packages

proxy stats -popular 20

root@kitploit:~
示例输出:```
Cache Statistics
================

Packages:   45
Versions:   128
Artifacts:  128
Total size: 892.4 MB
Total hits: 1547

Packages by ecosystem:
  npm        32
  cargo      13

Most popular packages:
   1. npm/lodash (342 hits, 24.7 KB)
   2. npm/react (198 hits, 89.3 KB)
   3. cargo/serde (156 hits, 234.1 KB)

Recently cached:
  npm/[email protected] (2024-01-15 14:32, 54.2 KB)
  cargo/[email protected] (2024-01-15 14:28, 412.8 KB)

API 端点

注册表协议

镜像 API

端点描述
POST /api/mirror启动镜像任务(JSON 请求体包含 purls 或内联 sbom)
GET /api/mirror/{id}获取任务状态和进度
DELETE /api/mirror/{id}

增强 API

代理提供 REST 端点,用于包元数据增强、漏洞扫描和过期检测。

获取包元数据```bash

curl http://localhost:8080/api/package/npm/lodash

root@kitploit:~
Response:```json
{
  "ecosystem": "npm",
  "name": "lodash",
  "latest_version": "4.17.21",
  "license": "MIT",
  "license_category": "permissive",
  "description": "Lodash modular utilities",
  "homepage": "https://lodash.com/",
  "repository": "https://github.com/lodash/lodash",
  "registry_url": "https://registry.npmjs.org"
}

获取带漏洞的版本```bash

curl http://localhost:8080/api/package/npm/lodash/4.17.0

root@kitploit:~
(no input provided)```json
{
  "package": {
    "ecosystem": "npm",
    "name": "lodash",
    "latest_version": "4.17.21",
    "license": "MIT",
    "license_category": "permissive"
  },
  "version": {
    "ecosystem": "npm",
    "name": "lodash",
    "version": "4.17.0",
    "license": "MIT",
    "published_at": "2016-06-17T03:59:56Z",
    "yanked": false,
    "is_outdated": true
  },
  "vulnerabilities": [
    {
      "id": "GHSA-p6mc-m468-83gw",
      "summary": "Prototype Pollution in lodash",
      "severity": "HIGH",
      "cvss_score": 7.4,
      "fixed_version": "4.17.12"
    }
  ],
  "is_outdated": true,
  "license_category": "permissive"
}

检查过时的软件包```bash

curl -X POST http://localhost:8080/api/outdated
-H "Content-Type: application/json"
-d '{ "packages": [ {"ecosystem": "npm", "name": "lodash", "version": "4.17.0"}, {"ecosystem": "pypi", "name": "requests", "version": "2.25.0"} ] }'

root@kitploit:~
Response:```json
{
  "results": [
    {
      "ecosystem": "npm",
      "name": "lodash",
      "version": "4.17.0",
      "latest_version": "4.17.21",
      "is_outdated": true
    },
    {
      "ecosystem": "pypi",
      "name": "requests",
      "version": "2.25.0",
      "latest_version": "2.31.0",
      "is_outdated": true
    }
  ]
}

批量包查询```bash

curl -X POST http://localhost:8080/api/bulk
-H "Content-Type: application/json"
-d '{ "purls": [ "pkg:npm/[email protected]", "pkg:pypi/[email protected]" ] }'

root@kitploit:~
Response:```json
{
  "packages": {
    "pkg:npm/lodash": {
      "ecosystem": "npm",
      "name": "lodash",
      "latest_version": "4.17.21",
      "license": "MIT",
      "license_category": "permissive"
    },
    "pkg:pypi/requests": {
      "ecosystem": "pypi",
      "name": "requests",
      "latest_version": "2.31.0",
      "license": "Apache-2.0",
      "license_category": "permissive"
    }
  }
}

统计响应(HTTP 端点)```json

{ "cached_artifacts": 142, "total_size_bytes": 523456789, "total_size": "499.2 MB", "storage_url": "file:///path/to/cache/artifacts", "database_path": "./cache/proxy.db" }

root@kitploit:~
## 工作原理

1. 包管理器向代理请求包元数据
2. 代理从上游获取元数据,将制品 URL 重写为指向代理
3. 包管理器请求制品(tarball、crate 等)
4. 代理检查本地缓存:
   - **缓存命中**:从本地存储提供
   - **缓存未命中**:从上游获取,存储到本地,再提供给客户端
5. 对同一制品的后续请求将从缓存中提供```
┌─────────────┐     ┌─────────┐     ┌──────────┐
│   npm/cargo │────▶│  proxy  │────▶│ upstream │
│   client    │◀────│         │◀────│ registry │
└─────────────┘     └─────────┘     └──────────┘
                         │
                         ▼
                    ┌─────────┐
                    │  cache  │
                    │ storage │
                    └─────────┘

Web 界面

代理在 /ui 下提供 Web UI。无需单独构建前端——模板和资源已嵌入二进制文件中。GET / 会重定向到 /ui/。UI 挂载在其独立的前缀下,因此反向代理可以对其应用与包端点不同的访问规则(例如,对 PathPrefix(/ui) 要求认证,而将 /npm、/pypi 等保持对构建机器开放)。

  • 仪表盘(/ui/)——缓存统计、热门包、最近缓存的制品以及漏洞概览。
  • 安装指南(/ui/install)——各生态系统的配置说明,这样你就不必在这里查找它们。
  • 包浏览器(/ui/packages)——浏览所有已缓存的包,可按生态系统筛选,并按命中次数、大小、名称或漏洞数量排序。
  • 搜索(/ui/search?q=...)——按名称搜索已缓存的包。
  • 包详情(/ui/package/{ecosystem}/{name})——包的元数据、许可证、漏洞以及版本列表。你可以选择两个版本进行比较。
  • 版本详情(/ui/package/{ecosystem}/{name}/{version})——各版本的元数据、完整性哈希、制品缓存状态以及命中次数。
  • 源码浏览器(/ui/package/{ecosystem}/{name}/{version}/browse)——浏览已缓存归档中的文件,对文本文件提供语法高亮,并支持图片预览。
  • 版本差异(/ui/package/{ecosystem}/{name}/compare/{v1}...{v2})——两个已缓存版本的并排差异对比,显示新增、删除和更改的文件。

监控

代理在 GET /metrics 处暴露 Prometheus 指标。所有指标名称均以 proxy_ 为前缀。

缓存大小和制品数量每 60 秒刷新一次。断路器状态在每次抓取 /metrics 和每次 /health 请求时从 fetcher 读取,因此 proxy_circuit_breaker_trips_total 统计的是这些读取之间可见的跳闸次数——若断路器在两次抓取之间完全打开并恢复,则不会被计入。其余指标在每次请求时更新。

断路器指标为每个上游主机携带一个序列,但仅针对自启动以来断路器至少跳闸过一次的主机。代理会为每个从中获取制品的主机创建一个断路器,而对于某些生态系统,该主机来自上游元数据而非配置(composer 从包的 dist.url 获取,helm 从 index.yaml 中的 chart URL 获取),因此发布每个主机将让上游内容在进程生命周期内不断增长序列数量。一旦某个主机跳闸,它就会持续上报,因此恢复仍会表现为向 0 的转变,而不是序列消失。/health 不是持久时间序列,会列出每个断路器,无论是否跳闸。

registry 标签是获取制品所用 URL 的主机。由于该 URL 可能来自上游元数据,并不总能从中读出一个主机——例如一个无法解析的已签名 dist.url——此类断路器会被标记为 hostless-url-<digest>,其中 digest 以启动时新生成的值作为键。/metrics 和 /health 都不需要认证,因此获取 URL 绝不会作为标签或键发布;digest 在进程运行期间标识该断路器,既不泄露其背后的 URL,也不允许将选定的 URL 与之匹配。

对 proxy_circuit_breaker_state == 2 持续超过几分钟的情况设置告警:当断路器打开时,该上游的制品下载在每次缓存未命中时都会以 HTTP 502 失败,并且每个退避间隔只有一个探测请求到达上游。已缓存的制品仍会继续提供,同一生态系统的元数据也是如此(元数据不经过断路器),因此安装失败的方式看起来像是部分上游中断。

健康检查

/health 返回子系统健康状况的结构化 JSON 报告。如果所有检查通过则返回 HTTP 200;如果有任何失败则返回 503。```json { "status": "ok", "checks": { "database": {"status": "ok"}, "storage": {"status": "ok"} }, "circuit_breakers": { "registry.npmjs.org": "closed", "static.crates.io": "open" } }

root@kitploit:~
失败的检查会包含一个 `"error"` 字段。存储失败还会包含一个 `"step"` 字段,用于标识哪个探测步骤失败(`write`、`size`、`read`、`verify`、`delete`)。当数据库检查失败时,存储条目会报告 `{"status": "skipped"}`,因此响应始终携带相同的键集合。

`circuit_breakers` 报告每个上游的 artifact 获取熔断器的状态(`"open"` 或 `"closed"`),以上游主机为键——或者在获取 URL 没有可读取的主机时,使用 [Monitoring](#monitoring) 中描述的 `hostless-url-<digest>` 占位符作为键。在代理从至少一个上游获取过 artifact 之前,该键会被省略;并且只有当某个主机创建了熔断器后,该主机才会出现。熔断器在上游反复失败后跳闸,并在指数退避后重试上游。当某个熔断器处于打开状态时,该主机的 artifact 下载在缓存未命中时会返回 HTTP 502,且不会联系上游;已缓存的 artifact 仍会从存储中提供,因为缓存会在获取器之前被检查。熔断器在其整个退避期间都报告为 `"open"`,包括半开窗口——在该窗口中它允许一个探测请求以测试恢复情况。熔断器状态是按进程且保存在内存中的,因此重启会清除它,但恢复并不需要重启:只要熔断器处于打开状态,退避就会持续重试,因此一旦上游再次正常提供服务,它就会自行关闭。

打开的熔断器**不会**将 `status` 设置为 `"error"`,也不会更改 HTTP 状态码:它报告的是某个特定上游拒绝提供服务,而不是此代理不适合接收流量;并且因为一个不健康的上游而使就绪探测失败,会导致该 pod 对所有其他生态系统也被移出轮换。请使用 `proxy_circuit_breaker_state` 对其进行告警。

存储探测结果会缓存 `health.storage_probe_interval`(默认 30 秒),以限制探测远程后端的成本。一次探测最多持有内部互斥锁 10 秒(硬编码的每次探测超时),因此 `/health` 旨在作为 Kubernetes 的**就绪**探测,而不是存活探测——缓慢的 S3 往返应该将 pod 移出轮换,而不是重启它。

Prometheus 的抓取配置:```yaml
scrape_configs:
  - job_name: git-pkgs-proxy
    static_configs:
      - targets: ["localhost:8080"]

生产环境部署

Systemd 服务

创建 /etc/systemd/system/proxy.service:```ini [Unit] Description=git-pkgs proxy After=network.target

[Service] Type=simple User=proxy ExecStart=/usr/local/bin/proxy -config /etc/proxy/config.yaml Restart=always RestartSec=5

[Install] WantedBy=multi-user.target

root@kitploit:~
启用并启动:```bash
sudo systemctl enable proxy
sudo systemctl start proxy

Docker

仓库中包含一个 Dockerfile。构建并运行:```bash docker build -t proxy . docker run -p 8080:8080 -v proxy-data:/data proxy

root@kitploit:~
使用 Postgres 和 S3:```bash
docker run -p 8080:8080 \
  -e PROXY_DATABASE_DRIVER=postgres \
  -e PROXY_DATABASE_URL=postgres://user:pass@db:5432/proxy \
  -e PROXY_STORAGE_URL=s3://my-bucket?region=us-east-1 \
  -e AWS_ACCESS_KEY_ID=... \
  -e AWS_SECRET_ACCESS_KEY=... \
  proxy

在反向代理之后

当运行在 nginx、Apache 或其他反向代理之后时,将 base_url 设置为你的公共 URL:```yaml base_url: "https://proxy.example.com"

root@kitploit:~
如果通过不同于软件包端点的主机名访问 UI——例如,UI 公开暴露在某个域名上,而构建机器访问的是 Docker 网络别名——则需单独设置 `ui_base_url`。`base_url` 是包管理器和元数据重写所使用的 URL;`ui_base_url` 是向访问 Web UI 的用户公布的 URL(canonical/`og:url` 标签以及安装指南横幅):```yaml
base_url: "http://pkg-proxy:8080"        # internal alias for build machines
ui_base_url: "https://proxy.example.com/ui"  # public UI URL

当未设置时,ui_base_url 默认为 base_url。

警告: 代理在同一监听器上同时提供 UI 和包端点。设置 ui_base_url 只会改变 UI 向人类展示的 URL;它并不会阻止包端点在同一主机名和端口上被访问。当使用公共反向代理前置该代理时,应将公共路由限制为 PathPrefix(/ui)(或你的代理的等效配置),否则 /npm、/pypi 以及其他包端点会与 UI 一起暴露。

nginx 示例,将公共主机限制为仅 UI,同时让包端点仅可在内部监听器上访问:```nginx server { listen 443 ssl; server_name proxy.example.com;

root@kitploit:~
location /ui/ {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_buffering off;
}

location / {
    return 404;
}

}

root@kitploit:~
使用 `PathPrefix(/ui)` 的 Traefik 示例,使公共路由器仅匹配 UI 流量:```yaml
labels:
  traefik.enable: "true"
  traefik.http.services.pkg-proxy.loadbalancer.server.port: "8080"
  traefik.http.routers.pkg-proxy.rule: "Host(`proxy.example.com`) && PathPrefix(`/ui`)"
  traefik.http.routers.pkg-proxy.entrypoints: "websecure"

缓存管理

代理将构件存储在配置的存储目录中,结构如下:``` cache/artifacts/ ├── npm/ │ └── lodash/ │ └── 4.17.21/ │ └── lodash-4.17.21.tgz ├── cargo/ │ └── serde/ │ └── 1.0.193/ │ └── serde-1.0.193.crate ├── oci/ │ └── library/nginx/ │ └── sha256:abc123.../ │ └── sha256:abc123... ├── deb/ │ └── nginx/ │ └── 1.18.0-6/ │ └── nginx_1.18.0-6_amd64.deb └── rpm/ └── nginx/ └── 1.24.0-1.fc39/ └── nginx-1.24.0-1.fc39.x86_64.rpm

root@kitploit:~
缓存元数据存储在 SQLite(默认)或 PostgreSQL 中。要清除本地缓存:```bash
rm -rf ./cache/artifacts/*
rm ./cache/proxy.db

代理将在下次启动时重新创建数据库。

从源码构建

要求:

  • Go(项目版本在 go.mod 中声明)```bash git clone https://github.com/git-pkgs/proxy.git cd proxy go build -o proxy ./cmd/proxy
root@kitploit:~
运行测试:```bash
go test ./...

许可证

GPL-3.0-or-later

下载工具
注册表语言/平台冷却已完成
npmJavaScript是✓
CargoRust是✓
RubyGemsRuby是✓
Go proxyGo✓
HexElixir是*✓
pub.devDart是✓
PyPIPython是✓
MavenJava✓
Gradle Build CacheJava/Kotlin✓
NuGet.NET是✓
ComposerPHP是✓
ConanC/C++✓
CondaPython/R是✓
CRANR✓
JuliaJulia✓
SwiftSwift✓
ContainerDocker/OCI✓
HomebrewmacOS/Linux✓
DebianDebian/Ubuntu✓
RPMRHEL/Fedora✓
AlpineAlpine Linux✓
ArchArch Linux✗
ChefChef✗
GenericAny✓
HelmKubernetes✓
VagrantVagrant✗
端点描述
GET /仪表盘(Web UI)
GET /health健康检查及上游断路器状态(JSON;HTTP 200 表示健康,503 表示不健康)
GET /stats缓存统计信息(JSON)
GET /metricsPrometheus 指标
GET /npm/*npm 注册表协议
GET /cargo/*Cargo 稀疏索引协议
GET /gem/*RubyGems 协议
GET /go/*Go 模块代理协议
GET /hex/*Hex.pm 协议
GET /pub/*pub.dev 协议
GET /pypi/*PyPI simple/JSON API
GET /maven/*Maven 仓库协议
GET /nuget/*NuGet V3 API
GET /composer/*Composer/Packagist 协议
GET /conan/*Conan C/C++ 协议
GET /conda/*Conda/Anaconda 协议
GET /cran/*CRAN (R) 协议
GET /julia/*Julia Pkg 服务器协议
GET /swift/*Swift Package Registry v1 协议
GET /helm/{repository}/*HTTP Helm chart 仓库协议
GET /homebrew/*Homebrew JSON API
GET /v2/*OCI/Docker 注册表协议
GET /v2/homebrew/core/*来自 GHCR 的 Homebrew core bottle 清单和 blob
GET /apk/{repository}/*Alpine APK 仓库协议
GET /generic/{name}/*通用 HTTP 下载代理(GitHub release 资产、mise/aqua)
GET /debian/*Debian/APT 仓库协议
GET /rpm/*RPM/Yum 仓库协议
取消正在运行的任务
端点描述
GET /api/package/{ecosystem}/{name}获取包元数据
GET /api/package/{ecosystem}/{name}/{version}获取包含漏洞的版本元数据
GET /api/vulns/{ecosystem}/{name}获取包的所有漏洞
GET /api/vulns/{ecosystem}/{name}/{version}获取特定版本的漏洞
POST /api/outdated检查多个包的过期版本
POST /api/bulk批量包元数据查询
指标类型标签描述
proxy_requests_totalcounterecosystem、status按包生态系统和 HTTP 状态统计的代理响应数
proxy_request_duration_secondshistogramecosystem、status代理请求耗时
proxy_cache_hits_totalcounterecosystem缓存命中次数
proxy_cache_misses_totalcounterecosystem缓存未命中次数
proxy_cache_size_bytesgauge已缓存制品的总大小
proxy_cached_artifacts_totalgauge已缓存制品的数量
proxy_upstream_fetch_duration_secondshistogramecosystem从上游获取所花费的时间
proxy_upstream_errors_totalcounterecosystem、error_type上游获取失败次数
proxy_storage_operation_duration_secondshistogramoperation存储读/写延迟
proxy_storage_errors_totalcounteroperation存储读/写失败次数
proxy_active_requestsgauge进行中的请求数
proxy_health_probe_failures_totalcounterstep按失败步骤(write、size、read、verify、delete)统计的存储健康探测失败次数。
proxy_circuit_breaker_stategaugeregistry每个上游注册表的制品获取断路器状态(0 为关闭,2 为打开)。在该注册表的断路器跳闸后发布。
proxy_circuit_breaker_trips_totalcounterregistry每个上游注册表的断路器跳闸次数。