Sub topic 11
Security and noise considerations
This chapter assumes you can re-run a job and enable step debug logging, both covered earlier. It covers what can go wrong when you turn debug logging on, and how to keep the logs useful and safe.
Why debug logs need more care
Debug logs contain more than normal logs. Step debug logging adds detail about how the runner evaluated each step. Runner diagnostic logging adds internal runner files to the downloadable log archive. Both can show values that a normal run never prints.
Two problems follow from that:
- Exposure: a sensitive value can end up in a log that more people can read than you intended.
- Noise: a long log makes the one useful line harder to find.
How secret masking works, and where it stops
GitHub Actions masks the exact value of each secret. If a registered secret appears in the log, the runner replaces it with ***.
Masking compares text against known values. It does not understand what a value means. A value is not masked in these cases:
- You transform it (base64, URL-encoding, a substring, or a JSON-escaped copy).
- A tool prints it in a different form.
- It is a structured secret, such as a multi-line JSON blob, that the tool prints one line at a time.
- It was never registered as a secret. Values from a file, an API response, or a cloud CLI call are examples.
Debug output makes these cases more likely, because more variables, inputs, and command traces are printed.
Masking derived values yourself
When a step creates a sensitive value at run time, register it with the ::add-mask:: workflow command before anything prints it.
name: mask-derived
on: [workflow_dispatch]
jobs:
demo:
runs-on: ubuntu-latest
steps:
- name: Mask a derived value
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
run: |
encoded=$(printf '%s' "$API_TOKEN" | base64)
echo "::add-mask::$encoded"
echo "::debug::encoded length is ${#encoded}"The debug message prints only the length of the encoded value, never the value itself. Follow that habit in your own ::debug:: messages. Log sizes, counts, and names, not contents.
Habits that leak data in debug mode
Some commands become risky when you add them for debugging:
env | sortprints every environment variable, including values the workflow copied from secrets under a different name or in a different form. The diagnostics step from the earlier example filters withgrep '^GITHUB_'for this reason.set -xin a shell step prints each command after variable expansion. Masking still applies, but derived values slip through.- Verbose flags such as
curl -vor--debugon a deployment tool can print request headers, including authorization headers.
Who can see and change what
| Action | Typical effect | Care to take |
|---|---|---|
| Reading logs | Visible to anyone with read access to the repository (everyone, if it is public) | Assume debug output is public in public repositories |
| Re-running with debug logging | Affects only that new attempt | Preferred for one-off investigation |
| Setting `ACTIONS_STEP_DEBUG` or `ACTIONS_RUNNER_DEBUG` | Affects every future run until you delete it | Remove it as soon as you finish |
| Downloading the log archive | Copies logs, including runner diagnostics, to your machine | Delete the copy when you finish. Don't attach it to public tickets without reading it first |
If both a secret and a variable named ACTIONS_STEP_DEBUG exist, the secret takes precedence. Check both places before you assume debug logging is off.
Choosing the narrowest option
Prefer the single re-run. It limits exposure to one attempt and leaves normal runs quiet. Use the persistent settings only for problems that a re-run cannot reproduce, such as failures that appear only on a certain trigger or branch.
Remove persistent settings with the same tool you used to set them:
gh secret delete ACTIONS_STEP_DEBUG
gh variable delete ACTIONS_RUNNER_DEBUGKeeping the noise manageable
- Search the log for the failing step first. Open only that step, and expand debug lines only when the normal output doesn't explain the failure.
- Use
gh run view RUN_ID --log-failedto print only the failed steps instead of scrolling the whole run. - Gate your own extra output behind
runner.debug == '1', so it appears only when debug logging is on. - Turn debug logging off after you find the cause. Leaving it on makes every later run slower to read and expands the exposure window.
If a secret does leak
Masking failures are rare but happen. If you find a sensitive value in a log:
- Rotate the credential first. Deleting the log does not undo exposure.
- Delete the affected run's logs, or the run itself, so the value is no longer displayed.
- Fix the step that printed it, and register the value with
::add-mask::if needed.
Exercise
A teammate sets the repository secret ACTIONSSTEPDEBUG to true to chase a one-time failure, then forgets about it. Name two problems this causes, and the command that fixes the root cause.
Show answer
Every future run now produces verbose logs. That adds noise and raises the chance that derived or unmasked values appear in logs readable by everyone with repository access. Run gh secret delete ACTIONS_STEP_DEBUG. A single re-run with debug logging enabled would have been the narrower choice.