Jonáš Kowalczyk
Jonáš Kowalczyk

Reputation: 96

helm registry login --password-stdin in Azure DevOps pipeline

I am trying to login to my private ACR using azure DevOps pipeline.

I tried it this way:

- task: AzureCLI@2
  inputs:
    azureSubscription: $(azureSubscriptionForACR)
    scriptType: 'ps'
    scriptLocation: 'inlineScript'
    inlineScript: |
      $password = az acr credential show -n $(azureAcrName) --query passwords[0].value
      helm registry login $(azureContainerRegistry) --username $(azureAcrUserName) --password $password

which works, but there is a warning when I run the pipeline:

"WARNING: Using --password via the CLI is insecure. Use --password-stdin."

I would like to avoid the warning, so I tried many variant of this, but no success:

- task: AzureCLI@2
  inputs:
    azureSubscription: $(azureSubscriptionForACR)
    scriptType: 'ps'
    scriptLocation: 'inlineScript'
    inlineScript: |
      $password = az acr credential show -n $(azureAcrName) --query passwords[0].value
      echo $password | helm registry login $(azureContainerRegistry) --username $(azureAcrName) --password-stdin

It always end up with:

Error: Get "https://azureacr.azurecr.io/v2/": unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.

I am using new helm 3.8.0

Is there a way to do it with --password-stdin?

Upvotes: 0

Views: 3691

Answers (1)

Ansuman Bal
Ansuman Bal

Reputation: 11451

You can store the $password value as an Environment Variable in Azure Devops , the same way you are doing for the ACR username and other values and then use echo command .

Example:

First get the password for the ACR using the below command and then store it in Environment Variable registryPassword .

az acr credential show -n $(azureAcrName) --query passwords[0].value

Then use the below to login:

- task: AzureCLI@2
  inputs:
    azureSubscription: $(azureSubscriptionForACR)
    scriptType: 'ps'
    scriptLocation: 'inlineScript'
    inlineScript: |
    echo $(registryPassword) | helm registry login $(azureContainerRegistry) --username $(azureAcrName) --password-stdin

For more information you can refer this Blog by Abhith Rajan or this SO thread.

Upvotes: 3

Related Questions