Pin GitHub Actions to specific commit SHAs for improved security
Project description
📌 gha-pinner
Table of Contents
🤔 Why should you pin your GitHub Actions?
Ever felt a bit of a thrill-seeker using actions/checkout@v3 or even actions/checkout@main in your workflows? While convenient, using floating references like tags, branches, or the latest tag means you're living on the edge.
Pinning your GitHub Actions to a specific commit SHA is your seatbelt for this ride. Here's why it's a non-negotiable security best practice:
- 🔐 Rock-Solid Immutability: A commit SHA is a unique, unchangeable fingerprint for a specific version of the code. No surprises. You can be absolutely certain about the code executing in your workflow.
- 🛡️ Dodge Malicious Updates: Tags (like
v3), branches (likemain), and even thelatestkeyword are mutable pointers. The repository owner can move them to a different commit, potentially slipping malicious code into your workflow without you ever knowing. Pinning to a SHA is like saying, "I'll have this exact version, and nothing else, thank you." - ✅ Crystal-Clear Verifiability: A pinned SHA lets you put on your detective hat. You can browse the repository at that exact commit, inspect the code, and confirm it's safe and sound.
🚀 What does gha-pinner do?
gha-pinner is your friendly neighborhood GitHub Actions detective. It's a simple command-line tool that does the hard work of pinning your actions for you.
Given a GitHub Action in the format owner/repo@ref (where ref can be a branch, tag, or even latest), gha-pinner will:
- 🔎 Track Down the
ref: It sleuths out the providedrefand resolves it to a specific, full-length commit SHA. - 📍 Serve the Pinned Version: It then hands you back the action, neatly pinned to that commit SHA.
For example, if you provide actions/checkout@v3, gha-pinner will resolve v3 to the latest commit SHA in the v3 tag and provide you with actions/checkout@<commit_sha>.
It can also update all actions in a workflow file in place.
📦 Installation
You can install gha-pinner using pip:
pip install gha-pinner
🛠️ Usage
Ready to lock down your workflows? Here's how you can use gha-pinner.
Pin a single action:
To get the commit SHA for a specific action, you can use the -a or --action flag:
$ gha-pinner --action actions/checkout@v3
Original: actions/checkout@v3
Pinned: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
You can then use the pinned version in your GitHub Actions workflow file:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
This ensures that you are always using the exact same version of the action, protecting you from any potential malicious updates.
Pin an entire workflow file:
To pin all actions in a workflow file, you can use the -f or --file flag:
$ gha-pinner --file .github/workflows/ci.yml
✅ Successfully pinned actions in '.github/workflows/ci.yml'
This will update the file in place, pinning all actions to their latest commit SHA and adding a comment with the original version, so you don't forget where you came from. For example:
- uses: actions/checkout@v3
will be updated to:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v3
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gha_pinner-0.1.3.tar.gz.
File metadata
- Download URL: gha_pinner-0.1.3.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.23 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3f9fc1125092bbd85ea87c562ed8a60085114ee6d72aa75d9666d74211b431b
|
|
| MD5 |
12dfec83f94b6eea410c87c7a6e3c265
|
|
| BLAKE2b-256 |
1e2906b93b8f2d78d978ff664b126fb18cdd8c9bd040b30a6fb729c167c8eb9a
|
File details
Details for the file gha_pinner-0.1.3-py3-none-any.whl.
File metadata
- Download URL: gha_pinner-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.23 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb1226770e3a6dd9d00f055ecf5a7d9f990bfc9be7849c2c7a013c7d55bb37b7
|
|
| MD5 |
b6847c08cd2d3db36fae4bd44821e9f5
|
|
| BLAKE2b-256 |
c792ef872cec7607141d1a004542b518909b9bf5590a8ac33f69c107397459b2
|