This post has been republished via RSS; it originally appeared at: Core Infrastructure and Security Blog articles.
Azure Kubernetes Service (AKS) clusters, whether deployed into a managed or custom virtual network, have certain outbound dependencies necessary to function properly. Previously, in environments requiring internet access to be routed through HTTP proxies, this was a problem. Nodes had no way of bootstrapping the configuration, environment variables, and certificates necessary to access internet services.
This feature adds HTTP proxy support to AKS clusters, exposing a straightforward interface that cluster operators can use to secure AKS-required network traffic in proxy-dependent environments.
Both AKS nodes and Pods will be configured to use the HTTP proxy. Here is an architecture diagram showing the different components.
If you are more comfortable with video content type, I have created one for you. It is available on Youtube.
Deploy demo using Terraform
You will create an environment where AKS egress traffic go through an HTTP Proxy server.
You will use MITM-Proxy as an HTTP Proxy server for AKS. Note you can use another proxy servers like `Squidhead` or `Zscaler`.
The source code and templates are available in this Github repository: https://github.com/HoussemDellai/docker-kubernetes-course/tree/main/67_egress_proxy
Generate Certificate for MITM-Proxy server
By default, MITM6-Proxy generates a certificate when it starts. You can get this certificate from ~\.mitmproxy\ folder and use it with AKS.
But, for an enterprise use case, they will create their own certificate and then import it into MITM-Proxy. That is what you will do here.
Refer to the script ``generate-cert.sh` to generate a certificate for MITM-Proxy and print it as base64 encoded.
An Azure VM `vm-linux-proxy-mitm.tf` will be used to install MITM-Proxy and import the generated certificate. Note how it runs the script `install-mitmproxy.sh` as custom data. For simplicity, the certificate will be imported from a Git repository.
To configure AKS with an HTTP Proxy, you should use the following configuration sample.
Now you can deploy the Terraform template using the following commands.
Check the created resources
Testing the HTTP Proxy
Deploy a sample Nginx pod and check the injected environment variables for the Proxy server.
Note the variables: httpProxy, httpsProxy, noProxy and trustedCa.
Check also these environment variables are injected into the cluster nodes.
Bypass HTTP Proxy
By default, all egress traffic for nodes and pods will go through the Proxy because the environment variables for proxy are injected into all pods and nodes.
However, if you need to bypass the proxy, you just need to not inject these environment variables.
In kubernetes, this could be done declaratively using the annotation "kubernetes.azure.com/no-http-proxy-vars": "true".
Now if you check the environment variables for this pod, you will notice that the environment variables for the proxy were not injected.
And if you try to connect to internet, the egress traffic will be carried through the cluster Load Balancer and it's Public IP address.
Updating Proxy configuration
You can update a cluster with existing proxy settings, but could not enable proxy for existing cluster.
An AKS update for httpProxy, httpsProxy, and/or NoProxy will automatically inject new environment variables into pods with the new httpProxy, httpsProxy, or NoProxy values.
Pods must be rotated for the apps to pick it up.
For components under kubernetes, like containerd and the node itself, this won't take effect until a node image upgrade is performed.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.