skip to Main Content

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


  1. 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:

    $azContext = (Connect-AzAccount -Identity).context
    
    Login or Signup to reply.
  2. I tried to reproduce the same in my environment and got the result successfully.

    In my bash I login with az login like below:

    enter image description here

    And copy the Https://microsoft.com/devicelogin in browser and enter the code -> continue and close the tab like below:

    enter image description here

    Now, when I create a file vi vault.sh with same script like below.

    az login
    Source_Kv_Name="khankeyvault "
    az keyvault secret list --vault-name $Source_Kv_Name --query "[].id" -o tsv
    

    enter image description here

    When I run bash vault.sh I got authenticate login as same and got the result successfully like below:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search