Sub topic 12
Security, Size, and Storage Considerations
This chapter assumes you can write a workflow with jobs and steps, and that you have already used actions/upload-artifact and actions/download-artifact. It covers how artifacts can leak data, what limits apply, and how to keep storage use down.
Artifacts are readable by anyone with repository access
Anyone who can read a repository can download its artifacts. In a public repository, that means anyone on the internet. Secrets that GitHub masks in logs are not masked inside files, so a secret written to a file and uploaded is exposed in plain text.
Common ways data leaks into an artifact:
- Uploading a whole workspace with
path: .. This picks up.envfiles, private keys, and build caches. - Uploading the
.gitdirectory. Withactions/checkout, the token is stored in.git/configby default. - Uploading debug logs or test reports that print environment variables or request headers.
- Uploading config files that were generated from secrets during the build.
Upload only what you need
Prefer narrow paths over broad ones. Use exclusions for files you cannot avoid matching.
- uses: actions/upload-artifact@v4
with:
name: dist
path: |
dist/
!dist/**/*.map
!dist/**/.env*
if-no-files-found: errorVersion 4 of the upload action excludes hidden files by default. You can turn that on with include-hidden-files: true. Leave it off unless you need those files, because hidden files are where .env and .git live.
You can also stop actions/checkout from persisting the token in .git/config:
- uses: actions/checkout@v4
with:
persist-credentials: falseArtifacts from pull requests
Treat artifacts from untrusted code as untrusted input. A pull request from a fork can produce an artifact containing anything. A common risky pattern is a workflow_run workflow, which runs with a privileged token, downloading an artifact created by a pull request workflow and then using its contents in a script or as a path.
Safer practice:
- Do not execute files from a downloaded artifact in a privileged workflow.
- Validate any value you read from an artifact, such as a pull request number, before using it.
- Keep the
permissionsof the downloading workflow as small as possible.
Limits and storage
Artifacts count against your account's storage quota, and the quota depends on your plan. Check the current figures in GitHub's billing documentation, because they change. Several habits keep usage in check:
| Setting | What it does | Practical advice |
|---|---|---|
| `retention-days` | Deletes the artifact after N days | Use a short value for build outputs that only later jobs need |
| `compression-level` | Sets zip compression from 0 to 9 | Use `0` for files that are already compressed, such as `.zip` or `.jpg` |
| Narrow `path` | Reduces upload size | Upload `dist/`, not the whole workspace |
| `if-no-files-found` | Fails or warns on empty uploads | Use `error` so mistakes surface |
Retention can be no longer than the maximum your repository or organization allows. A value above that limit is capped.
- uses: actions/upload-artifact@v4
with:
name: bundle
path: bundle.zip
retention-days: 1
compression-level: 0Each upload and download also takes time. Large artifacts slow every job that needs them. If you only need a dependency folder to speed up later runs, use the cache instead of an artifact.
Removing artifacts
You can delete an artifact from the run summary page in the web UI. You can also delete one with the GitHub CLI through the API:
gh api repos/OWNER/REPO/actions/runs/RUN_ID/artifacts --jq '.artifacts[] | {id, name}'
gh api -X DELETE repos/OWNER/REPO/actions/artifacts/ARTIFACT_IDDeleting an artifact that already leaked a secret does not make the secret safe. Anyone may already have downloaded it. Rotate the secret.
Summary of habits
- Upload specific paths, never the whole workspace.
- Exclude hidden and sensitive files, and set
persist-credentials: falseon checkout. - Treat artifacts from pull requests as untrusted.
- Set
retention-daysandcompression-leveldeliberately. - Rotate any secret that reached an artifact.
Exercise
A workflow uploads path: . after checkout and a build. The repository is public. Name two problems this causes and one change that fixes both.
Show answer
The artifact can expose sensitive files such as .env files and .git/config, which may contain the checkout token, and it is large because it includes the whole workspace. Changing path to only the needed output directory, such as dist/, fixes both. Adding persist-credentials: false to checkout further protects the token.
Exercise
You upload a .zip file that is already compressed and only the next job needs it. Which two inputs reduce storage and time, and what values would you choose?
Show answer
Set compression-level: 0 to skip recompressing the zip, and set retention-days: 1 so the artifact is deleted quickly.