Skip to content

RFC/META Harden CI security #34006

Open
Open

Description

@ogrisel

Warning

This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.

Because of the ongoing Mini Shai Hulud attack against CI & OSS supply chain (see Postmortem: TanStack npm supply-chain compromise for details), I think we should review and possibly straighten our CI before releasing 1.9.

In particular, we use the unsafe pull_request_target in several workflows which is a documented attack vector of the Mini Shai-Hulud worm that currently still spreads by corrupting an increasing number of npm and pypi packages.

Short term:

  • Regularly check that the dates of https://pypi.org/project/scikit-learn/#files match our manually triggered release dates (this seems to be the case as of today 2026-05-13)
  • Review our publish_pypi.yml and wheels.yml workflows to make sure it is not subject by cache poisoning attacks (from a cursory glance it does not think we use any build cache, but we should double-check).
  • Review findings reported by zizmor .github/workflows/publish_pypi.yml and zizmor .github/workflows/wheels.yml.
  • Assess if workflows that use pull_request_target can have a side effect on our release process.
  • Unzip and review the contents of the generated wheel files in the release branch prior to uploading to look for unexpected payload.
    • EDIT: I asked Claude (same conversation as the one linked above) to do that on the latest nightly wheel and it did not find anything fishy.

Medium/Long term

I labeled this PR as block as I think we should at least do the short terms items prior to releasing.

We can probably create sub-issues for things we agree are good ideas.

Activity

  1. added this to the 1.9 milestone on May 13, 2026
  2. agriyakhetarpal commented on May 13, 2026

    @agriyakhetarpal
    Contributor

    I believe y'all will be fine using pull_request_target as long as it doesn't check out any user code using actions/checkout and permissions for a specific job are scoped down to only what it needs.

    Another good thing to do here is to hash-pin all refs in pre-commit hooks; they currently aren't so: https://github.com/scikit-learn/scikit-learn/blob/ab6f86c1086377c19754177e0f46eb26e6282be5/.pre-commit-config.yaml. Zizmor may gain functionality to audit this in the future: zizmorcore/zizmor#1799, but for now, either pre-commit autoupdate --freeze or prek autoupdate --freeze will do it.

    Other things to check/do:

    There are also various useful recommendations to check out in this blog, in case you may have not come across it already (it goes quite a bit further about pull_request_target, for example): https://astral.sh/blog/open-source-security-at-astral.

  3. AnneBeyer commented on May 13, 2026

    @AnneBeyer
    Member

    I can create a PR for hash-pinning the actions, unless you're already working on that, @ogrisel?

  4. betatim commented on May 13, 2026

    @betatim
    Member

    @AnneBeyer I have a vague memory of us discussing the topic of using hash'es for GitHub actions before. However I can't find it in the issues :( My memory of it is that we discussed if we need/should pin all actions to hashes or if some can be left pinned to a specific version (e.g. those maintained by GitHub). I think the argument for not going "maximum pinning" was that it makes it more difficult to update things (potentially dependabot stops working) and that would not be great. https://github.com/scikit-learn/scikit-learn/blob/main/.github/dependabot.yml has a comment similar to this in it. Maybe something to fact check given that it is now 2 years later. (Maybe it is time to re-read SPEC8 and/or update its advice as well?)

  5. betatim commented on May 13, 2026

    @betatim
    Member

    Agriya mentioned that we should also look at pre-commit pinning, which made me wonder: should we think about our other CI as well?

    Now that someone mentioned it, using pre-commit makes me super nervous :D We are basically forcing software on every contributor and updating it for them. At least I don't know if/when/how pre-commit updates things and how I could stop it from doing that/ask for my permission.

  6. AnneBeyer commented on May 13, 2026

    @AnneBeyer
    Member

    I think the argument for not going "maximum pinning" was that it makes it more difficult to update things (potentially dependabot stops working) and that would not be great.

    From the last dependabot update PR it looks like it is able to handle both types, but the dependabot repo does have a few open issues on the consistency of hash and version comment in some updates.

  7. ogrisel commented on May 13, 2026

    @ogrisel
    MemberAuthor

    From what I recall, I think we stated we wanted to use SHA pinning on sensitive workflows such as publish_pypi.yml. We might want to do the same for wheels.yml and also configure a 7D cooldown.

  8. ogrisel commented on May 13, 2026

    @ogrisel
    MemberAuthor

    The version comment bug is annoying but not critical.

  9. ogrisel commented on May 15, 2026

    @ogrisel
    MemberAuthor

    I removed the block label based on the feedback of @agriyakhetarpal and the analysis of claude I linked above.

    However, I think it would be worth asking Claude or similar to check that the generated release wheels (e.g. those we push to test.pypi.org) have not been tainted with malware the way I did for nightly wheels.

  10. AnneBeyer commented on May 19, 2026

    @AnneBeyer
    Member

    From what I recall, I think we stated we wanted to use SHA pinning on sensitive workflows such as publish_pypi.yml. We might want to do the same for wheels.yml and also configure a 7D cooldown.

    Should we merge #33917 first to avoid conflicts?

  11. ogrisel commented on May 19, 2026

    @ogrisel
    MemberAuthor

    Should we merge #33917 first to avoid conflicts?

    Let's do that. Thanks for the review @AnneBeyer, I applied your suggestions and enabled auto-merge.

  12. ogrisel commented on May 21, 2026

    @ogrisel
    MemberAuthor

    OSS Supply Chain attacks do not only target CI: they can also target dev tools such as VS Code extensions to propagate by stealing github, pypi or other services credentials from OSS developers: https://www.bleepingcomputer.com/news/security/github-confirms-breach-of-3-800-repos-via-malicious-vscode-extension/

    Isolating the scikit-learn release repo with limited users with permissions on that repo would also help reduce our attack surface and better our project against this way of spreading malware into our release artifacts.

  13. modified the milestones: 1.9, 1.10 on May 26, 2026
  14. ogrisel commented on Jun 16, 2026

    @ogrisel
    MemberAuthor

    Note that @thomasjpfan create the scikit-learn-release repo here: https://github.com/scikit-learn/scikit-learn-release during last week's sprint.

    @thomasjpfan could you please let us know if you found any blockers in the process and maybe open a dedicated issue to cross-reference with a TODO list before being able to update our release process to use this new infrastructure?

  15. ogrisel commented on Jun 16, 2026

    @ogrisel
    MemberAuthor

    Related PR by @lesteve to simplify the release workflow and make it more maintainable: #34215

    EDIT: the workflow file of https://github.com/scikit-learn/scikit-learn-release already uses the cibuildwheel v4 github action.

  16. ogrisel commented on Jun 16, 2026

    @ogrisel
    MemberAuthor

    Also, another related PR to tackle the possibility to implement a relative dependency cooldown policy when refreshing our lockfiles. As documented above, mamba/conda-lock do not yet support them but pixi does. The following PR considers migrating our conda-lock based setup to pixi:

    #34212

    EDIT: I wrote more details about implementing the use of lockfiles and relative dependency cooldowns specifically for the isolated release repo in scikit-learn/scikit-learn-release#1.

  17. thomasjpfan commented on Jun 17, 2026

    @thomasjpfan
    Member

    I opened #34320 that lists out what is left to do and what the release process could look like.

  18. betatim commented on Sep 23, 2026

    @betatim
    Member

    I just saw https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target#default-policy-for-pull_request_target TLDR: from 2 November GitHub will restrict (aka block) workflows that use the pull_request_target trigger. If we want to keep using it we need to setup our own policy,

    I think the workflows we have right now need to use pull_request_target and we are fairly sure that we are "doing it right" (famous last words). So I'd add a policy to allow them.

    Thoughts anyone? @lesteve ?


    https://github.blog/changelog/2026-09-10-control-github-actions-cache-access-with-cache-mode/ looks interesting because it allows us to control access to the cache. This is useful because using one workflow to poison the cache of a different workflow is a "popular" way to exploit workflows. I haven't looked at this carefully enough to know what we can/should do.

  19. lesteve commented on Oct 4, 2026

    @lesteve
    Member

    Sorry I missed this but yeah I think we are fine for now with the "famous last words" caveat as you say 😅.

    The killer combination is pull_request_target + explicit checkout of PR branch code (checkout with pull_request_target checks out main by default), in other words the warnings in https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target#reviewing-the-impact-before-enforcement

    Only allow pull_request_target when it is necessary. Workflows triggered by this event should not check out, build, or run code from an untrusted pull request with access to repository secrets or a privileged GITHUB_TOKEN.

    The Astral security blog post says that they completely disallow pull_request_target:

    We forbid many of GitHub's most dangerous and insecure triggers, such as pull_request_target and workflow_run, across our entire GitHub organization. These triggers are almost impossible to use securely and attackers keep finding ways to abuse them, so we simply don't allow them.

    They recommend using GitHub App in the use cases you would use pull_request_target:

    Of course, there are some use cases that do require these triggers, such as anything that does really need to leave comments on third-party issues or pull requests. In these instances we recommend leaving GitHub Actions entirely and using a GitHub App (or webhook) that listens for the relevant events and acts in an independent context. We cover this pattern in more detail under Automations below.

    I haven't had a closer look how complex it would be and whether it would be worth it. In the past, I guess you would do this with a Heroku thingy (I have recently seen Cloudflare Python workers mentioned recently as a potential Heroku replacement)

  20. lesteve commented on Oct 8, 2026

    @lesteve
    Member

    I read your message too quickly so I thought that you enabled policies @betatim but unfortunately not, I opened #35103 so that we can remember to do it. And of course if you want to do it, it would be more than welcome 😉.

  21. removed this from the 1.10 milestone on Nov 3, 2026
  22. lesteve commented on Nov 3, 2026

    @lesteve
    Member

    I removed the 1.10 milestone because I don't think there is anything that absolutely needs to be done for the upcoming 1.10 release. Let me know if I missed something!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions