| 1 |
|
| 2 |
"""A daemon's own "exclude from" file may live outside the module root. |
| 3 |
|
| 4 |
"exclude from" / "include from" / "filter" name operator-configured paths, and |
| 5 |
pointing them at something like /etc/rsync/excludes is the ordinary way to |
| 6 |
write them -- rsyncd.conf(5) puts no constraint on where the file lives. |
| 7 |
|
| 8 |
parse_filter_file() confines a PEER-driven merge file to the module root, since |
| 9 |
a non-chrooted daemon writes --backup-dir entries as root and a raced backup |
| 10 |
symlink is therefore root-owned, which the ownership walk trusts (see |
| 11 |
filter-leak). That confinement must not extend to the operator's own |
| 12 |
parameters: applying it to these three refuses the file outright and takes the |
| 13 |
whole connection down with it, for a config that has nothing to do with the |
| 14 |
attack. |
| 15 |
""" |
| 16 |
|
| 17 |
import subprocess |
| 18 |
|
| 19 |
from rsyncfns import ( |
| 20 |
SCRATCHDIR, makepath, rmtree, rsync_argv, start_test_daemon, test_fail, |
| 21 |
write_daemon_conf, |
| 22 |
) |
| 23 |
|
| 24 |
PORT = 12947 |
| 25 |
|
| 26 |
base = SCRATCHDIR / 'exclude-from-outside' |
| 27 |
rmtree(base) |
| 28 |
module = base / 'module' |
| 29 |
etc = base / 'etc' |
| 30 |
dest = base / 'dest' |
| 31 |
makepath(module, etc, dest) |
| 32 |
|
| 33 |
(module / 'keep.txt').write_text('KEEP\n') |
| 34 |
(module / 'drop.txt').write_text('DROP\n') |
| 35 |
|
| 36 |
(etc / 'excludes').write_text('drop.txt\n') |
| 37 |
|
| 38 |
conf = write_daemon_conf([ |
| 39 |
('m', { |
| 40 |
'path': str(module), |
| 41 |
'read only': 'yes', |
| 42 |
'use chroot': 'no', |
| 43 |
'exclude from': str(etc / 'excludes'), |
| 44 |
}), |
| 45 |
], name='exclude-from-outside.conf') |
| 46 |
url = start_test_daemon(conf, PORT) |
| 47 |
|
| 48 |
proc = subprocess.run( |
| 49 |
rsync_argv('-r', f'{url}m/', str(dest) + '/'), |
| 50 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 51 |
ctx = f'rc={proc.returncode}, output={proc.stdout.strip()[:300]!r}' |
| 52 |
|
| 53 |
if proc.returncode != 0: |
| 54 |
test_fail(f'daemon refused an "exclude from" file outside the module root ({ctx})') |
| 55 |
|
| 56 |
got = sorted(p.name for p in dest.rglob('*') if p.is_file()) |
| 57 |
if got != ['keep.txt']: |
| 58 |
test_fail(f'expected only keep.txt to transfer, got {got} ({ctx})') |
| 59 |
|
| 60 |
print('an operator "exclude from" outside the module root is still honoured') |