Skip to content

fix: daemon-access module sub-path and access-rule edge cases - #5526

Merged
oferchen merged 5 commits into
masterfrom
fix/uts-3-daemon-access
Jun 10, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/uts-3-daemon-access

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

ModuleDefinition::permits (the hosts allow/hosts deny matcher used
on every daemon connection) diverged from upstream rsync's
access.c::allow_access(). Upstream short-circuits on the first allow-
list match - "If we match an allow-list item, we always allow access."

  • and only consults the deny list when the allow list is absent or did
    not match. oc-rsync instead evaluated allow and then deny in series, so
    a peer matching both lists was refused. Any daemon config that pairs an
    inclusive hosts allow = * with surgical hostname-pattern deny rules
    silently rejected connections the upstream testsuite expects to be
    accepted (testsuite/rsync.fns:381 ships exactly this idiom for the
    shared hosts allow = localhost 127.0.0.0/24 192.168.0.0/16 10.0.0.0/8 $hostname configuration).

What the fix does

Reorder permits to mirror access.c:264 exactly:

  1. hosts allow non-empty and the peer matches any pattern -> permit
    (deny list never consulted).
  2. hosts allow non-empty, no match, no deny list -> refuse.
  3. Fall through: peer matches a deny rule -> refuse, else permit.

The GHSA-rjfm-3w2m-jf4f fail-closed guard (PR #5524) stays on the deny
path and is unchanged for its existing use cases. After the reorder it
no longer punishes peers who already cleared the allow short-circuit -
a peer admitted by hosts allow is admitted regardless of reverse-DNS
state, which is what upstream does and what operators expect.

Upstream reference

target/interop/upstream-src/rsync-3.4.3/access.c:264-292 defines
allow_access. The comment on line 276 reads "If we match an allow-list
item, we always allow access." testsuite/rsync.fns:352-411 is the
shared daemon configuration the testsuite assembles for every
daemon-related test (daemon.test, daemon-refuse-compress.test,
daemon-gzip-{upload,download}.test), and line 381 declares the
hosts allow directive that pins the matcher behaviour this PR
restores.

Regression tests

In crates/daemon/src/daemon/module_state/tests.rs:

  • module_definition_allow_match_short_circuits_deny - replaces the
    bogus deny_takes_precedence_over_allow expectation.
  • module_definition_deny_applies_when_allow_does_not_match - exercises
    the fall-through path (allow miss + deny list present -> deny check
    runs).
  • module_definition_allow_short_circuit_skips_dns_fail_closed_guard -
    pins the interaction with the GHSA-rjfm-3w2m-jf4f guard: a peer that
    wins the allow short-circuit is admitted even when a hostname-pattern
    deny rule cannot evaluate.
  • module_definition_matches_upstream_rsync_fns_allow_list - reproduces
    upstream's testsuite/rsync.fns:381 allow list and asserts every IPv4
    inside the CIDRs is admitted and every IPv4 outside is refused.

In crates/daemon/src/tests/chunks/:

  • module_definition_ipv4_allow_deny_precedence.rs,
    module_definition_hostname_deny_takes_precedence.rs,
    module_definition_mixed_ip_and_hostname_acl.rs - the chunks whose
    assertions previously codified the bug have been updated to the
    upstream semantics. The hostname chunk now carries both the wildcard-
    allow short-circuit case and a no-allow-list deny case so the matcher
    is pinned in both directions.

Existing GHSA fail-closed regressions
(module_hostname_deny_fails_closed_when_dns_unresolved,
module_ip_deny_unaffected_by_dns_failure) remain green: the guard
still fires on the deny path when the allow list does not match.

Scope

  • No wire-protocol changes.
  • No crates/branding/ changes.
  • No effect on parallel-receive-delta, io_uring, IOCP, flat-flist,
    daemon-tls, DirSandbox, SEND_ZC, or flat arena flist.
  • Daemon #![deny(unsafe_code)] preserved; no clippy waivers.

Test plan

  • CI fmt + clippy green
  • CI nextest green (Linux GNU, Linux musl, macOS, Windows)
  • Upstream testsuite step in interop workflow shows daemon-family
    tests still passing

upstream rsync's `access.c::allow_access()` short-circuits on the first
allow-list match and returns 1 unconditionally - "If we match an allow-
list item, we always allow access." The deny list is consulted only when
the allow list is absent or did not match. oc-rsync's
`ModuleDefinition::permits` instead evaluated allow then deny in series,
so a peer that matched both an allow and a deny pattern was refused.
That divergence breaks any daemon config that uses an inclusive
`hosts allow = *` together with surgical hostname-pattern deny rules,
and silently rejects connections the upstream testsuite expects to be
accepted.

Reorder `permits` to match `access.c:264` exactly:

  1. allow-list non-empty + peer matches any allow pattern -> permit
     (deny list is never consulted)
  2. allow-list non-empty + no match + empty deny list -> refuse
  3. otherwise fall through to the deny check; deny match -> refuse,
     no match -> permit

The GHSA-rjfm-3w2m-jf4f fail-closed guard stays on the deny path. The
guard refuses peers with unresolved hostnames only when at least one
deny rule is hostname-based; a peer that has already won the allow
short-circuit is admitted regardless of DNS state, which matches
upstream's behaviour and avoids false rejection of perfectly-allowed
peers in chroot configurations.

Tests:
- `module_definition_allow_match_short_circuits_deny` and
  `module_definition_deny_applies_when_allow_does_not_match` replace the
  bogus `deny_takes_precedence_over_allow` expectation in the
  module_state unit tests.
- `module_definition_allow_short_circuit_skips_dns_fail_closed_guard`
  pins the interaction with the GHSA-rjfm-3w2m-jf4f guard.
- `module_definition_matches_upstream_rsync_fns_allow_list` reproduces
  the upstream testsuite's standard `hosts allow = localhost
  127.0.0.0/24 192.168.0.0/16 10.0.0.0/8 $hostname` configuration from
  `testsuite/rsync.fns:381` and pins CIDR matching against it.
- Updates `module_definition_ipv4_allow_deny_precedence`,
  `module_definition_hostname_deny_takes_precedence`, and
  `module_definition_mixed_ip_and_hostname_acl` chunks to express the
  upstream semantics they previously contradicted.
- Existing GHSA fail-closed regressions
  (`module_hostname_deny_fails_closed_when_dns_unresolved`,
  `module_ip_deny_unaffected_by_dns_failure`) remain green because the
  guard still fires on the deny path when the allow list does not match.
@github-actions github-actions Bot added the bug Something isn't working label Jun 10, 2026
The regression test expected refusal when a peer matches neither allow nor deny lists, but upstream access.c:281-291 only refuses non-matching peers when no deny list is configured; with a deny list present, fall through allows unmatched peers (access.c:290-291).
oferchen added 3 commits June 10, 2026 11:13
The chunk-file copy of module_definition_ipv4_allow_short_circuits_deny
in tests/chunks/ still encoded the pre-upstream 'allow-list non-match
refuses' assertion that the module_state unit tests already corrected.
With both an allow list and a deny list set, upstream allow_access
(access.c:287-291) refuses only on a positive deny-list match and
otherwise falls through to 'Allow all other access'. A peer outside
both subnets is therefore admitted, not refused.

Flip the third assertion to permits(...) and reference the upstream
line range. Brings the chunk into sync with module_state/tests.rs and
the new permits() implementation so Windows feature-flag combinations
and Linux musl (beta) stop tripping the assertion.
@oferchen
oferchen merged commit 292786d into master Jun 10, 2026
69 checks passed
@oferchen
oferchen deleted the fix/uts-3-daemon-access branch June 11, 2026 03:12
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix: align hosts allow/deny with upstream allow_access semantics

upstream rsync's `access.c::allow_access()` short-circuits on the first
allow-list match and returns 1 unconditionally - "If we match an allow-
list item, we always allow access." The deny list is consulted only when
the allow list is absent or did not match. oc-rsync's
`ModuleDefinition::permits` instead evaluated allow then deny in series,
so a peer that matched both an allow and a deny pattern was refused.
That divergence breaks any daemon config that uses an inclusive
`hosts allow = *` together with surgical hostname-pattern deny rules,
and silently rejects connections the upstream testsuite expects to be
accepted.

Reorder `permits` to match `access.c:264` exactly:

  1. allow-list non-empty + peer matches any allow pattern -> permit
     (deny list is never consulted)
  2. allow-list non-empty + no match + empty deny list -> refuse
  3. otherwise fall through to the deny check; deny match -> refuse,
     no match -> permit

The GHSA-rjfm-3w2m-jf4f fail-closed guard stays on the deny path. The
guard refuses peers with unresolved hostnames only when at least one
deny rule is hostname-based; a peer that has already won the allow
short-circuit is admitted regardless of DNS state, which matches
upstream's behaviour and avoids false rejection of perfectly-allowed
peers in chroot configurations.

Tests:
- `module_definition_allow_match_short_circuits_deny` and
  `module_definition_deny_applies_when_allow_does_not_match` replace the
  bogus `deny_takes_precedence_over_allow` expectation in the
  module_state unit tests.
- `module_definition_allow_short_circuit_skips_dns_fail_closed_guard`
  pins the interaction with the GHSA-rjfm-3w2m-jf4f guard.
- `module_definition_matches_upstream_rsync_fns_allow_list` reproduces
  the upstream testsuite's standard `hosts allow = localhost
  127.0.0.0/24 192.168.0.0/16 10.0.0.0/8 $hostname` configuration from
  `testsuite/rsync.fns:381` and pins CIDR matching against it.
- Updates `module_definition_ipv4_allow_deny_precedence`,
  `module_definition_hostname_deny_takes_precedence`, and
  `module_definition_mixed_ip_and_hostname_acl` chunks to express the
  upstream semantics they previously contradicted.
- Existing GHSA fail-closed regressions
  (`module_hostname_deny_fails_closed_when_dns_unresolved`,
  `module_ip_deny_unaffected_by_dns_failure`) remain green because the
  guard still fires on the deny path when the allow list does not match.

* test: align deny-fallthrough test with upstream access.c semantics

The regression test expected refusal when a peer matches neither allow nor deny lists, but upstream access.c:281-291 only refuses non-matching peers when no deny list is configured; with a deny list present, fall through allows unmatched peers (access.c:290-291).

* test: align ipv4 allow/deny chunk test with upstream access.c

The chunk-file copy of module_definition_ipv4_allow_short_circuits_deny
in tests/chunks/ still encoded the pre-upstream 'allow-list non-match
refuses' assertion that the module_state unit tests already corrected.
With both an allow list and a deny list set, upstream allow_access
(access.c:287-291) refuses only on a positive deny-list match and
otherwise falls through to 'Allow all other access'. A peer outside
both subnets is therefore admitted, not refused.

Flip the third assertion to permits(...) and reference the upstream
line range. Brings the chunk into sync with module_state/tests.rs and
the new permits() implementation so Windows feature-flag combinations
and Linux musl (beta) stop tripping the assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant