|
| 1 | +# |
| 2 | +# This action allows you to get a masked secret from Azure Key Vault using the Azure CLI. |
| 3 | +# It implies that the action az-login, is used before this action in the same job as where the secrets will be obtained. |
| 4 | +# This action is designed to be reusable and can be called from other workflows. |
| 5 | +# |
| 6 | +# HOW TO USE: |
| 7 | +# |
| 8 | +# To call this reusable action, copy the code between === lines to workflow file, |
| 9 | +# uncomment and adjust "uses" as needed (use the latest tag available). |
| 10 | +# ====================================================================== |
| 11 | +# on: |
| 12 | +# pull_request: |
| 13 | +# types: [opened, reopened, labeled, unlabeled] |
| 14 | +# |
| 15 | +# permissions: |
| 16 | +# id-token: write |
| 17 | +# contents: read |
| 18 | +# |
| 19 | +# (...) |
| 20 | +# steps: |
| 21 | +# (...) |
| 22 | +# # First, login to Azure using the az-devops-login action |
| 23 | +# - name: Azure Login |
| 24 | +# uses: OutSystems/rd.github-reusable-workflows/.github/actions/az-devops-login@vVersionHash |
| 25 | +# with: |
| 26 | +# subscription-id: ${{ AZURE_subscription-id }} |
| 27 | +# tenant-id: ${{ AZURE_TENANT_ID }} |
| 28 | +# client-id: ${{ AZURE_CLIENT_ID }} |
| 29 | +# |
| 30 | +# # Then, multiple calls to the az-keyvault-get action can be made to retrieve different secrets |
| 31 | +# # from the Azure Key Vault. The secrets will be masked in the logs. |
| 32 | +# |
| 33 | +# - name: Get KeyVault Secret 1 |
| 34 | +# id: GetAzKeyVaultSecret_1 |
| 35 | +# uses: OutSystems/rd.github-reusable-workflows/.github/actions/az-keyvault-get@vVersionHash |
| 36 | +# with: |
| 37 | +# keyvault-name: ${{ AZURE_KEYVAULT_NAME }} |
| 38 | +# key-name: ${{ AZURE_KEYVAULT_SECRET_NAME_1 }} |
| 39 | +# |
| 40 | +# - name: Get KeyVault Secret 2 |
| 41 | +# id: GetAzKeyVaultSecret_2 |
| 42 | +# uses: OutSystems/rd.github-reusable-workflows/.github/actions/az-keyvault-get@vVersionHash |
| 43 | +# with: |
| 44 | +# keyvault-name: ${{ AZURE_KEYVAULT_NAME }} |
| 45 | +# key-name: ${{ AZURE_KEYVAULT_SECRET_NAME_2 }} |
| 46 | +# |
| 47 | +# - name: Use KeyVault Secrets |
| 48 | +# run: | |
| 49 | +# echo "The secret 1 value is: ${{ steps.GetAzKeyVaultSecret_1.outputs.az-keyvault-value }}" |
| 50 | +# echo "The secret 2 value is: ${{ steps.GetAzKeyVaultSecret_2.outputs.az-keyvault-value }}" |
| 51 | +# |
| 52 | +# ====================================================================== |
| 53 | +# |
| 54 | +name: Azure KeyVault Get Value |
| 55 | +description: 'Get a secret from Azure Key Vault.' |
| 56 | +inputs: |
| 57 | + keyvault-name: |
| 58 | + description: 'Name of the Azure Key Vault.' |
| 59 | + required: false |
| 60 | + default: 'kv-ui-components' |
| 61 | + key-name: |
| 62 | + description: 'Name of the secret to retrieve.' |
| 63 | + required: true |
| 64 | + default: '' |
| 65 | +outputs: |
| 66 | + az-keyvault-value: |
| 67 | + description: 'The Azure key value.' |
| 68 | + value: ${{ steps.GetAzKeyVaultSecret.outputs.az-keyvault-secret }} |
| 69 | + |
| 70 | +runs: |
| 71 | + using: composite |
| 72 | + steps: |
| 73 | + - name: Azure KeyVault get Value |
| 74 | + uses: azure/cli@089eac9d8cc39f5d003e94f8b65efc51076c9cbd # v2.1.0 |
| 75 | + id: GetAzKeyVaultSecret |
| 76 | + with: |
| 77 | + inlineScript: | |
| 78 | + secretValue=$(az keyvault secret show --name "${{ inputs.key-name }}" --vault-name "${{ inputs.keyvault-name }}" --query "value" --output tsv) |
| 79 | + echo "::add-mask::$secretValue" |
| 80 | + echo "az-keyvault-secret=$secretValue" >> $GITHUB_OUTPUT |
0 commit comments