I have a bash script vault.sh
az login
Source_Kv_Name="myKeyVault2020"
SECRETS+=($(az keyvault secret list --vault-name $Source_Kv_Name --query "[].id" -o tsv))
If I run it as bash vault.sh
it fails to connect to vault (authenticate)
If I run the same commands from terminal, not the script, it works fine.
Why is happening, and how do I authenticate bash script to run the same?
2
Answers
What is the error? Can you share the output?
I can say that for a bash script usually you need to "hard code users password" on the script, or use SPN authentication.
If your script is running from Azure Automation, you can use the Identity Managment on the Azure Automation and give access to the automation account to the component and use that access.
Example:
I tried to reproduce the same in my environment and got the result successfully.
In my bash I login with
az login
like below:And copy the
Https://microsoft.com/devicelogin
in browser and enter the code -> continue and close the tab like below:Now, when I create a file
vi vault.sh
with same script like below.When I run
bash vault.sh
I got authenticate login as same and got the result successfully like below: