Securing Kubernetes API on Azure only accessible by Local IP (RFC1918) - azure

Notice that when I create a Azure Kubernetes, by default it creates the API with an *.azmk8s.io FQDN and it is external facing.
Is there a way to create with local IP instead? If "yes", can this be protected by NSG and Virtual Network to limit connections coming via Jump Server?
If there is any drawback creating to only allow internal IP?
Below is the command I used to create:-
az aks create -g [resourceGroup] -n
[ClusterName]  --windows-admin-password [SomePassword]
--windows-admin-username [SomeUserName] --location [Location] --generate-ssh-keys -c 1 --enable-vmss --kubernetes-version 1.14.8 --network-plugin azure
Anyone tried https://learn.microsoft.com/en-us/azure/aks/private-clusters? If that still allows external facing app but private management API?

why not? only the control plane endpoint is different. in all other regards - its a regular AKS cluster.
In a private cluster, the control plane or API server has internal IP
addresses that are defined in the RFC1918 - Address Allocation for
Private Internets document. By using a private cluster, you can ensure
that network traffic between your API server and your node pools
remains on the private network only.
this outlines how to connect to private cluster with kubectl. NSG should work as usual

Related

AKS Assign a DNS name to private ClusterIP address

I don't know how to implement this problem:
I have this private AKS cluster with 4 microservices (.net5) and a frontend. These 4 microservices talk to each other via HTTP requests using their public IP addresses (not good because I want them to have only a private endpoint, like microservicename.api.my-namespace.svc.cluster-domain.example).
Frontend (that has a public DNS and IP) should then be able to request a main API in that private endpoint.
I need to implement a solution to this, and also I feel like that communicating between microservices via HTTP requests on a certain endpoint is not a good design pattern, so I wanted some suggestions on this aspect also.
Many thanks
• You can use the Azure Private Link Service in this case to establish communication between the private AKS cluster and the frontend through the private endpoint that will be exposed in the subnet of the private AKS cluster.
• The Private Link service is supported on Standard Azure Load Balancer only. Basic Azure Load Balancer isn't supported. To use a custom DNS server, add the Azure DNS IP 168.63.129.16 as the upstream DNS server in the custom DNS server.
• You can create a private AKS cluster consisting of the four microservices using the below command with a private DNS zone or a custom private DNS zone: -
‘az aks create -n -g --load-balancer-sku standard --enable-private-cluster --enable-managed-identity --assign-identity --private-dns-zone [system|none]’ – with a private DNS zone (system for default value & none for public DNS zone)
‘az aks create -n -g --load-balancer-sku standard --enable-private-cluster --enable-managed-identity --assign-identity --private-dns-zone --fqdn-subdomain ’
• If the Private DNS Zone is in a different subscription than the AKS cluster, you need to register Microsoft.ContainerServices in both the subscriptions. Additionally, you will need a user assigned identity or service principal with at least the private dns zone contributor and vnet contributor roles. "fqdn-subdomain" can be utilized with "CUSTOM_PRIVATE_DNS_ZONE_RESOURCE_ID" only to provide subdomain capabilities to privatelink..azmk8s.io
• Next, you would need to use a VM that has access to the AKS cluster's Azure Virtual Network (VNet). There are several options for establishing network connectivity to the private cluster such as create a VM in the same Azure Virtual Network (VNet) as the AKS cluster or use a VM in a separate network and set up Virtual network peering. Thus, you can create a private link with a private endpoint for the four microservices in the private AKS cluster and provide connection to the frontend API.
Please refer the below link for more details: -
https://learn.microsoft.com/en-us/azure/aks/private-clusters

Cannot access Private AKS cluster from Local Machine (on home network) connected to Azure VPN

I have a Private AKS cluster deployed in a VNET on Azure. Once I deployed it, a private endpoint and a private DNS zone were created by default therefore making the cluster accessible from VM's which are part of the same VNET. (I have a VM deployed in the same VNET as the AKS cluster and "kubectl" commands work in it.)
My requirement is that I want to perform the "kubectl" commands from my local machine (connected to my home network) and also connected to the VPN which connects to the VNET.
My machine can talk to resources within the VNET but cannot seem to resolve the FQDN of the private cluster.
I read somewhere that having a DNS forwarder setup in the same VNET can help resolve the DNS queries made from the local machine which can then be resolved by Azure DNS. Is this the way to go about this? Or is there a better way to solve this problem?
It would really help if someone could give me an action plan to follow to solve this problem.
The better way to perform the "kubectl" commands from your local machine to your private AKS cluster is to use AKS Run Command (Preview). This feature allows you to remotely invoke commands in an AKS cluster through the AKS API. This feature provides an API that allows you to, for example, execute just-in-time commands from a remote laptop for a private cluster. Before using it, you need to enable the RunCommandPreview feature flag on your subscription and install aks-preview extension locally. However, there is a limitation that AKS-RunCommand does not work on clusters with AKS managed AAD and Private link enabled.
In this case, If you want to resolve the FQDN of the private cluster from your on-premise network, you could select to use either the hosts file locally(used for testing) or use your DNS forwarder to override the DNS resolution for a private link resource like this.
The DNS forwarder will be responsible for all the DNS queries via a server-level forwarder to the Azure-provided DNS 168.63.129.16.You can provision IaaS Windows VM with DNS role or Linux VM with bind configured as a DNS forwarder. This template shows how to create a DNS server that forwards queries to Azure's internal DNS servers for Linux VM. Refer to this for DNS forwarder on Windows VM.
If there is an internal DNS server in your on-premise network. The on-premises DNS solution needs to forward DNS traffic to Azure DNS via a conditional forwarder for your public DNS zones(e.g. {region}.azmk8s.io). The conditional forwarder references the DNS forwarder deployed in Azure. You could read this blog about DNS configuration sections for more details.

How Can I Turn On enableprivateipaddress Flag For Virtual Network Gateway?

I'm following these tutorials to enable a site-to-site connection on Windows Azure. I'm trying to connect a VPN to a virtual machine so I can access it via private IP.
https://learn.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-howto-multi-site-to-site-resource-manager-portal#part3
https://learn.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-howto-site-to-site-classic-portal
While creating the connection for the device to the virtual private gateway, I am getting the following error:
Failed to update the configuration for connection
...Error:UseLocalAzureIpAddress cannot be set...virtual network
gateway...does note have 'EnablePrivateIpAddress' flag set.
Also, I have tried to enable it under Virtual Private Gateway -> Configuration but there is no option for private IP.
Does anyone know how I can enable this either through the Azure portal or powershell?
As the hint on the right of the Use Azure Private IP Address tab. It's only supported on AZ SKUs. You have to deploy the Zone-redundant VPN gateways to enable this feature.
Also, VpnGw1AZ, VpnGw2AZ, VpnGw3AZ, VpnGw4AZ, and VpnGw5AZ are the zone resilient versions of VpnGw1, VpnGw2, VpnGw3, VpnGw4, and VpnGw5.
Please note that
Zone-redundant gateways and zonal gateways both rely on the Azure
public IP resource Standard SKU. The configuration of the Azure public
IP resource determines whether the gateway that you deploy is
zone-redundant, or zonal. If you create a public IP resource with a
Basic SKU, the gateway will not have any zone redundancy, and the
gateway resources will be regional.
Reference: https://learn.microsoft.com/en-us/azure/vpn-gateway/about-zone-redundant-vnet-gateways

Cannot connect to Private, Regional GKE endpoint from OpenVPN client

I created the GKE Private Cluster via Terraform (google_container_cluster with private = true and region set) and installed the stable/openvpn Helm Chart. My setup is basically the same as described in this article: https://itnext.io/use-helm-to-deploy-openvpn-in-kubernetes-to-access-pods-and-services-217dec344f13 and I am able to see a ClusterIP-only exposed service as described in the article. However, while I am connected to the VPN, kubectl fails due to not being able to reach the master.
I left the OVPN_NETWORK setting as the default (10.240.0.0), and changed the OVPN_K8S_POD_NETWORK and subnet mask setting to the secondary range I chose when I created my private subnet that the Private Cluster lives in.
I even tried adding 10.240.0.0/16 to my master_authorized_networks_config but I'm pretty sure that setting only works on external networks (adding the external IP of a completely different OVPN server allows me to run kubectl when I'm connected to it).
Any ideas what I'm doing wrong here?
Edit: I just remembered I had to set a value for master_ipv4_cidr_block in order to create a Private Cluster. So I added 10.0.0.0/28 to the ovpn.conf file as push "route 10.0.0.0 255.255.255.240" but that didn't help. The docs on this setting states:
Specifies a private RFC1918 block for the master's VPC. The master
range must not overlap with any subnet in your cluster's VPC. The
master and your cluster use VPC peering. Must be specified in CIDR
notation and must be /28 subnet.
but what's the implication for an OpenVPN client on a subnet outside of the cluster? How do I leverage the aforementioned VPC peering?
Figured out what the problem is: gcloud container clusters get-credentials always writes the master's external IP address to ~/.kube/config. So kubectl always talks to that external IP address instead of the internal IP.
To fix: I ran kubectl get endpoints, noted the 10.0.0.x IP and replaced the external IP in ~/.kube/config with it. Now kubectl works fine while connected to the OVPN server inside of the Kube cluster.
You can add --internal-ip to your gcloud command to put automatically the internal ip address to ~/.kube/config file

Expose containers to private network

I am looking for a way to create a docker cluster (probably kubernetes) on azure, and expose the containers only via a vnet to my datacenter.
Is such a setup possible?
That is that the container services can only be access via the vpn that is created. So that the container can use private resources (mainly database) not available in the azure cloud?
And so that I can access the resources in the cloud, only from my dc.
Yes, that is perfectly possible. depending on your setup you need to deploy regular kubernetes cluster and use site-to-site VPN to connect networks or use ACS engine to deploy kubernetes into existing vnet\subnet.
You would also need to tweak your network security group rules to allow traffic to flow (if you have them).
https://github.com/Azure/acs-engine/tree/master/examples/vnet
https://learn.microsoft.com/en-us/azure/container-service/kubernetes/container-service-kubernetes-walkthrough
https://blogs.technet.microsoft.com/canitpro/2017/06/28/step-by-step-configuring-a-site-to-site-vpn-gateway-between-azure-and-on-premise/
I am looking for a way to create a docker cluster (probably
kubernetes) on azure, and expose the containers only via a vnet to my
datacenter.
Yes, we just create k8s pod, and not expose it to internet. Then create S2S VPN connect Azure Vnet to your DC, in this way, your DC's VMs can connect to Azure K8S pod via Azure private IP address.
Update:
If you want to connect your K8S pods via VPN, we can create Azure route table to achieve that.
More information about create route table, please refer to my another answer.

Resources