DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 ArgoCD 报错 git ls-remote exit status 128 鉴权失败

分析 ArgoCD 连接私有 Git 仓库报 git ls-remote exit status 128 permission denied 根因,提供 Repository 凭证更新与 Secret 配置方案。

问题现象

在 ArgoCD 中添加私有 Git 仓库或同步应用时,应用状态变为 ComparisonError,UI 报错显示:

rpc error: code = Unknown desc = error testing repository connectivity:
command `git ls-remote https://github.com/my-org/my-repo.git HEAD` failed exit status 128:
fatal: could not read Username for 'https://github.com': terminal prompts disabled

或者使用 SSH 协议时提示:Permission denied (publickey). fatal: Could not read from remote repository.。

触发根因

ArgoCD Repo-Server 在与远程 Git 仓库交互时运行在非交互式容器内:

  1. 私有仓库缺少认证凭据:未在 ArgoCD 中配置该仓库的 SSH 私钥或 Personal Access Token (PAT)。
  2. Access Token 已过期或权限不足:GitHub/GitLab 的 Token 到期,或者缺少 repo 读取权限。
  3. SSH 私钥格式问题或缺少换行符:在 Secret 中粘贴私钥时破损。

诊断排查步骤

  1. 检查 ArgoCD 中配置的仓库状态:
argocd repo list

查看 CONNECTION STATUS 是否显示为 Failed。

解决步骤与操作命令

方案 A:使用 Personal Access Token (PAT) 重新认证(HTTPS 协议)

使用具有只读仓库权限的 Token 更新仓库配置:

argocd repo add https://github.com/my-org/my-repo.git   --username my-service-account   --password ghp_YourPersonalAccessToken123456

方案 B:使用 SSH 私钥建立安全连接(SSH 协议)

生成专用的 Deploy Key(不要设置密码):

ssh-keygen -t ed25519 -C "argocd-deploy-key" -f /tmp/argocd_id_ed25519 -N ""
  1. 将公钥 /tmp/argocd_id_ed25519.pub 添加到 GitHub 仓库的 Settings -> Deploy Keys。
  2. 将私钥配置给 ArgoCD:
argocd repo add git@github.com:my-org/my-repo.git   --ssh-private-key-path /tmp/argocd_id_ed25519

方案 C:在 Kubernetes 中直接声明 Repository Secret

创建规范的 Secret 纳管凭据:

apiVersion: v1
kind: Secret
metadata:
  name: private-repo-secret
  namespace: argocd
  labels:
    argocd.argoproj.io/secret-type: repository
stringData:
  type: git
  url: git@github.com:my-org/my-repo.git
  sshPrivateKey: |
    -----BEGIN OPENSSH PRIVATE KEY-----
    ...
    -----END OPENSSH PRIVATE KEY-----

应用该清单:

kubectl apply -f repo-secret.yaml

步骤三:验证连接成功

在 ArgoCD Web UI 上刷新仓库列表,状态立即变为绿色 Successful,应用完成秒级同步。