diff --git a/hack/devtools/local_dev_env.sh b/hack/devtools/local_dev_env.sh index 2d3335c43..ebfa84520 100755 --- a/hack/devtools/local_dev_env.sh +++ b/hack/devtools/local_dev_env.sh @@ -39,7 +39,58 @@ ask_to_create_default_env_config() { fi } +# We use a service principal and certificate as the mock MSI object +create_mock_msi() { + appName="mock-msi-$(openssl rand -base64 9 | tr -dc 'a-zA-Z0-9' | head -c 6)" + az ad sp create-for-rbac --name $appName --create-cert --output json +} + +get_mock_msi_clientID() { + echo "$1" | jq -r .appId +} + +get_mock_msi_tenantID() { + echo "$1" | jq -r .tenant +} + +get_mock_msi_cert() { + certFilePath=$(echo "$1" | jq -r '.fileWithCertAndPrivateKey') + base64EncodedCert=$(base64 -w 0 $certFilePath) + rm $certFilePath + echo $base64EncodedCert +} + create_env_file() { + local answer + read -p "Do you want to create an env file for Managed/Workload identity development? " answer + if [[ "$answer" == "y" || "$answer" == "Y" ]]; then + create_miwi_env_file + else + create_regular_env_file + fi +} + +create_miwi_env_file() { + echo "INFO: Creating default env config file for managed/workload identity development..." + + mockMSI=$(create_mock_msi) + mockClientID=$(get_mock_msi_clientID "$mockMSI") + mockTenantID=$(get_mock_msi_tenantID "$mockMSI") + mockCert=$(get_mock_msi_cert "$mockMSI") + + cat >env <env <