Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit ec9bc2d

Browse files
authored
Advanced networking arm templates (#302)
* advanced networking arm templates * use correct file name * review comments * fix deployment errors * making sure that 3389 port is enabled on vm * doc updates * create uniquestring * remove quotes * read me updates and clean up
1 parent e780ef5 commit ec9bc2d

File tree

4 files changed

+699
-0
lines changed

4 files changed

+699
-0
lines changed

advanced networking/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Advanced Networking
2+
This directory contains scripts and ARM templates to deploy resources which would show how to securely debug your projects using Azure Dev Spaces in a secured virtual network.
3+
4+
## Overview
5+
These ARM templates deploy a virtual network with an Azure firewall. The virtual network and Azure firewall ensure the traffic into and out of the virtual network is secured and monitored by the firewall. The AKS cluster is deployed into a private virutal network into the `aks-subnet`. An Azure Dev Spaces controller with `private` endpoint is also created on this AKS cluster and the controller's endpoint is only available in the same virtual network as the AKS cluster. To use Azure Dev Spaces to start debugging your projects, the ARM templates deploy a Windows 10 virtual machine in the `vm-subnet` subnet, which is also in the same virtual network as the AKS cluster.
6+
The Azure Dev Spaces routing capabilities as well as the endpoints of your services are only available within the virtual network.
7+
8+
To learn more about the network architecture of Azure Dev Spaces and configuring its endpoint types see [Configure networking for Azure Dev Spaces in different network topologies.](https://aka.ms/azds-networking)
9+
10+
## Prerequisites
11+
1. This scripts requires `az cli` & `kubectl` to set up the resources.
12+
2. Ensure that the subscription has `Microsoft.ContainerInstance` & `Microsoft.Storage` resource providers are registered. This is required as the
13+
templates uses arm's deploymentScripts resource.
14+
15+
## Deploying the ARM template
16+
This folder contains following files which would help in deploying resources:
17+
* `devspaces-vnet-template.json` is the ARM template
18+
* `devspaces-vnet-parameters.json` defines the parameter values for the ARM template
19+
* `deploy.sh` is a script you can use to automate the deployment of the ARM template
20+
21+
When using the `deploy.sh` script to deploy the ARM template, the script prompts you for the necessary values. For example:
22+
```
23+
$ chmod +x ./deploy.sh
24+
$ ./deploy.sh
25+
This script will deploy resouces which will enable you to work securely in a private virtual network.
26+
Enter the Resource Group name:
27+
< Enter a resource group name >
28+
Enter the managed identity name:
29+
< Enter a name for managed identity >
30+
Enter a password for connecting to vm:
31+
< Enter password for the windows VM that is used as a development machine to debug your projects >
32+
```
33+
After the deployment is done, the script outputs the required details to connect to the VM for debugging. For example:
34+
```
35+
Use '< password >' password to connect to the '< ipaddress >' windows VM created in the Resource group '< resource group name >' to securely debug your projects with Azure Dev Spaces.
36+
```
37+
38+
**Important:** The resources deployed using these templates should be used only as a starting point to secure your virtual network.
39+
40+
## Connecting to the virtual network for secure development
41+
Use the virtual machine created by the ARM template on the virtual network to start developing on your AKS cluster with Azure Dev Spaces. You can use the IP address and the password you set when deploying the ARM template to connect to the virtual machine. For more details on developing with Azure Dev Spaces, see the [Azure Dev Spaces quickstart.](https://aka.ms/azds-quickstart-netcore)

advanced networking/deploy.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
fatal() { echo "[FATAL] $*" ; exit 1 ; }
3+
4+
if ! which az >/dev/null 2>/dev/null; then
5+
fatal "Install azure cli to continue deploying resources."
6+
fi
7+
if ! which kubectl >/dev/null 2>/dev/null; then
8+
fatal "Install kubectl to continue deploying resources."
9+
fi
10+
11+
echo "This script will deploy resouces which will enable you to work securely in a private virtual network".
12+
echo "Enter the Resource Group name:" &&
13+
read resourceGroupName &&
14+
echo "Enter the location:" &&
15+
read region &&
16+
echo "Enter the managed identity name:" &&
17+
read idName &&
18+
echo "Enter a password for connecting to vm:" &&
19+
read password &&
20+
21+
echo "Running..."
22+
23+
# 1. Create resource group
24+
az group create -n $resourceGroupName -l $region
25+
26+
# 2. Create user assigned MI for running scripts in ARM templates
27+
identity=$(az identity create -g $resourceGroupName -n $idName --query id -o tsv)
28+
29+
# 3. Assign contributor role for the MI on the RG
30+
miPrincipalId=$(az identity show -g $resourceGroupName -n $idName --query principalId -o tsv)
31+
az role assignment create --role 'Contributor' -g $resourceGroupName --assignee $miPrincipalId
32+
33+
# 4. Create Service principal to be used by the AKS cluster
34+
sp_name="aks-sp-private"
35+
aks_sp_secret=$(az ad sp create-for-rbac --name "http://$sp_name" -o tsv --query password)
36+
aks_sp_id=$(az ad sp show --id http://$sp_name -o tsv --query appId)
37+
38+
# 5. Updating the parameters of the ARM template
39+
sed -i "s#{identity}#$identity#g" devspaces-vnet-parameters.json
40+
sed -i "s/{aks_sp_secret}/$aks_sp_secret/g" devspaces-vnet-parameters.json
41+
sed -i "s/{aks_sp_id}/$aks_sp_id/g" devspaces-vnet-parameters.json
42+
sed -i "s/{password}/$password/g" devspaces-vnet-parameters.json
43+
44+
# 6. Deploy the resources
45+
az group deployment create -g $resourceGroupName --template-file devspaces-vnet-template.json --parameters devspaces-vnet-parameters.json
46+
47+
# 7. Get the Public IP of the VM
48+
ip=$(az network public-ip show -g $resourceGroupName -n "bridge-vm_ip" --query ipAddress -o tsv)
49+
50+
# 8. Get the kube-api server IP
51+
az aks get-credentials -n private-aks-cluster -g $resourceGroupName -f ./kubeconfig
52+
chmod +x ./kubeconfig
53+
api_server=$(kubectl get endpoints --kubeconfig=./kubeconfig -o=jsonpath='{.items[?(@.metadata.name == "kubernetes")].subsets[].addresses[].ip}')
54+
55+
# add the api server ip to the firewall
56+
az extension add --name azure-firewall
57+
az network firewall network-rule create --firewall-name private-firewall --resource-group $resourceGroupName --collection-name "aksnetwork" --destination-addresses "$api_server" --destination-ports 22 443 9000 --name "allow network" --protocols "TCP" --source-addresses "*" --action "Allow" --description "aks network rule" --priority 100
58+
59+
# clean up the mi created for deploying the resources
60+
az role assignment delete --role 'Contributor' -g $resourceGroupName --assignee $miPrincipalId
61+
az identity delete -g $resourceGroupName -n $idName
62+
rm -rf ./kubeconfig
63+
64+
echo "Use '$password' password to connect to the '$ip' windows VM created in the Resource group '$resourceGroupName' to securely debug your projects with Azure Dev Spaces."
65+
echo "Please follow the documentation here https://aka.ms/azds-networking to try out different endpoint scenarios."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"identity": {
6+
"value": "{identity}"
7+
},
8+
"endpointType": {
9+
"value": "Private"
10+
},
11+
"vm_password": {
12+
"value": "{password}"
13+
},
14+
"aks_sp_id": {
15+
"value": "{aks_sp_id}"
16+
},
17+
"aks_sp_secret": {
18+
"value": "{aks_sp_secret}"
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)