-
Notifications
You must be signed in to change notification settings - Fork 0
/
aadlogintest.sh
116 lines (97 loc) · 3.92 KB
/
aadlogintest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
#######################################################################################################################
# Title: AADLoginExtension Install on Linux VMs
# Author: Marin Nedea
# Usage: Change the variables to your own.
# Make sure the script has executable permissions:
# chmod +x aadlogintest.sh
# execute the script by typing: ./aadlogintest.sh
# Requires: AzCli 2.0 to run: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
#
# Supported Azure regions and Linux distributions:
#
# The following Linux distributions are currently supported during the preview of this feature:
# -CentOS 6.9, and CentOS 7.4
# -Debian 9
# -RHEL 6, RHEL 7
# -Ubuntu 14.04 LTS, Ubuntu Server 16.04, Ubuntu Server 17.10, and Ubuntu Server 18.04
#
# The following Azure regions are currently supported during the preview of this feature:
# - All global Azure regions
#######################################################################################################################
# Login into Azure
# az login
#
# If multiple subscription, set the one where VM and KeyVault are.
# az account set -s "<YourSubscriptionID>"
# Decide on a region for the resources to be created
region="<Your_Region_Here>"
# Set a resource group name
rgName="<Your_RG_Here>"
# Create the Resource Group - optional
# az group create --name $rgName --location $region
# Use a specific admin username
adminusername="<Your_User_Here>"
# Get the AAD account
username=$(az account show --query user.name --output tsv)
# Simulate a multidimensional array for the VMs we need to create,
# each subarray containing the (hardcoded) VM name and Linux Image URN
declare -a vms
#Ubuntu (latest image for each version)
vms[0]='AADU1404;Canonical:UbuntuServer:14.04.5-LTS:14.04.201809130'
vms[1]='AADU1604;UbuntuLTS'
vms[2]='AADU11710;Canonical:UbuntuServer:17.10:17.10.201807060'
vms[3]='AADU1804;Canonical:UbuntuServer:18.04-LTS:18.04.201809110'
#CentOS (latest image for each version)
vms[4]='AADCentOS69;OpenLogic:CentOS:6.9:6.9.20180530'
vms[5]='AADCentOS74;OpenLogic:CentOS:7.4:7.4.20180704'
# RHEL (latest image for each version)
vms[6]='AADRHEL67;RedHat:RHEL:6.7:6.7.2017090815'
vms[7]='AADRHEL68;RedHat:RHEL:6.8:6.8.2017090906'
vms[8]='AADRHEL69;RedHat:RHEL:6.9:6.9.2018010506'
vms[9]='AADRHEL610;RedHat:RHEL:6.10:6.10.2018071006'
vms[10]='AADRHEL72;RedHat:RHEL:7.2:7.2.2017090716'
vms[11]='AADRHEL73;RedHat:RHEL:7.3:latest'
vms[12]='AADRHEL74;RedHat:RHEL:7.4:7.4.2018010506'
vms[13]='AADRHEL75;RedHat:RHEL:7-RAW:7.5.2018081518'
vms[14]='AADRHEL76Beta;RedHat:RHEL:7.6-BETA:7.6.2018091307'
# Debian (latest image for each version)
vms[15]='AADDebian9;credativ:Debian:9:9.0.201808270'
# Let's get the variables from the fake multidimensional array
for i in "${vms[@]}"
do
arr=(${i//;/ })
vmName=${arr[0]} #VM Name
vmImage=${arr[1]} #VM Imagev URN
# Create the VMs
# NOTE: I'm limited to 100vCPUs/region, so I decided to have the VMs
# size set to Standard_DS2_v2 (2vCPUs/7GB Ram), meaning I will have a total
# quota usage of 32 vCPUs for the above test VMs
az vm create \
--resource-group $rgName \
--name $vmName \
--image $vmImage \
--size Standard_DS2_v2 \
--admin-username $adminusername \
--generate-ssh-keys
#Install the Azure AD login VM extension on the newly created VM
az vm extension set \
--publisher Microsoft.Azure.ActiveDirectory.LinuxSSH \
--name AADLoginForLinux \
--resource-group $rgName \
--vm-name $vmName
# Configure role assignments for the newly created VM
vm=$(az vm show --resource-group $rgName --name $vmName --query id -o tsv)
az role assignment create \
--role "Virtual Machine Administrator Login" \
--assignee $username \
--scope $vm
# Retrieve the public IPs and add them to an external file,
# so we can later use them and test the aadlogin:
az vm show \
--resource-group $rgName \
--name $vmName \
-d --query publicIps \
-o tsv >> /tmp/PublicIpList.txt
done
exit 0