GitHub Actions 工作流程中的 Key Vault 机密

Sus*_*hil 2 github azure-keyvault github-actions

我有一个 GitHub Action 工作流程,其中我需要访问 Azure Key Vault 机密并使用它们。Azure Key Vault Action ( https://learn.microsoft.com/en-us/azure/developer/github/github-key-vault ) 允许您访问机密,然后在下一步中使用,部分代码如下,

    - 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 }}
Run Code Online (Sandbox Code Playgroud)

完整的 YML 可以在上面的链接中看到。

但是,此操作似乎已被弃用,取而代之的是 Azure CLI 操作 ( https://github.com/Azure/cli )。我可以使用该操作来访问密钥保管库,如下所示,

- name: Azure CLI script
  uses: azure/CLI@v1
  with:
    inlineScript: |
      az keyvault secret show --vault-name MyVaultName --name MySecret --query value
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何将上述返回的值传递到工作流程中的下一步。这里的任何帮助都会有所帮助。

预先感谢苏希尔

Ber*_*nho 7

这里介绍了新的推荐方法:https ://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files

例子:

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 }}"

Run Code Online (Sandbox Code Playgroud)

  • 不要忘记屏蔽此处列出的输出 https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-masking-a-string - 完整示例这篇博文 https://www.aaron-powell.com/posts/2022-07-14-working-with-add-mask-and-github-actions/ (2认同)