Debian Codegraph @

testsuite/operator-path-dir-daemon-leaf_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # A leaf-level module exclude (e.g. exclude = /public/f0, where the dir /public
3 # is itself served) must not be bypassable by a peer-supplied --partial-dir/
4 # --backup-dir symlink. (Codex-review follow-up to Omar Elsayed's findings.)
5 #
6 # The parent dir is served (it has other, non-excluded files), so resolution is
7 # allowed to descend into it; only the single leaf f0 is hidden. An in-module
8 # euid-owned symlink -> that served dir, used as the operator-path, targets the
9 # hidden leaf -- which the parent-only ownership walk did not filter-check. The
10 # leaf must be filter-checked too, so the peer cannot delete/overwrite it.
11 #
12 # Runs unprivileged: the boundary is the module exclude, not a uid.
13
14 import os
15 import subprocess
16
17 from rsyncfns import (
18 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
19 )
20
21 SECRET = "LEAF-EXCLUDED-IN-A-SERVED-DIR\n"
22
23
24 def run_case(label, opt, extra, port):
25 base = SCRATCHDIR / f'leaf-{label}'
26 rmtree(base)
27 base.mkdir()
28 mod = base / 'mod'
29 pub = mod / 'public' # served dir; only /public/f0 is excluded
30 pub.mkdir(parents=True)
31 (pub / 'f0').write_text(SECRET)
32 (pub / 'served.txt').write_text("served\n") # sibling => 'public' is served
33 (mod / 'f0').write_text("OLD-DEST-CONTENT\n")
34 os.symlink('public', mod / 'blink')
35 src = base / 'src'
36 src.mkdir()
37 (src / 'f0').write_text("NEW\n")
38
39 conf = write_daemon_conf(
40 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/public/f0'})],
41 {'pid file': str(SCRATCHDIR / f'rsyncd-leaf-{label}.pid')},
42 name=f'leaf-{label}.conf')
43 url = start_test_daemon(conf, port)
44 subprocess.run(
45 rsync_argv('-a', *extra, f'{opt}=/blink', f'{src}/', f'{url}mod/'),
46 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
47 after = (pub / 'f0').read_text() if (pub / 'f0').exists() else None
48 if after == SECRET:
49 test_fail(
50 f"{label}: the daemon refused a {opt} symlink to a leaf-excluded file "
51 f"that stock rsync (3.2.7) reaches: public/f0 is unchanged ({after!r}). "
52 "The daemon exclude filter is name-based ('blink' is not excluded), not "
53 "a symlink boundary; it must not block this.")
54
55
56 run_case('backup', '--backup-dir', ['--backup'], 12906)
57 run_case('partial', '--partial-dir', [], 12907)
58 print("daemon exclude is name-based: an operator-path symlink reaches a "
59 "leaf-excluded file in a served dir (3.2.7-equivalent)")