Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11631 GitHub Workflows security hardening #11632

Merged
merged 11 commits into from Sep 4, 2022
Merged

Conversation

sashashura
Copy link
Contributor

@sashashura sashashura commented Sep 2, 2022

Fixes #11631

This PR adds explicit permissions section to workflows. This is a security best practice because by default workflows run with extended set of permissions (except from on: pull_request from external forks). By specifying any permission explicitly all others are set to none. By using the principle of least privilege the damage a compromised workflow can do (because of an injection or compromised third party tool or action) is restricted.
It is recommended to have most strict permissions on the top level and grant write permissions on job level case by case.

Signed-off-by: sashashura <93376818+sashashura@users.noreply.github.com>
@sashashura sashashura changed the title [#11631] GitHub Workflows security hardening #11631 GitHub Workflows security hardening Sep 2, 2022
@altendky
Copy link
Member

altendky commented Sep 2, 2022

Thanks for making me see this! I was totally unaware of this feature. On the off chance, do you know when this was added? Or did I always just miss it...

@sashashura
Copy link
Contributor Author

Read/write permissions for non pull_request triggers were from very beginning. Explicit control of permissions was introduced about a year ago https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
I guess that this is ok.
A bit better than what we had before, mostly future-proof.

I think we were always fine, as we make simple usage of GHA.

We don't use pull_request_target.

We have recently introduced workflow_dispatch but I think this was always safe.
I can't find much info about workflow_dispatch security.
I know Jean-Paul has tried using it with forks and it failed.


Also, I hope we can keep GHA usage simple, to reduce our dependency on GHA and at the same time, improve security.

@@ -339,6 +342,8 @@ jobs:
# process late in the release cycle,
# The files are published only when a tag is created.
release-publish:
permissions:
contents: write
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. so we need this in write mode, only to update the "stable" branch.

The "stable" branch was added as a hack, since Read the docs, doesn't recognizes our twisted-12.23.45 tag format, and can't determine the latest stable version.

Maybe for better security, the "stable" branch update can be moved into a separate job that is performed after release-publish.

So, this would go further with the principle of least privilege

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you got the idea! Restrict as much as possible. I just usually try to minimize the changes to avoid breaking anything. I have split it into a separate job. Please, take a look.

sashashura and others added 2 commits September 3, 2022 06:26
Also make it a dependency for the general job success.
Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the changes.

I push a change that adds some extra comment/docs for why we need the extra job.

I have triggered the auto-merge for this. I hope all will be ok.

Not sure how our 'all-success' works with the skip state.
I guess it might fail.

The idea is that we want all-success as a single way to monitor the success of the jobs for a commit... but we might need to remove the stable branch update job.

@adiroiban
Copy link
Member

Thanks, Sasha for the change.

Much appreciated to get help with the supply chain security.
It's a big topic these days and I think it was something overlooked for a long time.


Before merging this I would like to get a second opinion from @altendky regarding https://github.com/twisted/twisted/pull/11632/files#diff-245392b692a50c38ecab4381b118862db514035c10983f3bd4f4b7f1f4be4692R440

I think that not failing on skip is ok.


The previous issue was that on fail, the job was considered skipped, so we didn't had a final failure.

@adiroiban adiroiban merged commit d415545 into twisted:trunk Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove unnecessary permissions in workflows
4 participants