Skip to content

Commit f53a140

Browse files
Merge pull request #444 from alan-turing-institute/DSGN-Bristol-AUG2019
Take changes from Bristol DSGN SHM/DSG deployment
2 parents 791abb0 + bb12e8d commit f53a140

45 files changed

Lines changed: 382 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ new_dsg_environment/azure-vms/tests/logistic.csv
55

66
# All secrets folders, no matter how nested
77
secrets/
8-
temp/
8+
temp/
9+
.vscode

new_dsg_environment/azure-runbooks/dsg_build_instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ Each DSG must be assigned it's own unique IP address space, and it is very impor
333333

334334
- Login with domain user `<shm-domain>\atiadmin` and the SHM DC admin password from the `sh-management-dc-admin-password` secret in the Safe Haven Management KeyVault
335335

336-
- From the "Server Management" application, select `Tools -> Group Policy Management` then `Active Directory Domains and Trust`
336+
- From the "Server Management" application, select `Tools -> Active Directory Domains and Trust`
337337

338338
- Right click the management domain name and select `Properties`
339339

@@ -575,7 +575,7 @@ Each DSG must be assigned it's own unique IP address space, and it is very impor
575575

576576
- Install the packages present in the folder
577577

578-
- **NOTE:** Intalling TexLive (`install-tl-windows-xxx`) will take about an hour to install (including downloading lots of files from the internet), so it is recommended to leave this until last and then continue with the remaining sections of this runbook while the TexLive installation completes.
578+
- **NOTE:** Installing TexLive (`install-tl-windows-xxx`) will take about an hour to install (including downloading lots of files from the internet), so it is recommended to leave this until last and then continue with the remaining sections of this runbook while the TexLive installation completes.
579579

580580
- Once installed logout of the server
581581

new_dsg_environment/azure-vms/README-parallel-deploy-using-azure-vms.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## Make a new deployment VM
22
### Deploy a new VM
33
- Go to the `new_dsg_environment/azure-vms` directory
4-
- Run `./deploy_azure_deployment_pool_vm.sh -s "Safe Haven Management Testing" -n <number>` where number is a zero padded number one greater than largest one currently used by an existing deployment VM (eg. 01, 02, etc.)
4+
- Run `./deploy_azure_deployment_pool_vm.sh -s "<sh-management-subscription-name>" -i <shm-id> -n <number>` where `<number>` is a zero padded number one greater than largest one currently used by an existing deployment VM (eg. 01, 02, etc.)
55
- This will deploy a VM that you can use for deployment (ie. it has the necessary tools already installed)
6-
- You will need to take the public keypair output at the end of deployment and add it to the `Secrets > Deploy Keys` tab in the safe haven repo on GitHub.
6+
- You will need to take the public keypair output at the end of deployment and add it to the `Settings > Deploy Keys` tab in the safe haven repo on GitHub. The keys **do not** need write access, so leave this box **unchecked**.
77

88
### VM information
99
- The username is `atiadmin`
@@ -13,13 +13,14 @@
1313
- azure-cli
1414
- powershell
1515
- pip
16+
- eternal terminal
1617
- You will need to clone the safe haven repo via `git clone git@github.com:alan-turing-institute/data-safe-haven.git`. This will automatically authenticate using the VM's `id_rsa` SSH key you just added to the safe haven repo as a deploy key.
1718

1819

1920
## Use a deployment VM to deploy to the Safe Haven
2021
The VM(s) you want to use may be stopped to save money, so you may need to start the VM(s) you want to use from the Azure Portal
21-
- Install [mosh](https://mosh.org/) locally for more stable SSH (e.g. via `brew install mosh` on OSX)
22-
- Connect to the VM using `mosh atiadmin@sh-deployment-0X.westeurope.cloudapp.azure.com` (replacing `0X` with the zero padded number of the deployment VM you want to use and using the password from the `deployment-vm-admin-password` secret in `dsg-management-test` KeyVault in the `RG_DSG_SECRETS` resource group of the `Safe Haven Management Testing` subscription)
22+
- Connect to the VM using `ssh atiadmin@sh-deployment-<shm-id>-<number>.westeurope.cloudapp.azure.com` (replacing `0X` with the zero padded number of the deployment VM you want to use; and using the password from the `deployment-vm-admin-password` secret in `dsg-management-<shm-id>` KeyVault in the `RG_DSG_SECRETS` resource group of the `<sh-management-subscription-name>` subscription)
23+
- If you have not yet cloned the safe haven GitHub repository, run `git clone git@github.com:alan-turing-institute/data-safe-haven.git`
2324
- Navigate to the folder in the safe haven repo with the deployment scripts using `cd data-safe-haven/new_dsg_environment/dsg_deploy_scripts/07_deploy_compute_vms`
2425
- Checkout the master branch using `git checkout master` (or the deployment branch for the DSG environment you are deploying to - you may need to run `git fetch` first if not using `master`)
2526
- Ensure you have the latest changes locally using `git pull`

new_dsg_environment/azure-vms/cloud-init-deployment-vm.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ runcmd:
2828
- mkdir -p /home/atiadmin/.ssh
2929
- ssh-keygen -t rsa -b 4096 -N "" -f /home/atiadmin/.ssh/id_rsa
3030
- chown atiadmin:atiadmin /home/atiadmin/.ssh/id_rsa*
31-
# Install Azure CLI support for Powershell
32-
- pwsh -command "Install-Module -Name Az -Force -AllowClobber"
33-
- pwsh -command "Install-Module -Name Az.Accounts -Force -AllowClobber"
31+
# Install Azure support for Powershell (needs to install for the shared admin user, not root)
32+
- sudo -u atiadmin pwsh -command "Install-Module -Name Az -Force -AllowClobber"
33+
34+
# Install Eternal Terminal
35+
- apt-get install -y software-properties-common
36+
- add-apt-repository ppa:jgmath2000/et
37+
- apt-get update
38+
- apt-get install et
39+
40+
# Install certbot
41+
- apt install certbot
3442

3543
# Clean up
3644
- apt-get -y upgrade

new_dsg_environment/azure-vms/deploy_azure_compute_vm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ LDAP_FILTER_ESCAPED=${LDAP_FILTER/"&"/"\&"}
407407
LDAP_FILTER_REGEX="s/LDAP_FILTER/${LDAP_FILTER_ESCAPED}/g"
408408
AD_DC_NAME_UPPER_REGEX="s/AD_DC_NAME_UPPER/${AD_DC_NAME_UPPER}/g"
409409
AD_DC_NAME_LOWER_REGEX="s/AD_DC_NAME_LOWER/${AD_DC_NAME_LOWER}/g"
410-
PYPI_MIRROR_IP_REGEX="s/PYPI_MIRROR_IP/${PYPI_MIRROR_IP}/"
411-
CRAN_MIRROR_IP_REGEX="s/CRAN_MIRROR_IP/${CRAN_MIRROR_IP}/"
410+
PYPI_MIRROR_IP_REGEX="s|PYPI_MIRROR_IP|${PYPI_MIRROR_IP}|g"
411+
CRAN_MIRROR_IP_REGEX="s|CRAN_MIRROR_IP|${CRAN_MIRROR_IP}|g"
412412

413413
# Substitute regexes
414414
sed -e "${USERNAME_REGEX}" -e "${LDAP_SECRET_REGEX}" -e "${MACHINE_NAME_REGEX}" -e "${LDAP_USER_REGEX}" -e "${DOMAIN_LOWER_REGEX}" -e "${DOMAIN_UPPER_REGEX}" -e "${LDAP_CN_REGEX}" -e "${LDAP_BASE_DN_REGEX}" -e "${LDAP_FILTER_REGEX}" -e "${LDAP_BIND_DN_REGEX}" -e "${AD_DC_NAME_UPPER_REGEX}" -e "${AD_DC_NAME_LOWER_REGEX}" -e "${PYPI_MIRROR_IP_REGEX}" -e "${CRAN_MIRROR_IP_REGEX}" $CLOUD_INIT_YAML > $TMP_CLOUD_CONFIG_YAML

new_dsg_environment/azure-vms/deploy_azure_deployment_pool_vm.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,21 @@ print_usage_and_exit() {
5252
echo "usage: $0 [-h] -s subscription -n machine_number [-r resource_group]"
5353
echo " -h display help"
5454
echo " -s subscription [required] specify subscription to deploy into. (Test using 'Safe Haven Management Testing')"
55+
echo " -i shm_id [required] specify the short ID for the Safe Haven Management segment (e.g. prod, test etc)"
5556
echo " -n machine_number [required] specify number of created VM, which must be unique in this resource group (VM will be called '${MACHINENAMEPREFIX}-<number>')"
5657
echo " -r resource_group specify resource group for deploying the VM image - will be created if it does not already exist (defaults to '${RESOURCEGROUP}')"
5758
exit 1
5859
}
5960

6061
# Read command line arguments, overriding defaults where necessary
61-
while getopts "hn:r:s:" opt; do
62+
while getopts "hi:n:r:s:" opt; do
6263
case $opt in
6364
h)
6465
print_usage_and_exit
6566
;;
67+
i)
68+
SHMID=$OPTARG
69+
;;
6670
n)
6771
MACHINENUMBER=$OPTARG
6872
;;
@@ -87,13 +91,19 @@ if [ "$SUBSCRIPTION" = "" ]; then
8791
fi
8892

8993

90-
# Check that a machine name has been provided
94+
# Check that an SHM ID has been provided
95+
# -------------------------------------------
96+
if [ "$SHMID" = "" ]; then
97+
echo -e "${RED}SHM ID is a required argument!${END}"
98+
print_usage_and_exit
99+
fi
100+
# Check that a machine number has been provided
91101
# -------------------------------------------
92102
if [ "$MACHINENUMBER" = "" ]; then
93103
echo -e "${RED}Machine number is a required argument!${END}"
94104
print_usage_and_exit
95105
fi
96-
MACHINENAME="${MACHINENAMEPREFIX}-${MACHINENUMBER}"
106+
MACHINENAME="${MACHINENAMEPREFIX}-${SHMID}-${MACHINENUMBER}"
97107
DNSNAME="$(echo $MACHINENAME | tr '[:upper:]' '[:lower:]')"
98108

99109

@@ -129,8 +139,10 @@ fi
129139
if [ "$(az network nsg show --resource-group $RESOURCEGROUP --name $NSG_NAME 2> /dev/null)" = "" ]; then
130140
echo -e "${BOLD}Creating NSG for deployment: ${BLUE}$NSG_NAME${END}"
131141
az network nsg create --resource-group $RESOURCEGROUP --name $NSG_NAME
132-
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 1000 --name AllowMosh --description "Allow Mosh" --access "Allow" --source-address-prefixes "*" --source-port-ranges "*" --destination-address-prefixes "VirtualNetwork" --destination-port-ranges "60000-61000" --protocol "UDP"
133-
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 2000 --name AllowTuringIPs --description "Allow inbound Turing connections on port 22 (SSH)" --access "Allow" --source-address-prefixes 193.60.220.253 193.60.220.240 --source-port-ranges "*" --destination-address-prefixes "*" --destination-port-ranges "22" --protocol "TCP"
142+
PERMITTED_IPS="193.60.220.253 193.60.220.240"
143+
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 1000 --name AllowMosh --description "Allow Mosh" --access "Allow" --source-address-prefixes "$PERMITTED_IPS" --source-port-ranges "*" --destination-address-prefixes "*" --destination-port-ranges "60000-61000" --protocol "UDP"
144+
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 1500 --name AllowEternalTerminal --description "Allow Eternal Terminal" --access "Allow" --source-address-prefixes "$PERMITTED_IPS" --source-port-ranges "*" --destination-address-prefixes "*" --destination-port-ranges "2022" --protocol "TCP"
145+
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 2000 --name AllowTuringIPs --description "Allow inbound Turing connections on port 22 (SSH)" --access "Allow" --source-address-prefixes "$PERMITTED_IPS" --source-port-ranges "*" --destination-address-prefixes "*" --destination-port-ranges "22" --protocol "TCP"
134146
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_NAME --direction Inbound --priority 3000 --name IgnoreInboundRulesBelowHere --description "Deny all other inbound" --access "Deny" --source-address-prefixes "*" --source-port-ranges "*" --destination-address-prefixes "*" --destination-port-ranges "*" --protocol "*"
135147
fi
136148

@@ -189,7 +201,7 @@ else
189201
--os-disk-name $OSDISKNAME \
190202
--public-ip-address-dns-name $DNSNAME \
191203
--resource-group $RESOURCEGROUP \
192-
--size Standard_F4s_v2 \
204+
--size Standard_B2ms \
193205
--storage-sku Standard_LRS \
194206
--subnet $SUBNET_NAME \
195207
--vnet-name $VNET_NAME

new_dsg_environment/azure-vms/deploy_azure_external_mirror_servers.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ else
185185

186186
# Temporarily allow outbound internet connections through the NSG from this IP address only
187187
PRIVATEIPADDRESS=${VNET_IPTRIPLET}.4
188-
echo -e "${BOLD}Temporarily allowing outbound internet access from ${BLUE}$PRIVATEIPADDRESS${END}${BOLD} in NSG ${BLUE}$NSG_EXTERNAL${END}${BOLD} (for use during deployment *only*)${END}"
188+
echo -e "${BOLD}Temporarily allowing outbound internet access on ports 80, 443 and 3128 from ${BLUE}$PRIVATEIPADDRESS${END}${BOLD} in NSG ${BLUE}$NSG_EXTERNAL${END}${BOLD} (for installing software during deployment *only*)${END}"
189189
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --direction Outbound --name configurationOutboundTemporary --description "Allow ports 80 (http), 443 (pip) and 3128 (pip) for installing software" --access "Allow" --source-address-prefixes $PRIVATEIPADDRESS --destination-port-ranges 80 443 3128 --protocol TCP --destination-address-prefixes Internet --priority 100 --output none
190190
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --direction Outbound --name vnetOutboundTemporary --description "Block connections to the VNet" --access "Deny" --source-address-prefixes $PRIVATEIPADDRESS --destination-port-ranges "*" --protocol "*" --destination-address-prefixes VirtualNetwork --priority 150 --output none
191191

@@ -215,14 +215,10 @@ else
215215

216216
# Poll VM to see whether it has finished running
217217
echo -e "${BOLD}Waiting for VM setup to finish (this may take several minutes)...${END}"
218-
while true; do
219-
POLL=$(az vm get-instance-view --resource-group $RESOURCEGROUP --name $MACHINENAME --query "instanceView.statuses[?code == 'PowerState/running'].displayStatus")
220-
if [ "$(echo $POLL | grep 'VM running')" == "" ]; then break; fi
221-
sleep 10
222-
done
218+
az vm wait --name $MACHINENAME --resource-group $RESOURCEGROUP --custom "instanceView.statuses[?code == 'PowerState/stopped'].displayStatus" --output none
223219

224220
# Delete the configuration NSG rule and restart the VM
225-
echo -e "${BOLD}Restarting VM: ${BLUE}${MACHINENAME}${END}" --output none
221+
echo -e "${BOLD}Restarting VM: ${BLUE}${MACHINENAME}${END}"
226222
az network nsg rule delete --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --name configurationOutboundTemporary --output none
227223
az network nsg rule delete --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --name vnetOutboundTemporary --output none
228224
az vm start --resource-group $RESOURCEGROUP --name $MACHINENAME --output none
@@ -271,7 +267,7 @@ if [ "$TIER" == "2" ]; then # we do not support Tier-3 CRAN mirrors at present
271267

272268
# Temporarily allow outbound internet connections through the NSG from this IP address only
273269
PRIVATEIPADDRESS=${VNET_IPTRIPLET}.5
274-
echo -e "${BOLD}Temporarily allowing outbound internet access from ${BLUE}$PRIVATEIPADDRESS${END}${BOLD} in NSG ${BLUE}$NSG_EXTERNAL${END}${BOLD} (for use during deployment *only*)${END}"
270+
echo -e "${BOLD}Temporarily allowing outbound internet access on ports 80, 443 and 3128 from ${BLUE}$PRIVATEIPADDRESS${END}${BOLD} in NSG ${BLUE}$NSG_EXTERNAL${END}${BOLD} (for installing software during deployment *only*)${END}"
275271
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --direction Outbound --name configurationOutboundTemporary --description "Allow ports 80 (http), 443 (pip) and 3128 (pip) for installing software" --access "Allow" --source-address-prefixes $PRIVATEIPADDRESS --destination-port-ranges 80 443 3128 --protocol TCP --destination-address-prefixes Internet --priority 100 --output none
276272
az network nsg rule create --resource-group $RESOURCEGROUP --nsg-name $NSG_EXTERNAL --direction Outbound --name vnetOutboundTemporary --description "Block connections to the VNet" --access "Deny" --source-address-prefixes $PRIVATEIPADDRESS --destination-port-ranges "*" --protocol "*" --destination-address-prefixes VirtualNetwork --priority 200 --output none
277273

@@ -300,11 +296,7 @@ if [ "$TIER" == "2" ]; then # we do not support Tier-3 CRAN mirrors at present
300296

301297
# Poll VM to see whether it has finished running
302298
echo -e "${BOLD}Waiting for VM setup to finish (this may take several minutes)...${END}"
303-
while true; do
304-
POLL=$(az vm get-instance-view --resource-group $RESOURCEGROUP --name $MACHINENAME --query "instanceView.statuses[?code == 'PowerState/running'].displayStatus")
305-
if [ "$(echo $POLL | grep 'VM running')" == "" ]; then break; fi
306-
sleep 10
307-
done
299+
az vm wait --name $MACHINENAME --resource-group $RESOURCEGROUP --custom "instanceView.statuses[?code == 'PowerState/stopped'].displayStatus" --output none
308300

309301
# Delete the configuration NSG rule and restart the VM
310302
echo -e "${BOLD}Restarting VM: ${BLUE}${MACHINENAME}${END}"

0 commit comments

Comments
 (0)