How to Encrypt Artifacts Before Upload in GitHub Actions
Artifacts are downloadable by anyone with repo access, so anything sensitive must be encrypted before it leaves the step.
Encrypt the file with symmetric GPG using a passphrase from secrets, upload the ciphertext, and decrypt only where needed.
Steps
- Produce the file you need to protect.
- Encrypt it with gpg symmetric using a passphrase stored in secrets.
- Upload only the encrypted .gpg file as the artifact.
- Decrypt it later with the same passphrase where it is consumed.
Workflow
.github/workflows/encrypt-artifact.yml
name: Encrypt Artifact
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: make secret-bundle
- run: |
gpg --batch --yes --symmetric --cipher-algo AES256 \
--passphrase "${{ secrets.ARTIFACT_KEY }}" bundle.tar
- uses: actions/upload-artifact@v4
with:
name: bundle
path: bundle.tar.gpgNotes
- Never upload the plaintext alongside the ciphertext, or the encryption buys you nothing.
- Latchkey managed runners run these encrypt-and-upload jobs cheaper and self-heal mid-run.
Frequently asked questions
How do I encrypt Artifacts Before Upload in GitHub Actions?
Encrypt the file with symmetric GPG using a passphrase from secrets, upload the ciphertext, and decrypt only where needed.
Related guides
How to Enable Branch Coverage vs Line Coverage in CITurn on branch coverage in CI so both sides of every conditional are measured, a stricter signal than line co…
How to Implement Prow-Style Commands Like /lgtm and /approveImplement Prow-style commands such as /lgtm and /approve in GitHub Actions, mapping each to a label and a req…
How to Comment on a Pull Request From a Workflow in GitHub ActionsPost a comment on a pull request from a GitHub Actions workflow using actions/github-script and the GITHUB_TO…