Why are GitHub Actions secrets exposed in matrix job names even when masked in logs? #190708
-
🏷️ Discussion TypeQuestion BodyI'm using GitHub Actions with matrix builds to test across multiple Node.js versions. I set up a I've tried:
Nothing prevents the secret from appearing in the job name. Is this a GitHub limitation or am I missing something? Guidelines
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
This is a known GitHub Actions security behavior: secrets should never be used directly in matrix strategy variables because the matrix values are interpolated into job metadata (names, etc.) before secret masking is applied. Secret masking only works on the actual job logs, not on the job's metadata properties. Solution:
strategy:
matrix:
node-version: [16, 18, 20] # ✓ Safe
# environment: [dev, prod] # ✗ Don't put secrets here
steps:
- name: Use secret safely in step
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: |
# Secret is only in environment, masked in logs
echo "Deploying with token"
jobs:
deploy:
environment: ${{ matrix.env }}
steps:
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
This is a security-by-design choice: if you need different secrets per matrix variation, use separate jobs or Environments instead of matrix variables. |
Beta Was this translation helpful? Give feedback.
-
|
Welcome to the GitHub Community, @augustbreay, we're happy you're here! You are more likely to get a useful response if you are posting your question in the applicable category and are explicit about what your project entails--giving a few more details might help someone give you a nudge in the right direction. I've gone ahead and moved it for you. Good luck! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @augustbreay 👋, This is a GitHub Actions limitation secrets are only masked in logs, not in job names. To keep them safe, avoid putting secrets in the matrix; use a placeholder in the job name and reference the actual secret inside your steps instead. |
Beta Was this translation helpful? Give feedback.
This is a known GitHub Actions security behavior: secrets should never be used directly in matrix strategy variables because the matrix values are interpolated into job metadata (names, etc.) before secret masking is applied. Secret masking only works on the actual job logs, not on the job's metadata properties.
Solution:
matrix.includeor strategy definitions