Do you know how to mask secrets from GitHub Actions logs?
Updated by Brady Stroud [SSW] 1 year ago. See history
Example:
Consider the scenario where we need to retrieve a secret from Azure Key Vault (there is no pre-built action to do this from Microsoft) and use it in our GitHub Actions workflow. In the following bad example, the secret is exposed in the logs:
- name: keyVault - Secretsshell: pwshid: KeyVaultSecretsrun: |$GoogleRecaptchaSiteKey = (az keyvault secret show --name Google-Recaptcha-Site-KEY --vault-name ${{ env.KEY_VAULT}} --query value -o tsv)echo "GoogleRecaptchaSiteKey=$GoogleRecaptchaSiteKey" >> $env:GITHUB_OUTPUT

❌ Figure: Bad example - The secret is exposed in the GitHub logs
- name: keyVault - Secretsshell: pwshid: KeyVaultSecretsrun: |$GoogleRecaptchaSiteKey = (az keyvault secret show --name Google-Recaptcha-Site-KEY --vault-name ${{ env.KEY_VAULT}} --query value -o tsv)echo "::add-mask::$GoogleRecaptchaSiteKey"echo "GoogleRecaptchaSiteKey=$GoogleRecaptchaSiteKey" >> $env:GITHUB_OUTPUT

✅ Figure: Good example - The secret is masked in the GitHub logs
For further details on masking secrets in logs, refer to the GitHub documentation.
This method ensures that while you can still use the secret within your workflow, it remains masked in the logs, mitigating the risk of accidental secret exposure.
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.