Skip to content

Commit

Permalink
Lint our GitHub Actions workflows with zizmor
Browse files Browse the repository at this point in the history
zizmor is a new tool to lint GitHub Actions workflows. For the most part
our workflows are pretty low risk since we don't give it a bunch of
credentials, but we can avoid issues in the future by locking them down
now.

The only issue that needed fixing was setting persist-credentials: false
for actions/checkout, which we do everywhere except in the workflows
that need to push.

While zizmor is written in Rust, it is also shipped as a prebuilt binary
via PyPI, so we can set it as a poetry dependency and run it as part of
our normal lint CI.

Refs <freedomofpress/securedrop-tooling#18>.
  • Loading branch information
legoktm committed Dec 20, 2024
1 parent 73fc073 commit 2027441
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
steps:
- run: dnf install -y git make
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install dependencies
run: |
make test-deps
Expand All @@ -27,6 +29,8 @@ jobs:
steps:
- run: dnf install -y git make
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install dependencies
run: |
make build-deps
Expand All @@ -45,6 +49,8 @@ jobs:
steps:
- run: dnf install -y make
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install dependencies
run: |
make test-deps
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/nightlies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- run: dnf install -y make git
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install dependencies
run: make build-deps
- name: Build RPM
Expand Down Expand Up @@ -56,6 +58,8 @@ jobs:
path: "securedrop-yum-test"
lfs: true
token: ${{ secrets.PUSH_TOKEN }}
# We need to store credentials here
persist-credentials: true
- name: Commit and push
run: |
git config --global user.email "[email protected]"
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ venv: ## Provision a Python 3 virtualenv for development (ensure to also install
check: lint test ## Runs linters and tests

.PHONY: lint
lint: check-ruff mypy rpmlint shellcheck ## Runs linters (ruff, mypy, rpmlint, and shellcheck)
lint: check-ruff mypy rpmlint shellcheck zizmor ## Runs all linters

.PHONY: test-launcher
test-launcher: ## Runs launcher tests
Expand Down Expand Up @@ -238,6 +238,10 @@ rpmlint: ## Runs rpmlint on the spec file
shellcheck: ## Runs shellcheck on all shell scripts
./scripts/shellcheck.sh

.PHONY: zizmor
zizmor: ## Lint GitHub Actions workflows
poetry run zizmor .

# Explanation of the below shell command should it ever break.
# 1. Set the field separator to ": ##" to parse lines for make targets.
# 2. Check for second field matching, skip otherwise.
Expand Down
27 changes: 25 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ types-setuptools = "^75.6.0"
ruff = "^0.8.3"
python-debian = "^0.1.49"
pysequoia = "^0.1.25"
zizmor = "*"

[tool.ruff]
line-length = 100
Expand Down

0 comments on commit 2027441

Please sign in to comment.