project: Pin Python dependencies#802
Conversation
9700c68 to
d01c275
Compare
| --hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \ | ||
| --hash=sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970 | ||
| # via tox | ||
| colorama==0.4.6 \ |
There was a problem hiding this comment.
Can colorama really affect release output? That sounds like serious security design attack surface issues if it can.
There was a problem hiding this comment.
Not sure what you mean with this comment, colorama is a dependency of tox, this file was generated with only tox as the package to install.
There was a problem hiding this comment.
If colorama is a dependency of tox only, then it does not need to be pinned to a specific SHA because tox should NEVER be in a position to affect source code or releases, or have any side effect. It should simply not be part of that attack surface.
Same for this entire requirements-tox.txt file.
| --hash=sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106 \ | ||
| --hash=sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272 \ | ||
| --hash=sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a \ | ||
| --hash=sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7 |
There was a problem hiding this comment.
Any idea why some dependencies need a crazy number of hashes?
There was a problem hiding this comment.
They can have different pre-built binaries for different platforms, and because of that all the hashes need to be added.
There was a problem hiding this comment.
Every distribution of a package (specific python version, platform, output format like wheels vs tarball) needs to be added to the list of hashes.
There was a problem hiding this comment.
Isn't there a way to "checksum the list of checksums" and reduce the number?
Checksums are meant to be compared, that's their only purpose. Often enough, they need to be compared by humans but no one is going to compare dozens of checksums visually.
There was a problem hiding this comment.
I don't think so, not at least where other tooling (dependabot) can still parse them.
There was a problem hiding this comment.
not at least where other tooling (dependabot) can still parse them.
It does not have to be mutually exclusive. We could have both the list and its sum (if there were such a sum)
There was a problem hiding this comment.
Not sure what to do here, this is generated using tools I frequently use.
| @@ -0,0 +1,346 @@ | |||
| # This file was autogenerated by uv via the following command: | |||
| # uv pip compile --universal --python-version 3.9 --generate-hashes --group ci -o requirements-ci.txt pyproject.toml | |||
There was a problem hiding this comment.
Why do we need the same hashes 4 times? Is there no way to include and re-use?
There was a problem hiding this comment.
What do you mean with the same hashes? For the different requirements files? These are generated with the entire chain of sub-dependencies, not sure if common packages could be extracted.
There was a problem hiding this comment.
Also installing all the different requirement files would simply skip already installed packages. The hashes are identical.
There was a problem hiding this comment.
Thanks for your patience, I'm slowly making sense of all this.
I don't see why we need to pin tox dependencies. I hope tox is not involved in the release process, is it? I mean, I hope there is no way a compromised tox could affect the release output in any way, correct? If it were capable of that, that would be a much bigger problem.
There was a problem hiding this comment.
It's one of the medium security issues checked by the OpenSSF tool: https://github.com/zephyrproject-rtos/west/security/code-scanning/26
There was a problem hiding this comment.
Even in the "read-only" case we want to ensure that our simplest CI actions are running the tools we expect them to run. Be it setuptools, build, colorama, tox, ... really any tool or package.
That's just a statement without a rationale.
Apologies, this was not intentional, I guess I am unable to answer your initial question.
As @kartben mentioned, access to CI already opens that "read-only" view. So if that's what you're referring to as "least privilege" then I guess we can't trust Github for that matter.
It's not about "trusting GitHub.com" in general, I agree there is not a lot we can do there. It's about trusting project-specific, automated workflows and controlling their respective access levels.
So are you saying that all GitHub workflows must have the same, full access level no matter what side effects they need? In other words, running
pylintor creating a new, official release requires the same level of complete access? Not having something that simple and that effective would be very sad, even more sad when compared to the incredibly fine-grained docs.github.com/en/organizations/managing-peoples-access-to-your-organization-with-roles/roles-in-an-organization that no one ever fully understands and to all the incoming CodeQL, pinning and Dependabot complexity.
@marc-hb I appreciate your efforts and value your opinion, but in the context of the PR, I have no clue what to do with this comment. Is this a showstopper? Can you give any suggestions on what would be a better workflow/solution?
I'd like to move forward with this, as I think it is an improvement, both for testing and packaging. It follows best practices. It relies on tooling, yes, but alongside automation that should help maintainers.
There was a problem hiding this comment.
So are you saying that all GitHub workflows must have the same, full access level no matter what side effects they need? In other words, running pylint or creating a new, official release requires the same level of complete access?
Do you know the answer?
There was a problem hiding this comment.
So are you saying that all GitHub workflows must have the same, full access level no matter what side effects they need? In other words, running pylint or creating a new, official release requires the same level of complete access?
Do you know the answer?
The closest, I can find, is this: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions
There was a problem hiding this comment.
Thanks @henrikbrixandersen . So it does look indeed possible to de-privilege test runs and code scanners. Unlike rubber-stamping dozens of checksums, this looks like actual security.
There was a problem hiding this comment.
Yes, this is already applied to all current workflows with:
permissions:
contents: readAny other permission is defaulted to none:
If you specify the access for any of these permissions, all of those that are not specified are set to none.
7376504 to
a93bb9d
Compare
There was a problem hiding this comment.
I'm confused by the file names: requirements-tox.txt is used in .github/ CI while requirements-ci.txt is used in tox.ini... is this intended?
Automation aside, after this PR how can I simply test the latest version of all dependencies and in my workspace and detect any new incompatibility or regression in them?
There was a problem hiding this comment.
Yes, the file names maybe aren't clear, currently:
requirements-tox.txt -> the dependency chain to install tox itself
requirements-ci.txt -> the dependencies to run tox
requirements.txt -> the dependencies of west
requirements-build.txt -> the dependencies to create a package
Automation aside, after this PR how can I simply test the latest version of all dependencies and in my workspace and detect any new incompatibility or regression in them?
I was thinking about making this easier too, I can add a script that would create/update the requirements files (without dependabot).
There was a problem hiding this comment.
Renamed the files, now:
requirements.txt -> the dependencies of west
requirements-tox.txt -> the dependencies to run tox
requirements-install-build.txt -> the dependencies to create a package
requirements-install-tox.txt -> the dependencies to install tox
ee89738 to
af66ce0
Compare
Let me try to clarify.
"Security theater" sounds harmless and even fun maybe. But it is actually a dangerous distraction because it steals scarce attention and brain cycles and because routine tasks are mind-numbing. Speaking of scarce attention and distractions, OS images of runners offer a much larger attack surface. Are those all pinned too and who's going to review updates of entire images like Ubuntu and others? I noticed that GitHub performs "continuous" updates of its default runners. |
Even if you disagree with this, you'll agree the risk level is much lower. So these could be done later - after learning from experience with privileged dependencies. "Smaller PRs". |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #802 +/- ##
=======================================
Coverage 84.06% 84.06%
=======================================
Files 11 11
Lines 3345 3345
=======================================
Hits 2812 2812
Misses 533 533 🚀 New features to boost your workflow:
|
|
@marc-hb @henrikbrixandersen @kartben is anything here not ready for merging? It'd be great to move this forward. @marc-hb in particular, I am not sure by reading your comments whether you are OK with this change or not. |
There was a problem hiding this comment.
@marc-hb in particular, I am not sure by reading your comments whether you are OK with this change or not.
I'm OK with only "half" of it. Pinning requirements.txt makes sense, pinning requirements-tox.txt does not.
I'm very concerned about the perception that pinning is the latest security silver bullet. For years we were told to "update, update and update" to stay secure. Now it's the opposite. Which is it? Neither, it's complicated. And it can never be that "cheap".
EDIT: Pinning is only one tool in the box. It's not a hammer that sees everything as a nail.
| --hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \ | ||
| --hash=sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970 | ||
| # via tox | ||
| colorama==0.4.6 \ |
There was a problem hiding this comment.
If colorama is a dependency of tox only, then it does not need to be pinned to a specific SHA because tox should NEVER be in a position to affect source code or releases, or have any side effect. It should simply not be part of that attack surface.
Same for this entire requirements-tox.txt file.
I have to disagree here, pinning
It isn't a silver bullet, this has never been stated. It is an improvement as it pins the "current" state of what is thought to be an accepted version of the tool. I would argue we still do "update, update, update", but I prefer to offload that to tooling, and in this case dependabot. |
|
As a side-note: |
I tried to phrase the difference in 2 or 3 different ways. Maybe none were well written, but your reply does not even try to mention any of them. I give up! |
I'm sorry, I may have difficulties explaining this, but requirements.txt is only relevant during CI, as is requirements-tox.txt. During installation of west itself, it isn't used. |
I think that is still besides my main point.
dependabot is nice but it does absolutely nothing to help with actual security audits. Except giving a bit of a false sense maybe. |
Off-topic but since this thread is doomed anyway... I've used homebrew on my mac since forever. Once, I tried to make a one-line change in one of the packages. That's the "essential" litmus test. I tried for hours and gave up. Probably unrelated to pinning but really not impressed. |
Generate pinned requirement files from pyproject.toml for tox. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Create pinned requirement files for both build/setuptools and tox and use these in the Github workflows. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Let dependabot check for python pinned dependency updates on a monthly schedule. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The helper script uses the uv command to create universal requirement files. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
|
@marc-hb this has been now open for a while. My impression when reading your comments is that you disagree with pinning everything as a rule, but are not strictly opposed to using pinning as tool. So here's my question: if @pdgendt only pinned |
|
I'm not in favour of doing only one, but not the other. I'll close this and not include it in v1.4, maybe try to come up with something for v2.0. |
Generate pinned requirement files from pyproject.toml for tox.
Additionally create pinned requirement files for the Github workflows.