Skip to content

Add daemon hosts allow/deny enforcement for module access - #829

Merged
oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync
Oct 21, 2025
Merged

oferchen merged 1 commit into
masterfrom
implement-missing-components-for-oc-rsync

Conversation

@oferchen

@oferchen oferchen commented Oct 21, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • enforce daemon module hosts allow/hosts deny directives when responding to legacy clients
  • parse host access directives from config files and CLI modules, filtering #list output accordingly
  • add regression tests covering access control enforcement and configuration parsing

Testing

  • cargo test

@oferchen
oferchen merged commit 7f4087c into master Oct 21, 2025
@oferchen
oferchen deleted the implement-missing-components-for-oc-rsync branch October 21, 2025 17:52
oferchen added a commit that referenced this pull request Jun 12, 2026
…REOPEN)

Lock the round-trip parity between the client-side option-arg escape
emitted by `safe_arg_for_daemon` and the daemon-side `unbackslash_arg`
un-escape. Mirrors upstream `options.c:2539-2594` (rsync 3.4.4
`safe_arg`) and `io.c:1295-1306` (`unbackslash_arg`).

The asymmetric case is `--groupmap=*:GID` (upstream issue #829): a
3.4.3+ non-protect_args client wraps the value with
`safe_arg("--groupmap", value)`, which backslash-escapes `*` because
it is a member of `WILD_CHARS`. The daemon must reverse the escape
before option parsing or `--groupmap=\*:GID` reaches
`parse_name_map()` and the wildcard silently mismatches.

The existing implementation is already symmetric, but had no
character-level coverage of the escape set. Adds:

- `crates/core/.../arguments.rs`: pin the byte-for-byte form
  `safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"`,
  plus a round-trip test that covers every `WILD_CHARS + SHELL_CHARS`
  escape character (`*?[]!#$&;|<>(){}\"'` \t\\`).
- `crates/daemon/.../tests.rs`: ground-truth port of upstream
  `safe_arg` (option-arg branch) used to assert that
  `unbackslash_arg(upstream_safe_arg("--groupmap", value)) == value`
  for the wildcard, every escape character, and the
  `--usermap`/`--groupmap` wildcard family.

The ground-truth `safe_arg` helper in the daemon test module is
independent of the oc-rsync `safe_arg_for_daemon` implementation so
the contract is locked against upstream wire output rather than
against our own escape code.

No behaviour change; defense-in-depth coverage that pins the daemon
arg backslash contract against URV-2.a regression. Production
non-protect_args round-trip remains exercised by the
secluded-args-default code path that already covers the wire layer.

upstream: options.c:2539-2594 safe_arg() (client-side escape)
upstream: io.c:1295-1306 unbackslash_arg() (daemon-side un-escape)
upstream: options.c:2912-2916 safe_arg("--usermap"|"--groupmap", value)
oferchen added a commit that referenced this pull request Jun 12, 2026
…REOPEN) (#5727)

Lock the round-trip parity between the client-side option-arg escape
emitted by `safe_arg_for_daemon` and the daemon-side `unbackslash_arg`
un-escape. Mirrors upstream `options.c:2539-2594` (rsync 3.4.4
`safe_arg`) and `io.c:1295-1306` (`unbackslash_arg`).

The asymmetric case is `--groupmap=*:GID` (upstream issue #829): a
3.4.3+ non-protect_args client wraps the value with
`safe_arg("--groupmap", value)`, which backslash-escapes `*` because
it is a member of `WILD_CHARS`. The daemon must reverse the escape
before option parsing or `--groupmap=\*:GID` reaches
`parse_name_map()` and the wildcard silently mismatches.

The existing implementation is already symmetric, but had no
character-level coverage of the escape set. Adds:

- `crates/core/.../arguments.rs`: pin the byte-for-byte form
  `safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"`,
  plus a round-trip test that covers every `WILD_CHARS + SHELL_CHARS`
  escape character (`*?[]!#$&;|<>(){}\"'` \t\\`).
- `crates/daemon/.../tests.rs`: ground-truth port of upstream
  `safe_arg` (option-arg branch) used to assert that
  `unbackslash_arg(upstream_safe_arg("--groupmap", value)) == value`
  for the wildcard, every escape character, and the
  `--usermap`/`--groupmap` wildcard family.

The ground-truth `safe_arg` helper in the daemon test module is
independent of the oc-rsync `safe_arg_for_daemon` implementation so
the contract is locked against upstream wire output rather than
against our own escape code.

No behaviour change; defense-in-depth coverage that pins the daemon
arg backslash contract against URV-2.a regression. Production
non-protect_args round-trip remains exercised by the
secluded-args-default code path that already covers the wire layer.

upstream: options.c:2539-2594 safe_arg() (client-side escape)
upstream: io.c:1295-1306 unbackslash_arg() (daemon-side un-escape)
upstream: options.c:2912-2916 safe_arg("--usermap"|"--groupmap", value)
oferchen added a commit that referenced this pull request Jun 12, 2026
…d-args (#5736)

* fix(daemon): merge phase-1 cmdline + phase-2 stdin args under secluded-args

Under secluded-args mode upstream rsync splits the daemon argv at the
NULL it injects at options.c:2745: phase 1 (cmdline) carries `--server`,
`--sender`, the compact flag string (`-slogDtprIzxe.iLsfxCIvu`) and
`--iconv=...`; phase 2 (stdin via `send_protected_args`) carries every
long-form option (`--list-only`, `--log-format`, `--usermap`,
`--groupmap`, ...), the `.` separator and the positional paths.

Upstream re-runs `parse_arguments()` against each phase so the popt
globals carry the union forward (clientserver.c:1073,1083). The daemon
was discarding phase 1 entirely and parsing only phase 2, so the
compact flag string, `--sender`, and `--iconv` never reached
`ServerConfig`. Compression / recursion / role negotiation diverged
before the transfer started, explaining the early connection drop on
the `daemon-groupmap-wild` secluded-args case (upstream issue #829):
the wildcard groupmap was parsed correctly but the missing `-z` from
phase 1 broke the protocol handshake.

The fix concatenates the two phases (dropping the synthetic `"rsync"`
arg0 upstream rewrites into the NULL slot) and feeds the merged list
through the same single-pass option parser. No unbackslash pass is
needed on either phase: `safe_arg()` skips the WILD_CHARS escape when
`protect_args` is set (options.c:2551), so phase 2 args - including
`--groupmap=*:GID` - arrive verbatim.

upstream: clientserver.c:1059-1086 two-phase read_args() + parse_arguments()
upstream: options.c:2614-2745 server_options() placement of `--server`,
  `--sender`, argstr and the secluded-args NULL split point
upstream: rsync.c:283-320 send_protected_args() NULL/arg0 rewrite

* style(daemon): take phase2 by mut value in merge_secluded_args

Replace the shadow `let mut phase2 = phase2` with `mut phase2: Vec<String>`
in the parameter list to drop a redundant statement.
oferchen added a commit that referenced this pull request Jun 14, 2026
…s path

Under secluded-args daemon push, the client's phase 1 wire was
`--server [--sender] -s .` - both the trailing `.` and the bare `-s`
diverge from upstream's `clientserver.c:395-402` wire layout. Upstream's
phase 1 never contains a standalone `.` (that token only enters `sargs`
in `do_cmd` at `clientserver.c:303` AFTER `server_options()` inserts the
phase 1 / phase 2 split NULL at `options.c:2745`), and never contains a
bare `-s` (the `s` for `--secluded-args` is embedded in the compact flag
string `argstr` at `options.c:2622-2623`).

The stray phase 1 `.` short-circuited the daemon's `apply_long_form_args`
dot_position lookup (it picks the FIRST standalone `.` as the boundary
between option region and positional file args). Every option after the
phase 1 / phase 2 merge boundary - including `--groupmap=*:GID` - was
silently dropped before reaching `GroupMapping::parse`, so the wildcard
match rule was never installed on the receiver. Upstream regression
#829 / `daemon-groupmap-wild` (`[secluded-args] groupmap upload failed
(rc=12) + connection unexpectedly closed (23 bytes received) [sender]`).

The bare `-s` also shadowed phase 2's real compact flag string in
`build_server_config`'s first-short-form-arg picker, so compression /
recursion / capability negotiation broke before the transfer started.

Emit phase 1 as `--server [--sender] --secluded-args` instead. The
long-form alias is in the daemon's `has_secluded_args_flag` detection
set (`-s` | `--protect-args` | `--secluded-args`), so phase 2 reading
still trips. Upstream daemons accept `--secluded-args` per
`options.c:804` (`{"secluded-args", 's', POPT_ARG_VAL, ...}`), so this
remains wire-compatible with upstream rsync.

Adds character-level coverage on both ends of the wire:
- `crates/core/.../orchestration/tests.rs` pins that
  `build_minimal_daemon_args` emits neither a standalone `.` nor a bare
  `-s` for both push and pull, and that phase 1 is exactly
  `[--server, [--sender], --secluded-args]`.
- `crates/daemon/.../module_access/tests.rs` pins that the merged arg
  list from the new phase 1 + a representative phase 2 round-trips
  `--groupmap=*:4242` through `apply_long_form_args` to
  `GroupMapping::parse`, and that the real compact flag string
  (`-logDtprIze.LsfxCIvu`) is the first short-form arg in the merged
  list - locking against a future regression that would reintroduce the
  bare-`-s` shadow.

upstream: clientserver.c:303 - `sargs[sargc++] = "."` after server_options()
upstream: clientserver.c:395-402 - phase 1 wire writes args until !sargs[i]
upstream: options.c:2622-2623 - `argstr[x++] = 's'` when `protect_args`
upstream: options.c:2744-2745 - NULL marker between phase 1 / phase 2 args
upstream: options.c:804 - `--secluded-args` long-form alias for `-s`
oferchen added a commit that referenced this pull request Jun 14, 2026
…s path (#5752)

Under secluded-args daemon push, the client's phase 1 wire was
`--server [--sender] -s .` - both the trailing `.` and the bare `-s`
diverge from upstream's `clientserver.c:395-402` wire layout. Upstream's
phase 1 never contains a standalone `.` (that token only enters `sargs`
in `do_cmd` at `clientserver.c:303` AFTER `server_options()` inserts the
phase 1 / phase 2 split NULL at `options.c:2745`), and never contains a
bare `-s` (the `s` for `--secluded-args` is embedded in the compact flag
string `argstr` at `options.c:2622-2623`).

The stray phase 1 `.` short-circuited the daemon's `apply_long_form_args`
dot_position lookup (it picks the FIRST standalone `.` as the boundary
between option region and positional file args). Every option after the
phase 1 / phase 2 merge boundary - including `--groupmap=*:GID` - was
silently dropped before reaching `GroupMapping::parse`, so the wildcard
match rule was never installed on the receiver. Upstream regression
#829 / `daemon-groupmap-wild` (`[secluded-args] groupmap upload failed
(rc=12) + connection unexpectedly closed (23 bytes received) [sender]`).

The bare `-s` also shadowed phase 2's real compact flag string in
`build_server_config`'s first-short-form-arg picker, so compression /
recursion / capability negotiation broke before the transfer started.

Emit phase 1 as `--server [--sender] --secluded-args` instead. The
long-form alias is in the daemon's `has_secluded_args_flag` detection
set (`-s` | `--protect-args` | `--secluded-args`), so phase 2 reading
still trips. Upstream daemons accept `--secluded-args` per
`options.c:804` (`{"secluded-args", 's', POPT_ARG_VAL, ...}`), so this
remains wire-compatible with upstream rsync.

Adds character-level coverage on both ends of the wire:
- `crates/core/.../orchestration/tests.rs` pins that
  `build_minimal_daemon_args` emits neither a standalone `.` nor a bare
  `-s` for both push and pull, and that phase 1 is exactly
  `[--server, [--sender], --secluded-args]`.
- `crates/daemon/.../module_access/tests.rs` pins that the merged arg
  list from the new phase 1 + a representative phase 2 round-trips
  `--groupmap=*:4242` through `apply_long_form_args` to
  `GroupMapping::parse`, and that the real compact flag string
  (`-logDtprIze.LsfxCIvu`) is the first short-form arg in the merged
  list - locking against a future regression that would reintroduce the
  bare-`-s` shadow.

upstream: clientserver.c:303 - `sargs[sargc++] = "."` after server_options()
upstream: clientserver.c:395-402 - phase 1 wire writes args until !sargs[i]
upstream: options.c:2622-2623 - `argstr[x++] = 's'` when `protect_args`
upstream: options.c:2744-2745 - NULL marker between phase 1 / phase 2 args
upstream: options.c:804 - `--secluded-args` long-form alias for `-s`
oferchen added a commit that referenced this pull request Aug 24, 2026
…REOPEN) (#5727)

Lock the round-trip parity between the client-side option-arg escape
emitted by `safe_arg_for_daemon` and the daemon-side `unbackslash_arg`
un-escape. Mirrors upstream `options.c:2539-2594` (rsync 3.4.4
`safe_arg`) and `io.c:1295-1306` (`unbackslash_arg`).

The asymmetric case is `--groupmap=*:GID` (upstream issue #829): a
3.4.3+ non-protect_args client wraps the value with
`safe_arg("--groupmap", value)`, which backslash-escapes `*` because
it is a member of `WILD_CHARS`. The daemon must reverse the escape
before option parsing or `--groupmap=\*:GID` reaches
`parse_name_map()` and the wildcard silently mismatches.

The existing implementation is already symmetric, but had no
character-level coverage of the escape set. Adds:

- `crates/core/.../arguments.rs`: pin the byte-for-byte form
  `safe_arg_for_daemon("--groupmap=*:42") == "--groupmap=\*:42"`,
  plus a round-trip test that covers every `WILD_CHARS + SHELL_CHARS`
  escape character (`*?[]!#$&;|<>(){}\"'` \t\\`).
- `crates/daemon/.../tests.rs`: ground-truth port of upstream
  `safe_arg` (option-arg branch) used to assert that
  `unbackslash_arg(upstream_safe_arg("--groupmap", value)) == value`
  for the wildcard, every escape character, and the
  `--usermap`/`--groupmap` wildcard family.

The ground-truth `safe_arg` helper in the daemon test module is
independent of the oc-rsync `safe_arg_for_daemon` implementation so
the contract is locked against upstream wire output rather than
against our own escape code.

No behaviour change; defense-in-depth coverage that pins the daemon
arg backslash contract against URV-2.a regression. Production
non-protect_args round-trip remains exercised by the
secluded-args-default code path that already covers the wire layer.

upstream: options.c:2539-2594 safe_arg() (client-side escape)
upstream: io.c:1295-1306 unbackslash_arg() (daemon-side un-escape)
upstream: options.c:2912-2916 safe_arg("--usermap"|"--groupmap", value)
oferchen added a commit that referenced this pull request Aug 24, 2026
…d-args (#5736)

* fix(daemon): merge phase-1 cmdline + phase-2 stdin args under secluded-args

Under secluded-args mode upstream rsync splits the daemon argv at the
NULL it injects at options.c:2745: phase 1 (cmdline) carries `--server`,
`--sender`, the compact flag string (`-slogDtprIzxe.iLsfxCIvu`) and
`--iconv=...`; phase 2 (stdin via `send_protected_args`) carries every
long-form option (`--list-only`, `--log-format`, `--usermap`,
`--groupmap`, ...), the `.` separator and the positional paths.

Upstream re-runs `parse_arguments()` against each phase so the popt
globals carry the union forward (clientserver.c:1073,1083). The daemon
was discarding phase 1 entirely and parsing only phase 2, so the
compact flag string, `--sender`, and `--iconv` never reached
`ServerConfig`. Compression / recursion / role negotiation diverged
before the transfer started, explaining the early connection drop on
the `daemon-groupmap-wild` secluded-args case (upstream issue #829):
the wildcard groupmap was parsed correctly but the missing `-z` from
phase 1 broke the protocol handshake.

The fix concatenates the two phases (dropping the synthetic `"rsync"`
arg0 upstream rewrites into the NULL slot) and feeds the merged list
through the same single-pass option parser. No unbackslash pass is
needed on either phase: `safe_arg()` skips the WILD_CHARS escape when
`protect_args` is set (options.c:2551), so phase 2 args - including
`--groupmap=*:GID` - arrive verbatim.

upstream: clientserver.c:1059-1086 two-phase read_args() + parse_arguments()
upstream: options.c:2614-2745 server_options() placement of `--server`,
  `--sender`, argstr and the secluded-args NULL split point
upstream: rsync.c:283-320 send_protected_args() NULL/arg0 rewrite

* style(daemon): take phase2 by mut value in merge_secluded_args

Replace the shadow `let mut phase2 = phase2` with `mut phase2: Vec<String>`
in the parameter list to drop a redundant statement.
oferchen added a commit that referenced this pull request Aug 24, 2026
…s path (#5752)

Under secluded-args daemon push, the client's phase 1 wire was
`--server [--sender] -s .` - both the trailing `.` and the bare `-s`
diverge from upstream's `clientserver.c:395-402` wire layout. Upstream's
phase 1 never contains a standalone `.` (that token only enters `sargs`
in `do_cmd` at `clientserver.c:303` AFTER `server_options()` inserts the
phase 1 / phase 2 split NULL at `options.c:2745`), and never contains a
bare `-s` (the `s` for `--secluded-args` is embedded in the compact flag
string `argstr` at `options.c:2622-2623`).

The stray phase 1 `.` short-circuited the daemon's `apply_long_form_args`
dot_position lookup (it picks the FIRST standalone `.` as the boundary
between option region and positional file args). Every option after the
phase 1 / phase 2 merge boundary - including `--groupmap=*:GID` - was
silently dropped before reaching `GroupMapping::parse`, so the wildcard
match rule was never installed on the receiver. Upstream regression
#829 / `daemon-groupmap-wild` (`[secluded-args] groupmap upload failed
(rc=12) + connection unexpectedly closed (23 bytes received) [sender]`).

The bare `-s` also shadowed phase 2's real compact flag string in
`build_server_config`'s first-short-form-arg picker, so compression /
recursion / capability negotiation broke before the transfer started.

Emit phase 1 as `--server [--sender] --secluded-args` instead. The
long-form alias is in the daemon's `has_secluded_args_flag` detection
set (`-s` | `--protect-args` | `--secluded-args`), so phase 2 reading
still trips. Upstream daemons accept `--secluded-args` per
`options.c:804` (`{"secluded-args", 's', POPT_ARG_VAL, ...}`), so this
remains wire-compatible with upstream rsync.

Adds character-level coverage on both ends of the wire:
- `crates/core/.../orchestration/tests.rs` pins that
  `build_minimal_daemon_args` emits neither a standalone `.` nor a bare
  `-s` for both push and pull, and that phase 1 is exactly
  `[--server, [--sender], --secluded-args]`.
- `crates/daemon/.../module_access/tests.rs` pins that the merged arg
  list from the new phase 1 + a representative phase 2 round-trips
  `--groupmap=*:4242` through `apply_long_form_args` to
  `GroupMapping::parse`, and that the real compact flag string
  (`-logDtprIze.LsfxCIvu`) is the first short-form arg in the merged
  list - locking against a future regression that would reintroduce the
  bare-`-s` shadow.

upstream: clientserver.c:303 - `sargs[sargc++] = "."` after server_options()
upstream: clientserver.c:395-402 - phase 1 wire writes args until !sargs[i]
upstream: options.c:2622-2623 - `argstr[x++] = 's'` when `protect_args`
upstream: options.c:2744-2745 - NULL marker between phase 1 / phase 2 args
upstream: options.c:804 - `--secluded-args` long-form alias for `-s`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant