Skip to content

Commit 5ea80bb

Browse files
committed
It's gitfs not gtfs, plus some code fixes and cleanup
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
1 parent 9529f72 commit 5ea80bb

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

changelog/cve-2023-20898.security

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fixed gtfs cachedir_basename to avoid hash collisions. Added MP Lock to gtfs. These changes should stop race conditions.
1+
Fixed gitfs cachedir_basename to avoid hash collisions. Added MP Lock to gitfs. These changes should stop race conditions.

salt/utils/gitfs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(
457457

458458
hash_type = getattr(hashlib, self.opts.get("hash_type", "md5"))
459459
# Generate full id. The full id is made from these parts name-id-env-_root.
460-
# Full id stops collections in the gtfs cache.
460+
# Full id stops collections in the gitfs cache.
461461
self._full_id = "-".join(
462462
[
463463
getattr(self, "name", ""),
@@ -683,9 +683,9 @@ def clear_lock(self, lock_type="update"):
683683
Clear update.lk
684684
"""
685685
if self.__class__._master_lock.acquire(timeout=60) is False:
686-
# if gtfs works right we should never see this timeout error.
687-
log.error("gtfs master lock timeout!")
688-
raise TimeoutError("gtfs master lock timeout!")
686+
# if gitfs works right we should never see this timeout error.
687+
log.error("gitfs master lock timeout!")
688+
raise TimeoutError("gitfs master lock timeout!")
689689
try:
690690
return self._clear_lock(lock_type)
691691
finally:
@@ -871,9 +871,9 @@ def _lock(self, lock_type="update", failhard=False):
871871
Place a lock file if (and only if) it does not already exist.
872872
"""
873873
if self.__class__._master_lock.acquire(timeout=60) is False:
874-
# if gtfs works right we should never see this timeout error.
875-
log.error("gtfs master lock timeout!")
876-
raise TimeoutError("gtfs master lock timeout!")
874+
# if gitfs works right we should never see this timeout error.
875+
log.error("gitfs master lock timeout!")
876+
raise TimeoutError("gitfs master lock timeout!")
877877
try:
878878
return self.__lock(lock_type, failhard)
879879
finally:

tests/pytests/unit/utils/test_gitfs.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import string
3-
from time import time
3+
import time
44

55
import pytest
66
import salt.config
@@ -70,14 +70,6 @@ def test_provider_case_insensitive_gitfs_provider(minion_opts, role_name, role_c
7070
# Now try to instantiate an instance with all lowercase
7171
# letters. Again, no need for an assert here.
7272
role_class(*args, **kwargs)
73-
pytest.mark.parametrize(
74-
"role_name,role_class",
75-
(
76-
("gitfs", salt.utils.gitfs.GitFS),
77-
("git_pillar", salt.utils.gitfs.GitPillar),
78-
("winrepo", salt.utils.gitfs.WinRepo),
79-
),
80-
)
8173

8274

8375
@pytest.mark.parametrize(
@@ -126,7 +118,9 @@ def _prepare_remote_repository_pygit2(tmp_path):
126118
remote = os.path.join(tmp_path, "pygit2-repo")
127119
filecontent = "This is an empty README file"
128120
filename = "README"
129-
signature = pygit2.Signature("Dummy Commiter", "dummy@dummy.com", int(time()), 0)
121+
signature = pygit2.Signature(
122+
"Dummy Commiter", "dummy@dummy.com", int(time.time()), 0
123+
)
130124
repository = pygit2.init_repository(remote, False)
131125
builder = repository.TreeBuilder()
132126
tree = builder.write()
@@ -161,10 +155,10 @@ def _prepare_remote_repository_pygit2(tmp_path):
161155

162156
@pytest.fixture
163157
def _prepare_provider(tmp_path, minion_opts, _prepare_remote_repository_pygit2):
164-
cache = os.path.join(tmp_path, "pygit2-repo-cache")
158+
cache = tmp_path / "pygit2-repo-cache"
165159
minion_opts.update(
166160
{
167-
"cachedir": cache,
161+
"cachedir": str(cache),
168162
"gitfs_disable_saltenv_mapping": False,
169163
"gitfs_base": "master",
170164
"gitfs_insecure_auth": False,
@@ -210,16 +204,16 @@ def _prepare_provider(tmp_path, minion_opts, _prepare_remote_repository_pygit2):
210204
"user": "",
211205
}
212206
per_remote_only = ("all_saltenvs", "name", "saltenv")
213-
override_params = tuple(per_remote_defaults.keys())
214-
cache_root = os.path.join(cache, "gitfs")
207+
override_params = tuple(per_remote_defaults)
208+
cache_root = cache / "gitfs"
215209
role = "gitfs"
216210
provider = salt.utils.gitfs.Pygit2(
217211
minion_opts,
218212
_prepare_remote_repository_pygit2,
219213
per_remote_defaults,
220214
per_remote_only,
221215
override_params,
222-
cache_root,
216+
str(cache_root),
223217
role,
224218
)
225219
return provider

tests/unit/utils/test_gitfs.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import tempfile
77

88
import pytest
9-
109
import salt.ext.tornado.ioloop
1110
import salt.fileserver.gitfs
1211
import salt.utils.files

0 commit comments

Comments
 (0)