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

Upgrade zizmor to the latest version in CI #15649

Merged
merged 4 commits into from
Jan 22, 2025
Merged

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 21, 2025

Summary

The latest version of zizmor points out that we have the default permissions set in several of our GitHub workflows that don't really need any permissions at all. These can be made more secure by restricting the permissions for these workflows.

Test Plan

CI on this PR. All workflows being modified here are fully run as part of normal PR CI.

@AlexWaygood AlexWaygood added red-knot Multi-file analysis & type inference ci Related to internal CI tooling and removed red-knot Multi-file analysis & type inference labels Jan 21, 2025
Copy link
Contributor

github-actions bot commented Jan 21, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@AlexWaygood AlexWaygood marked this pull request as ready for review January 21, 2025 18:01
Comment on lines 13 to 17
excessive-permissions:
ignore:
- build-docker.yml
- publish-playground.yml
- publish-docs.yml
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't make modifications to these files because they don't run as part of normal PR CI (only during releases, usually) and it wasn't obvious to me how to figure out what permissions each workflow needs. I didn't want to break the release workflow, and it didn't seem worth investing a large amount of time into trying to investigate exactly what permissions each workflow needed, so I left it for now.

Copy link
Member

Choose a reason for hiding this comment

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

The permissions related to jobs in the release workflow are in Cargo.toml here:

ruff/Cargo.toml

Lines 309 to 310 in 4cfa355

# Custom permissions for GitHub Jobs
github-custom-job-permissions = { "build-docker" = { packages = "write", contents = "read" }, "publish-wasm" = { contents = "read", id-token = "write", packages = "write" } }

And, can also be referred in the release.yml.

So, I think it's just build-docker.yml that requires specific permission while the other two jobs don't require any.

But, I'm fine leaving it as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Aah, thank you for pointing that out!

So, I think it's just build-docker.yml that requires specific permission while the other two jobs don't require any.

I think if we put permissions: {} in e.g. publish-wasm.yml, it would override the permissions passed to the workflow by release.yml -- the docs here state:

The GITHUB_TOKEN permissions passed from the caller workflow can be only downgraded (not elevated) by the called workflow.

And the called workflow here would be publish-wasm.yml, so that would mean that publish-wasm.yml's more restricted permissions would downgrade the permissions passed to it by release.yml, breaking the release workflow.

I think that means that each of these workflows needs to have exactly the same permissions in their individual workflow files as they have passed to them by release.yml -- does that sound right to you?

Copy link
Member

Choose a reason for hiding this comment

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

The GITHUB_TOKEN permissions passed from the caller workflow can be only downgraded (not elevated) by the called workflow.

And the called workflow here would be publish-wasm.yml, so that would mean that publish-wasm.yml's more restricted permissions would downgrade the permissions passed to it by release.yml, breaking the release workflow.

I think that means that each of these workflows needs to have exactly the same permissions in their individual workflow files as they have passed to them by release.yml -- does that sound right to you?

Interesting, doesn't this mean that the nested workflow (e.g., publish-wasm.yml) can have permissions: {} because that's more restrictive as compared to the parent workflow (release.yml) ?

Otherwise, we'll need to revert the build-binaries.yml update in this PR as that's also a nested workflow called by release.yml.

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise, we'll need to revert the build-binaries.yml update in this PR as that's also a nested workflow called by release.yml.

I'm pretty confident that the build-binaries.yml change is okay because, unlike the other workflows, that workflow is run exactly the same way as part of PR CI as it is when it's called from release.yml. (And the CI on this PR is green.)

I'm just going to leave this as-is for now, but I'm very happy if somebody else wants to experiment with removing these ignores and actually fixing the issues zizmor is complaining about!

Comment on lines 13 to 17
excessive-permissions:
ignore:
- build-docker.yml
- publish-playground.yml
- publish-docs.yml
Copy link
Member

Choose a reason for hiding this comment

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

The permissions related to jobs in the release workflow are in Cargo.toml here:

ruff/Cargo.toml

Lines 309 to 310 in 4cfa355

# Custom permissions for GitHub Jobs
github-custom-job-permissions = { "build-docker" = { packages = "write", contents = "read" }, "publish-wasm" = { contents = "read", id-token = "write", packages = "write" } }

And, can also be referred in the release.yml.

So, I think it's just build-docker.yml that requires specific permission while the other two jobs don't require any.

But, I'm fine leaving it as it is.

@@ -10,3 +10,8 @@ rules:
ignore:
- build-docker.yml
- publish-playground.yml
excessive-permissions:
ignore:
Copy link
Member

Choose a reason for hiding this comment

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

It might be helpful to add a short comment explaining why they ignored. Ideally, this wouldn't be necessary (maybe add a todo?)

Copy link
Member Author

Choose a reason for hiding this comment

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

there was already a TODO on line 4, but I added a comment closer to these lines explaining exactly why they are ignored :-)

@AlexWaygood AlexWaygood enabled auto-merge (squash) January 22, 2025 16:57
@AlexWaygood AlexWaygood merged commit 05abd64 into main Jan 22, 2025
37 of 38 checks passed
@AlexWaygood AlexWaygood deleted the alex/upgrade-zizmor branch January 22, 2025 17:00
dcreager added a commit that referenced this pull request Jan 24, 2025
* main:
  [red-knot] MDTests: Do not depend on precise public-symbol type inference (#15691)
  [red-knot] Make `infer.rs` unit tests independent of public symbol inference (#15690)
  Tidy knot CLI tests (#15685)
  [red-knot] Port comprehension tests to Markdown (#15688)
  Create Unknown rule diagnostics with a source range (#15648)
  [red-knot] Port 'deferred annotations' unit tests to Markdown (#15686)
  [red-knot] Support custom typeshed Markdown tests (#15683)
  Don't run the linter ecosystem check on PRs that only touch red-knot crates (#15687)
  Add `rules` table to configuration (#15645)
  [red-knot] Make `Diagnostic::file` optional (#15640)
  [red-knot] Add test for nested attribute access (#15684)
  [red-knot] Anchor relative paths in configurations (#15634)
  [`pyupgrade`] Handle multiple base classes for PEP 695 generics (`UP046`) (#15659)
  [`pyflakes`] Treat arguments passed to the `default=` parameter of `TypeVar` as type expressions (`F821`) (#15679)
  Upgrade zizmor to the latest version in CI (#15649)
  [`pyupgrade`] Add rules to use PEP 695 generics in classes and functions (`UP046`, `UP047`) (#15565)
  [red-knot] Ensure a gradual type can always be assigned to itself (#15675)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Related to internal CI tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants