Get key for login using service principal dynamically python script

345 views Asked by At

I'm running a python script, where o want to use service principal to authenticate. I don't want to store service principal secret in my script.

Please help me to store the secret key somewhere and access it dynamically in the script using az cli commands.

I need some command which can fetch the secret key runtime and I can pass it to

"az login --servicePrincipal" command.

1

There are 1 answers

0
Rukmini On

I tried to reproduce the same in my environment and got the results successfully like below:

I registered an Azure AD application and generated client_secret:

enter image description here

To store the above secret key of the, I created an Azure Key Vault like below:

Go to Azure Key Vault -> Your Vault -> Secrets -> Generate/Import -> Create

enter image description here

To fetch the Service Principal secret key via Azure CLI, please try the below commands:

az login --only-show-errors
 
$client_secret = az keyvault secret show --name testclientsecret --vault-name testrukkey --query value
$client_secret

enter image description here