Skip to content

GH Actions: set permissions for each workflow/job - #218

Merged
antecedent merged 1 commit into
masterfrom
feature/ghactions-set-minimal-permissions
Aug 18, 2026
Merged

antecedent merged 1 commit into
masterfrom
feature/ghactions-set-minimal-permissions

Conversation

@jrfnl

@jrfnl jrfnl commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

Users frequently over-scope their workflow and job permissions, or set broad workflow-level permissions without realizing that all jobs inherit those permissions.

Furthermore, users often don't realize that the default GITHUB_TOKEN permissions can be very broad, meaning that workflows that don't configure any permissions at all can still provide excessive credentials to their individual jobs.

Remediation
In general, permissions should be declared as minimally as possible, and as close to their usage site as possible.

In practice, this means that workflows should almost always set permissions: {} at the workflow level to disable all permissions by default, and then set specific job-level permissions as needed.

Refs:

Notes:

  • Includes a few minor tweaks for consistency in the instructions order.
  • The permissions added are based on an best effort to discover the ones needed. Some tweaking may still be needed.

@antecedent And while looking at the workflows to create this PR, I noticed the following:

  1. The regenerate-pages job in the release.yml workflow seems kind of useless as it doesn't do anything other than checkout the branch and create an empty commit. What is that job supposed to do ?
    Looking at the website, the changelog page feels painfully out of date.
  2. For the PHAR releases it would probably be a good idea to enable creating attestations (SLSA). It would only take a small tweak to the bundle job to enable that.

> Users frequently over-scope their workflow and job permissions, or set broad workflow-level permissions without realizing that all jobs inherit those permissions.
>
> Furthermore, users often don't realize that the _default_ `GITHUB_TOKEN` permissions can be very broad, meaning that workflows that don't configure any permissions at all can _still_ provide excessive credentials to their individual jobs.
>
> **Remediation**
> In general, permissions should be declared as minimally as possible, and as close to their usage site as possible.
>
> In practice, this means that workflows should almost always set `permissions: {}` at the workflow level to disable all permissions by default, and then set specific job-level permissions as needed.

Refs:
* https://docs.zizmor.sh/audits/#excessive-permissions

**Notes**:
* Includes a few minor tweaks for consistency in the instructions order.
* The permissions added are based on an best effort to discover the ones needed. Some tweaking may still be needed.
@antecedent

Copy link
Copy Markdown
Owner

@jrfnl: I believe that regenerate-pages was supposed to be my starting point for implementing the things that you describe: auto-updating the changelog and bumping the version number on the home page. I never got to any of that, though. For the time being, I could replace the changelog page with a link to the list of releases on GitHub.

As for the artifact attestations, thank you for bringing them to my attention; I will take a look.

@antecedent
antecedent merged commit 652f096 into master Aug 18, 2026
24 of 26 checks passed
@antecedent
antecedent deleted the feature/ghactions-set-minimal-permissions branch August 18, 2026 08:13
@jrfnl

jrfnl commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

@jrfnl: I believe that regenerate-pages was supposed to be my starting point for implementing the things that you describe: auto-updating the changelog and bumping the version number on the home page. I never got to any of that, though. For the time being, I could replace the changelog page with a link to the list of releases on GitHub.

I see. Want me to have a look at this when I find some time ?

@antecedent

Copy link
Copy Markdown
Owner

I see. Want me to have a look at this when I find some time ?

Thank you for offering that! At the same time, I wonder if the GH Pages site is worth keeping at all? There is not much to that site in general; it seems that a more comprehensive README could do its job. (Or a couple of separate Markdown files by topic.) But that could be just the way I see it. What do you think?

@jrfnl

jrfnl commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you for offering that! At the same time, I wonder if the GH Pages site is worth keeping at all? There is not much to that site in general; it seems that a more comprehensive README could do its job. (Or a couple of separate Markdown files by topic.) But that could be just the way I see it. What do you think?

Pff... not an easy question to answer, but I do have thoughts about this....

I do think having a GH pages website has value, both for search engines as well as for having docs layed out in a human friendly manner and when I looked at the site the other day when working on this PR, I quite liked it.

Having said that, a GH Pages site created via a gh-pages branch is painful to maintain as updating the docs after a new feature would be added or when something has changed, always requires a separate PR, so is easily forgotten and requires more contributor education.
Also, checking out an orphan branch in a repo, tends to destroy .gitignored/git-excluded files related to the main branch, which is a PITA. I have gotten into the habit of always having two local clones of repos with gh-pages branches. One for normal work, one for GH Pages, but I can imagine less experienced contributors having some nasty surprises when they first contribute to a gh-pages branch.

Originally, the only way to have a GH Pages site was via a gh-pages branch which would then automagically deploy with a black box preprocessing and deploy process involving Jekyll etc.
This still works and is what is currently used for this repo, though AFAICS, the advantages of Jekyll/Liquid and the API access during compilation are not used at this time.
Note: when using the Jekyll/Liquid preprocessing properly, the source files can also be plain markdown or an HTML/markdown mixture, which would probably make maintenance more straight forward.

Just as an example of what you can do with Liquid/Jekyll - the contributors list with the usernames and avatars on this TGMPA Authors page is generated with this small snippet of Jekyll/Liquid and auto-updates on every deploy.
If you are interested in learning more about what's possible with Liquid/Jekyll, you might want to have a browse through this old slidedeck of mine. The info is a bit dated, but still relevant. The examples I show off in that slidedeck can all be seen in action in the TGMPA site I linked above.

So, as an initial step, we could look at adding some Liquid/Jekyll magic to auto-update things like the version number of the last release, the links to PHAR downloads and the changelogs.

Now, for the "orphan gh-pages branch is a PITA" part.... The good news is that things have evolved since GH Pages were introduced and there are now two other options available:

  • Commit the docs in a separate folder (docs) on the main branch of the repo and still use the automagic black box preprocessing and deployment.
  • Set things up in whatever way is best for the project, including doing your own preprocessing (which could still be using Jekyll) and deploying via a GH Actions workflow which is maintained in the repository.

The first option would probably already make life a little easier for maintenance of the site and I think we could probably maintain the history of the docs if we move the files into a docs subdirectory and then merged the gh-pages branch to the main branch.
Once that's done, it would be just a toggle on the Settings -> GH Pages page to switch to deploying from the docs subdirectory.
Just like for the gh-pages branch, we can still add some Jekyll/Liquid magic and switch to markdown if we move things to a docs directory. That will still work.

The second option is to take complete control. In that case, I'd still advocate for moving the skeletons of the docs to the main branch, but by using your own workflow, there's all sort of things which suddenly become possible.

Just as an example, here's the (fairly simple) website for the PHPCSUtils project.
It uses a PHP script to convert the project README and CHANGELOG files to pages for the GH Pages website and then runs phpDocumentor to generate the API docs and automatically updates on every release using this workflow.

Alternatively, it could be considered to move the docs to the repo wiki (currently turned off, but that's a setting).
The wiki is also a git repo, but there are no branches and based on a setting it is either "world-writable" or "committers-only".
This is problematic for popular repos, where "world-writable" invites vandalism of the docs, while "committers-only" puts yet another maintenance burden on maintainers. And in both cases, it doesn't allow for review of the changes before they are published.
There are ways around that, but that's not that straight-forward, so basically only worth the time investment for a very popular project.

Example. In the linked repo, I imported the original git history of the wiki as it was into a subdirectory of the new repo and then added automation to update the code samples in the docs and the tables of contents on each page. And then when something gets merged to the main branch, the repo automatically deploys to the wiki of the main project via a GH Actions script.
It's explained a bit more in the CONTRIBUTING guide.

All in all, there are options to automatically update the site on each release which aren't that much work to implement and will not need much maintenance.

I can't decide for you what to do, but I think injecting some small Jekyll/Liquid/GH API snippets would be a good first step.
Moving things into the main branch to allow for a feature PR to include updates to the docs would be a bonus.

Anything beyond that, I think we'd need to weight the time investment needed against the benefits.

Sorry for the long ramble. Take your time to think it over and let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants