forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix user.list_groups omits remote groups
* fixes saltstack#64953 user.list_groups omits remote groups * fixes saltstack#65029 support for pysss can be removed * add changlog entries * add tests for _getgrall and local vs remote group handling * add negative tests for _getgrall * root can still read the file and tests run as root * remove permission check as its probably an unreachable edge case --------- Co-authored-by: nicholasmhughes <[email protected]> BACKPORT-UPSTREAM=saltstack#65077
- Loading branch information
Showing
7 changed files
with
122 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed grp.getgrall() in utils/user.py causing performance issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix user.list_groups omits remote groups via sssd, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tech Debt - support for pysss removed due to functionality addition in Python 3.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
pytest.importorskip("grp") | ||
|
||
import grp | ||
|
||
import salt.utils.user | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def etc_group(tmp_path): | ||
etcgrp = tmp_path / "etc" / "group" | ||
etcgrp.parent.mkdir() | ||
etcgrp.write_text( | ||
dedent( | ||
"""games:x:50: | ||
docker:x:959:debian,salt | ||
salt:x:1000:""" | ||
) | ||
) | ||
return etcgrp | ||
|
||
|
||
def test__getgrall(etc_group): | ||
group_lines = [ | ||
["games", "x", 50, []], | ||
["docker", "x", 959, ["debian", "salt"]], | ||
["salt", "x", 1000, []], | ||
] | ||
expected_grall = [grp.struct_group(comps) for comps in group_lines] | ||
|
||
grall = salt.utils.user._getgrall(root=str(etc_group.parent.parent)) | ||
|
||
assert grall == expected_grall | ||
|
||
|
||
def test__getgrall_bad_format(etc_group): | ||
with etc_group.open("a") as _fp: | ||
_fp.write("\n# some comment here\n") | ||
|
||
with pytest.raises(IndexError): | ||
salt.utils.user._getgrall(root=str(etc_group.parent.parent)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from types import SimpleNamespace | ||
|
||
import pytest | ||
|
||
from tests.support.mock import MagicMock, patch | ||
|
||
pytest.importorskip("grp") | ||
|
||
import grp | ||
|
||
import salt.utils.user | ||
|
||
|
||
def test_get_group_list(): | ||
getpwname = SimpleNamespace(pw_gid=1000) | ||
getgrgid = MagicMock(side_effect=[SimpleNamespace(gr_name="remote")]) | ||
group_lines = [ | ||
["games", "x", 50, []], | ||
["salt", "x", 1000, []], | ||
] | ||
getgrall = [grp.struct_group(comps) for comps in group_lines] | ||
with patch("os.getgrouplist", MagicMock(return_value=[50, 1000, 12000])), patch( | ||
"pwd.getpwnam", MagicMock(return_value=getpwname) | ||
), patch("salt.utils.user._getgrall", MagicMock(return_value=getgrall)), patch( | ||
"grp.getgrgid", getgrgid | ||
): | ||
group_list = salt.utils.user.get_group_list("salt") | ||
assert group_list == ["games", "remote", "salt"] | ||
getgrgid.assert_called_once() |