Skip to content

Commit 7dc8173

Browse files
Fix containerized AcknowlEDG Forge cg_annotate []
1 parent 44f0e8f commit 7dc8173

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎dev_tools/pylibs/edgacknowledg/forge/runner/roles.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class RunnerPolicy:
2525
2626
- ``commands``: allowed argument prefixes. The first element of each is
2727
resolved on ``search_path`` when the runner starts; a request may name
28-
it either way, and the resolved one runs.
28+
it by name or by any absolute path to the same file, and the resolved
29+
one runs.
2930
- ``roots``: every absolute path in the request (arguments after the
3031
allowed prefix, the working directory, and variable values) must lie
3132
under one of them.

‎dev_tools/pylibs/edgacknowledg/forge/runner/server.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ def _under_roots(value: str, roots: Sequence[Path]) -> bool:
8282
)
8383

8484

85+
def _names_program(name: str, prefix: str, resolved: str) -> bool:
86+
'''Whether a request's ``name`` names the program ``prefix`` resolved to:
87+
by name, or by any absolute path to it (the client may have found it on
88+
a search path of its own, e.g. through Fedora's /usr/sbin, which links to
89+
/usr/bin).
90+
'''
91+
if name in (prefix, resolved):
92+
return True
93+
return (os.path.isabs(name) and
94+
os.path.realpath(name) == os.path.realpath(resolved))
95+
96+
8597
@dataclass(frozen = True)
8698
class Job:
8799
argv: tuple[str, ...]
@@ -102,7 +114,7 @@ def check_request(request: Mapping[str, Any],
102114
prefix_length = 0
103115
for prefix, resolved in commands:
104116
if (len(argv) >= len(prefix) and
105-
argv[0] in (prefix[0], resolved) and
117+
_names_program(argv[0], prefix[0], resolved) and
106118
tuple(argv[1:len(prefix)]) == prefix[1:]):
107119
program = resolved
108120
prefix_length = len(prefix)

‎dev_tools/services/acknowledg-forge/tests/test_runner.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ def _check(root: Path, **request: object) -> object:
106106
def test_only_allowed_commands_run(tmp_path: Path) -> None:
107107
sh = shutil.which('sh')
108108
assert sh is not None
109-
# By name or by the path it resolves to; the resolved one runs.
110-
for name in ('sh', os.path.abspath(sh)):
109+
# Another path to the same program, as the client may find it on its own
110+
# search path (Fedora's /usr/sbin links to /usr/bin).
111+
linked_dir = tmp_path / 'sbin'
112+
linked_dir.symlink_to(os.path.dirname(os.path.abspath(sh)))
113+
# By name, by the path it resolves to, or by any other path to it; the
114+
# resolved one runs.
115+
for name in ('sh', os.path.abspath(sh), str(linked_dir / 'sh')):
111116
job = _check(tmp_path, argv = [name, '-c', 'true'])
112117
assert job.argv[0] == os.path.abspath(sh) # type: ignore[attr-defined]
113118
refused = [

0 commit comments

Comments
 (0)