Skip to content

Compose sshd_config Match blocks per keyword - #1186

Open
ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:match-block
Open

Compose sshd_config Match blocks per keyword#1186
ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:match-block

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

wolfSSHD_GetUserConf() returned the first matching Match block whole, so a keyword set only in a later matching block was dropped and the result depended on the order blocks appear in the file. OpenSSH resolves one keyword at a time across every applicable block.

  • Each config node tracks in a setMask which keywords it set itself, so an inherited value can be told from one the block named. Compile-time check that no option tag shifts out of the mask.
  • wolfSSHD_GetUserConf() now resolves into a fresh config seeded from the globals; every matching block contributes the keywords no earlier block claimed.
  • The returned config belongs to the caller. wolfsshd.c and the auth paths free it; unit tests compare values, not node identity.
  • Tests: test_GetUserConfMatchOverlapCompose (user matched by both a Match User and a Match Group block, in either order) and sshd_match_overlap_test.sh, the same case against a live daemon. Both fail before the fix.

Issue: ZD-22324

Copilot AI lite review requested due to automatic review settings August 20, 2026 21:29
OpenSSH resolves sshd_config one keyword at a time, scanning every Match
block that applies. wolfSSHD_GetUserConf returns the first matching block
whole, so a setting made only in a later matching block is dropped.

- add test_GetUserConfMatchOverlapCompose, covering a user matched by both
  a Match User and a Match Group block, in either order
- add sshd_match_overlap_test.sh, the same case against a live daemon,
  where the group block's ForceCommand is the setting that goes missing
- both fail until per keyword composition lands, so the unit test runs
  last and the script stays commented out of run_all_sshd_tests.sh
wolfSSHD_GetUserConf returned the first matching Match block whole, so a
keyword named only in a later matching block was dropped and the outcome
depended on the order the blocks were written.

- track in a new setMask which keywords a node set itself, so a value
  inherited from the globals can be told from one the block named, with a
  compile time check that no option tag shifts out of the mask
- resolve into a fresh config seeded from the globals, letting every
  matching block contribute the keywords no earlier block claimed
- the resolved config now belongs to the caller, so wolfsshd and the auth
  paths free it and the tests compare values rather than node identity
- put sshd_match_overlap_test.sh back in the suite

Issue: ZD-22324

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1186

Scan targets checked: wolfssh-bugs, wolfssh-src

No new issues found in the changed files. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants