You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Source Repositories配置Private Google Access并解决SSH访问超时

问题分析与解决步骤

核心原因

Private Google Access(PGA)默认仅支持通过HTTP/HTTPS(80/443端口)访问Google服务,你使用的SSH协议(2022端口)无法通过PGA直接路由到Google内部服务端点,这是连接超时的关键原因。

解决方案选项

选项1:改用HTTPS协议克隆代码

Source Repositories支持HTTPS方式克隆,这种方式可直接通过PGA正常访问,无需额外配置。命令格式如下:

git clone https://source.developers.google.com/p/source-proj/r/repo1

若需认证,可先用gcloud生成凭证:

gcloud auth git-helper --account=my.email@myorg.com config --global

之后执行HTTPS克隆命令即可自动完成认证。

选项2:配置Private Service Connect实现SSH访问

若必须使用SSH协议,需创建Private Service Connect端点映射source.developers.google.com的2022端口:

  1. 在VPC网络中创建Private Service Connect端点:
    gcloud compute forwarding-rules create source-repo-ssh-psc \
        --network=default \
        --region=你的区域 \
        --target-service-attachment=projects/google-services/regions/你的区域/serviceAttachments/source-repos-ssh
    
    (若需指定内部IP,添加--address=你的内部IP参数即可)
  2. 在内部DNS区域创建记录,将source.developers.google.com解析到上述端点的内部IP:
    gcloud dns record-sets create source.developers.google.com. \
        --zone=你的内部DNS区域 \
        --type=A \
        --ttl=300 \
        --rrdatas=PSC端点的内部IP
    

选项3:确认Private Google Access的子网配置

检查PGA是否针对整个子网启用:

gcloud compute networks subnets describe default \
    --region=你的区域 \
    --format="value(privateIpGoogleAccess)"

若输出为False,执行以下命令启用:

gcloud compute networks subnets update default \
    --region=你的区域 \
    --enable-private-ip-google-access

验证步骤

完成配置后,先测试DNS解析:

nslookup source.developers.google.com
  • 若用HTTPS方式,测试连接可用性:
    curl -v https://source.developers.google.com
    
  • 若用SSH方式,测试端口连通性:
    nc -zv source.developers.google.com 2022
    

内容的提问来源于stack exchange,提问作者rossco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 18:20:42