Forward HTTPS client ip from Google Container Engine
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Google Container Engine, now known as Google Kubernetes Engine (GKE), offers a powerful platform for deploying containerized applications in the cloud. When deploying applications using GKE, it is often necessary to track the originating IP address of client requests for security and logging purposes. In an HTTPS scenario, this can be complex due to SSL termination at the load balancer or ingress level in GKE. This article will explore methods to forward the client IP address in a GKE environment.
Understanding SSL Termination
When you deploy an application in GKE behind a Google Cloud Load Balancer, SSL termination usually occurs at the load balancer level. This means that the SSL connection is decrypted there before forwarding to your backend services. While this ensures efficient load distribution and security management, it poses challenges in transmitting the original client IP to your application.
How SSL Termination Works
- Client to Load Balancer: The client initiates an SSL handshake and establishes a secure connection with the load balancer.
- Load Balancer: The load balancer decrypts the incoming traffic and terminates the SSL.
- Load Balancer to Backend: Unencrypted traffic is forwarded to the backend services.
Forwarding the Client IP
To forward the client IP to your application, you need to handle the incoming HTTP headers correctly. The `X-Forwarded-For` header is instrumental in this process.
X-Forwarded-For Header
The `X-Forwarded-For` (XFF) header is an HTTP header used to identify the originating IP address of a client connecting to a web server through a proxy or load balancer. In most GKE setups, this header is automatically added by the Google Cloud Load Balancer.
Example of an XFF Header:
- host: example.com
- path: /
- from:
- ipBlock:
Related reading
- Frontend communication with API in Kubernetes cluster
- GCE ingress with routes always falls back to default-http-backend
- Get context from Pod launched with Airflow KubernetesPodOperator
- Get current image of kubernetes deployment
- From inside of a Docker container, how do I connect to the localhost of the machine?
- Get docker-compose.yml file location from running container?
- GCE VM can't connect to TPU
- General Knowledge Question Network Access Time, Cache Access Time, Disk Access Time

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.