Home > Back-end >  Key Vault secrets in GitHub Actions workflow
Key Vault secrets in GitHub Actions workflow

Time:10-28

I have a GitHub Action Workflow wherein I need to access Azure Key Vault secrets and use them. There is the Azure Key Vault Action (https://learn.microsoft.com/en-us/azure/developer/github/github-key-vault) that allows you to access the secrets and then use then in the next step, partial code as follows,

    - uses: Azure/get-keyvault-secrets@v1
      with: 
        keyvault: "containervault"
        secrets: 'containerPassword, containerUsername'
      id: myGetSecretAction
    - uses: azure/docker-login@v1
      with:
        login-server: myregistry.azurecr.io
        username: ${{ steps.myGetSecretAction.outputs.containerUsername }}
        password: ${{ steps.myGetSecretAction.outputs.containerPassword }}

Full YML can be seen in the link above.

However, this action seems to be deprecated in favor of Azure CLI Action (https://github.com/Azure/cli). I could use the action to access the key vault as follows,

- name: Azure CLI script
  uses: azure/CLI@v1
  with:
    inlineScript: |
      az keyvault secret show --vault-name MyVaultName --name MySecret --query value

However, I am not sure how to pass the value returned by the above to the next step in the workflow. Any assistance here would help.

Thanks in advance Sushil

CodePudding user response:

The new recommended way of doing it is covered here: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files

Example:

steps:
- name: Azure CLI script
  id: step_one
  uses: azure/CLI@v1
  with:
    inlineScript: |
      echo secret=$(az keyvault secret show --vault-name MyVaultName --name MySecret --query value) >> $GITHUB_ENV
  - name: Use the value
    id: step_two
    run: |
      echo "${{ env.secret }}"

  • Related