Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use MSI for az login #116

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cloud-provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set_azure_config() {
local az_subnet_name=$(cat "$AZURE_CLOUD_CONFIG_PATH" | jq -r .subnetName)
local az_vnet_name=$(cat "$AZURE_CLOUD_CONFIG_PATH" | jq -r .vnetName)
local az_vm_type=$(cat "$AZURE_CLOUD_CONFIG_PATH" | jq -r .vmType)
local az_managed_identity_extension=$(cat "$AZURE_CLOUD_CONFIG_PATH" | jq -r .useManagedIdentityExtension)

local az_vm_resources_group=$(curl -s -H Metadata:true "${AZURE_META_URL}/resourceGroupName?api-version=${AZURE_META_API_VERSION}&format=text")
local az_vm_name=$(curl -s -H Metadata:true "${AZURE_META_URL}/name?api-version=${AZURE_META_API_VERSION}&format=text")
Expand All @@ -32,8 +33,12 @@ set_azure_config() {
az cloud set --name ${azure_cloud}

# login to Azure
az login --service-principal -u ${azure_client_id} -p ${azure_client_secret} --tenant ${azure_tenant_id} 2>&1 > /dev/null

if [ "$az_managed_identity_extension" = "true" ] && [ "${azure_client_secret}" = "" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the curly braces on az_managed_identity_extension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldnt we also make this easier with no param and just say if azure_client_secret is empty to fall back on an az login --idtentity ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would also work for usecase where az_managed_identity_extension is true however want to use different credentials for azure_client_secret

echo "using MSI for az login"
az login --identity 2>&1 > /dev/null
else
az login --service-principal -u ${azure_client_id} -p ${azure_client_secret} --tenant ${azure_tenant_id} 2>&1 > /dev/null
fi
# set subscription to be the current active subscription
az account set --subscription ${az_subscription_id}

Expand Down