google-app-engine - GKE 上用于出口到 GAE 应用程序的 IP 地址是 0.0.0.0,而不是带有 Cloud NAT 的 IPv4
问题描述
在我发布相关问题后很长时间过去了。 关联
现在,问题变了。使用相同的程序进行集群和 NAT 设置,GAE 应用程序显示0.0.0.0,而不是 IPv6 地址。
※GAE 应用程序使用自定义域。
如果出口通信是使用本地服务器,服务器会显示一个静态 IP 地址,由 NAT 设置。
Google 内部网络有什么变化吗?当我想要一个确切的静态 IP 地址时,我想知道如何避免这个问题。
1.create a VPC
gcloud compute networks create ${vpc_name}\
--project=${project_id}\
--bgp-routing-mode=regional\
--subnet-mode=custom
2. create a subnet
gcloud compute networks subnets create ${subnet_name}\
--project=${project_id}\
--region=${region}\
--network=${vpc_name}\
--range=192.168.0.0/16
3. create an external static IP
gcloud compute addresses create ${external_ip_name}\
--region=${region}
4. create a route
gcloud compute routers create ${router_name}\
--region=${region}\
--network=${vpc_name}\
--asn=65001
5. create a nat
gcloud compute routers nats create ${nat_name}\
--region=${region}\
--router=${router_name}\
--nat-external-ip-pool="${external_ip}"\
--nat-all-subnet-ip-ranges
6. make a cluster
gcloud container clusters create ${gke_cluster_name}\
--project=${project_id}\
--zone=${zone}\
--network=${vpc_name}\
--subnetwork=${subnet_name}\
--enable-ip-alias\
--enable-private-nodes\
--master-ipv4-cidr=172.16.0.0/28\
--enable-master-authorized-networks\
--master-authorized-networks=0.0.0.0/0\
--no-enable-legacy-authorization\
--no-enable-basic-auth\
--no-issue-client-certificate\
--num-nodes=${NUM_NODE}\
--enable-autoscaling --max-nodes=${MAX_NUM} --min-nodes=${MIN_NUM}\
--scopes="cloud-platform"
7. deploy an application to the cluster and confirm the IP
从应用程序到其他 gcp 项目的应用程序进行 https 连接。并将 origin-request 的 IP 地址检测为“REMOTE_ADDR”。
解决方案
感谢您的澄清。所以基本上这就是我们所拥有的:
私有 GKE -> Cloud NAT -> 外部 GAE 负载均衡器 -> GAE
并且 GAE 中的应用程序看到一个 ipv6 地址
当您使用 Cloud NAT 时,默认情况下会启用 Google Private Access,因此从您的 VPC 到 GAE 的请求将使用 Private Access。
Private Access 将使用 Google 内部网络来路由请求,以确保不使用公共互联网。为了正确路由它,我们使用 IPv6。
解释 IPv6 地址:
Google 使用一组 NAT64 前缀:fda3:e722:ac3:10::/64。此值在所有 GCP VPC 网络中保持不变。最后 32 位直接从发出请求的主机的内部 IP 地址转换而来。这从二进制转换为十六进制(即十进制的 10.132.0.5 -> 十六进制的 0x0a840005)。
NAT64 前缀和最后 32 位之间的中间部分是您的 VPC 的唯一标识符。此标识符对于每个 VPC 网络都是唯一的,因此每个项目可以有多个。
目前,没有办法预先预测这个标识符。获取此信息的最佳方式是通过 Private Access 向 GAE 发送请求,并记下列为源的 IPv6。服务器的响应和 Stackdriver 日志中都提供了 IPv6 地址。
使用此信息,您应该能够充分维护 GAE 托管应用程序的白名单。
话虽如此,如果您看到 GKE pod 中的 IPv4 地址在 GAE 应用程序中显示为 0.0.0.0。我鼓励您使用此链接报告此问题
推荐阅读
- java - 如何通过java从PDF文件中读取行并存储在数据库表中
- javascript - 基于 id Javascript 更新数组
- dryioc - 容器对 .net 5 web 应用程序和测试项目有不同的规则
- java - Prisma 易受攻击的依赖项未显示在 Maven 依赖项中:树
- arrays - Powershell自动填充数组
- sql - 如果变量为空,则插入默认值
- android - 将硬件键盘连接到 android 时禁用指定键
- git - Git 在拉取请求时排除文件
- javascript - 如何使用“ngFor”而不重复应用它的元素?
- android - 如何在 PWA 对话框中检测安装点击事件?