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

Only make config more permissive in tests that need it #1648

Merged
merged 4 commits into from
Sep 7, 2023

Conversation

EliahKagan
Copy link
Contributor

@EliahKagan EliahKagan commented Sep 7, 2023

Closes #1544

Edit: When making this PR, I didn't notice #1647, which was recently opened (but opened before this PR; #1647 came first). That PR includes an alternative to the approach taken here. It uses a GitPython feature to set protocol.file.allow in git command-like arguments, while this patches GIT_CONFIG_* environment variables. Both approaches are specific and, I believe, robust. The approach in this PR avoids using more GitPython features that are not conceptually under test in the submodule tests. But the approach in #1647 is significantly more compact, which might be considered the more important benefit. I will not mind if this is closed in preference for #1647! At this time, both #1647 and this PR also contain changes beyond those that directly address #1544, and another option, if the approach in #1647 is chosen, would be for me to narrow this PR to make only CI changes, after #1647 is accepted.

(The original description of the changes in this PR, and the rationale for them, follows.)

protocol.file.allow

This eliminates the need for users running the test suite to set protocol.file.allow to always in the global git configuration. Setting it globally to always has security implications, as alluded to in #1544, and as noted in the description in git release notes of how CVE-2022-39253 was fixed, and in git/git@a1d4f67 where its default value was changed from always to user.

On CI, this was not directly a problem, because the CI runner is isolated and not being used to clone unrelated less-trusted repositories. But users are likely to be looking at the CI workflows to figure out how to overcome the fatal: transport 'file' not allowed error locally. Furthermore, by having the test suite make the change automatically and temporarily by modifying process environment variables, the needed setup is simplified for everyone.

The approach taken here is inspired by #1544 (comment) and makes use of GIT_CONFIG_* environment variables. But it is more specific than suggested there, instead temporarily patching the environment only during the runs of the two specific tests that require it, test_list_only_valid_submodules and test_git_submodules_and_add_sm_with_new_commit. This is done without much code duplication, so it can be applied easily to any future test cases that require it. (I think this probably won't ever be needed outside test_submodule.py, because Git's default value of protocol.file.allow is user, not never.)

I patched GIT_CONFIG_* variables in such a way that existing assignments to GIT_CONFIG_* variables, if present, are still used, rather than being replaced or causing an error. I considered patching GIT_ALLOW_PROTOCOL instead, but I decided against it because it may be useful for people running the tests to be able to change what other protocols are allowed/disallowed. Patching GIT_ALLOW_PROTOCOL in a way that respected that would be more complicated than patching GIT_CONFIG_* variables.

safe.directory

protocol.file.allow is one of two security-related configuration options that were set on CI. The other is safe.directory. This is not needed in the pythonpackage.yml workflow, because the cloned repository's files are always owned by the same user that is running pytest and thus git, so I removed it from there. The cygwin-test.yml workflow does currently need it, and I shell-quoted $(pwd) there, which is slightly more robust and better expresses the intent that no splitting or globbing be performed, but otherwise retained it.

I was unsure if I should include changes related to safe.directory in this PR, or open a separate PR. The protocol.file.allow and safe.directory customizations were presented as closely related in the workflows. More importantly, to decide where to put the fixture/helper used for patching protocol.file.allow in test_submodule.py, I checked that it would not be needed elsewhere, by verifying that no test cases inherently require safe.directory to be set (but that it just works around a Cygwin-specific issue). For the same reason, it seems to me that the changes may be easier to review together than separately, as well. However, I would be pleased to make any requested changes to this PR, including splitting out safe.directory-related changes to a separate PR if desired.

This stops setting the current directory as an explicit safe
directory on CI for non-Windows systems, where this is not needed
because the repository has the ownership Git expects. The step name
is updated accordingly to reflect its now narrower purpose.

This also adds shell quoting to $(pwd) in the Cygwin workflow. In
practice, on CI, the path is very unlikely to contain whitespace,
but double-quoting $ expansions on which splitting and globbing are
unwanted is more robust and better expresses intent. This also has
the benefit that users who use the CI workflows as a guide to
commands they run locally, where on Windows they may very well have
spaces somewhere in this absolute path, will use a correct command.
Instead of setting a global git configuration.

This makes no significant difference for security on CI, but it is
an iterative step toward a more specific way of setting them that
will apply on CI and locally and require less configuration.

In addition, this shows an approach more similar to what users who
do not want to carefully review the security impact of changing
the global setting can use locally (and which is more secure).
Instead of setting environment variables just on CI and for the
the entire pytest command, this has the two test cases that need
protocol.file.allow to be set to "always" (instead of "user") set
them, via a shared fixture, just while those tests are running.

Both on CI and for local test runs, this makes it no longer
necessary to set this in a global configuration or through
environment variables, reducing the setup needed to run the tests.
_allow_file_protocol was effectively a _patch_git_config fixture,
being no no shorter, simpler, or clearer by hard-coding the
specific name and value to patch. So this changes it to be that.

As a secondary issue, it previously was called with no arguments,
then that would be used as a decorator. That was unintutive and it
was easy to omit the parentheses accidentally. This resolves that.
@EliahKagan EliahKagan marked this pull request as ready for review September 7, 2023 02:43
@Byron Byron linked an issue Sep 7, 2023 that may be closed by this pull request
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

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

This looks great to me, thanks a lot for the initiative and contribution!

Since this PR is complete for what it is supposed to achieve, let's merge it and deal with safe.directory in a separate PR. Thank you.

@Byron Byron merged commit 11839ab into gitpython-developers:main Sep 7, 2023
@Byron Byron added this to the v3.1.35 - Bugfixes milestone Sep 7, 2023
@EliahKagan EliahKagan deleted the file-protocol branch September 7, 2023 15:34
@EliahKagan
Copy link
Contributor Author

EliahKagan commented Sep 7, 2023

@Byron No problem!

This PR actually had already dealt with safe.directory, in 537af83. It didn't attempt to harmonize the ownership situation in cygwin-test.yml, but it did make the changes described in the safe.directory portion of the PR description. I hope that's okay! If you'd like those changes undone or done differently, I could open a new PR for that.

@Byron
Copy link
Member

Byron commented Sep 8, 2023

I hope that's okay!

I think it's OK as long you think the same :).

renovate bot referenced this pull request in allenporter/flux-local Sep 8, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [GitPython](https://github.com/gitpython-developers/GitPython) |
`==3.1.34` -> `==3.1.35` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/GitPython/3.1.35?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/GitPython/3.1.35?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/GitPython/3.1.34/3.1.35?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/GitPython/3.1.34/3.1.35?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>gitpython-developers/GitPython (GitPython)</summary>

###
[`v3.1.35`](https://github.com/gitpython-developers/GitPython/releases/tag/3.1.35):
- a fix for CVE-2023-41040

[Compare
Source](https://github.com/gitpython-developers/GitPython/compare/3.1.34...3.1.35)

#### What's Changed

- Bump actions/checkout from 3 to 4 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/gitpython-developers/GitPython/pull/1643](https://github.com/gitpython-developers/GitPython/pull/1643)
- Fix 'Tree' object has no attribute '\_name' when submodule path is
normal path by [@&#8203;CosmosAtlas](https://github.com/CosmosAtlas)
in
[https://github.com/gitpython-developers/GitPython/pull/1645](https://github.com/gitpython-developers/GitPython/pull/1645)
- Fix CVE-2023-41040 by
[@&#8203;facutuesca](https://github.com/facutuesca) in
[https://github.com/gitpython-developers/GitPython/pull/1644](https://github.com/gitpython-developers/GitPython/pull/1644)
- Only make config more permissive in tests that need it by
[@&#8203;EliahKagan](https://github.com/EliahKagan) in
[https://github.com/gitpython-developers/GitPython/pull/1648](https://github.com/gitpython-developers/GitPython/pull/1648)
- Added test for PR
[#&#8203;1645](https://github.com/gitpython-developers/GitPython/issues/1645)
submodule path by
[@&#8203;CosmosAtlas](https://github.com/CosmosAtlas) in
[https://github.com/gitpython-developers/GitPython/pull/1647](https://github.com/gitpython-developers/GitPython/pull/1647)
- Fix Windows environment variable upcasing bug by
[@&#8203;EliahKagan](https://github.com/EliahKagan) in
[https://github.com/gitpython-developers/GitPython/pull/1650](https://github.com/gitpython-developers/GitPython/pull/1650)

#### New Contributors

- [@&#8203;CosmosAtlas](https://github.com/CosmosAtlas) made their
first contribution in
[https://github.com/gitpython-developers/GitPython/pull/1645](https://github.com/gitpython-developers/GitPython/pull/1645)
- [@&#8203;facutuesca](https://github.com/facutuesca) made their first
contribution in
[https://github.com/gitpython-developers/GitPython/pull/1644](https://github.com/gitpython-developers/GitPython/pull/1644)

**Full Changelog**:
gitpython-developers/GitPython@3.1.34...3.1.35

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/allenporter/flux-local).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi44My4wIiwidXBkYXRlZEluVmVyIjoiMzYuODMuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
otc-zuul bot pushed a commit to opentelekomcloud-infra/eyes_on_docs that referenced this pull request Sep 11, 2023
Bump gitpython from 3.1.32 to 3.1.35

Bumps gitpython from 3.1.32 to 3.1.35.

Release notes
Sourced from gitpython's releases.

3.1.35 - a fix for CVE-2023-41040
What's Changed

Bump actions/checkout from 3 to 4 by @​dependabot in gitpython-developers/GitPython#1643
Fix 'Tree' object has no attribute '_name' when submodule path is normal path by @​CosmosAtlas in gitpython-developers/GitPython#1645
Fix CVE-2023-41040 by @​facutuesca in gitpython-developers/GitPython#1644
Only make config more permissive in tests that need it by @​EliahKagan in gitpython-developers/GitPython#1648
Added test for PR #1645 submodule path by @​CosmosAtlas in gitpython-developers/GitPython#1647
Fix Windows environment variable upcasing bug by @​EliahKagan in gitpython-developers/GitPython#1650

New Contributors

@​CosmosAtlas made their first contribution in gitpython-developers/GitPython#1645
@​facutuesca made their first contribution in gitpython-developers/GitPython#1644

Full Changelog: gitpython-developers/GitPython@3.1.34...3.1.35
3.1.34 - fix resource leaking
What's Changed

util: close lockfile after opening successfully by @​skshetry in gitpython-developers/GitPython#1639

New Contributors

@​skshetry made their first contribution in gitpython-developers/GitPython#1639

Full Changelog: gitpython-developers/GitPython@3.1.33...3.1.34
v3.1.33 - with security fix
What's Changed

WIP Quick doc by @​LeoDaCoda in gitpython-developers/GitPython#1608
Partial clean up wrt mypy and black by @​bodograumann in gitpython-developers/GitPython#1617
Disable merge_includes in config writers by @​bodograumann in gitpython-developers/GitPython#1618
feat: full typing for "progress" parameter in Repo class by @​madebylydia in gitpython-developers/GitPython#1634
Fix CVE-2023-40590 by @​EliahKagan in gitpython-developers/GitPython#1636
#1566 Creating a lock now uses python built-in "open()" method to work arou… by @​HageMaster3108 in gitpython-developers/GitPython#1619

New Contributors

@​LeoDaCoda made their first contribution in gitpython-developers/GitPython#1608
@​bodograumann made their first contribution in gitpython-developers/GitPython#1617
@​EliahKagan made their first contribution in gitpython-developers/GitPython#1636
@​HageMaster3108 made their first contribution in gitpython-developers/GitPython#1619

Full Changelog: gitpython-developers/GitPython@3.1.32...3.1.33



Commits

c8e303f prepare next release
09e1b3d Merge pull request #1650 from EliahKagan/envcase
8017421 Merge pull request #1647 from CosmosAtlas/master
fafb4f6 updated docs to better describe testing procedure with new repo
9da24d4 add test for submodule path not owned by submodule case
eebdb25 Eliminate duplication of git.util.cwd logic
c7fad20 Fix Windows env var upcasing regression
7296e5c Make test helper script a file, for readability
d88372a Add test for Windows env var upcasing regression
11839ab Merge pull request #1648 from EliahKagan/file-protocol
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the Security Alerts page.

Reviewed-by: Vladimir Vshivkov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3.1.30 & 3.1.31: failing tests Tests fail due to security vulnerability fix in git 2.38.1
2 participants