Skip to content

fix: reject wrong-typed optional action params - #701

Merged
vladimirrott merged 4 commits into
lacs-project:mainfrom
dannyward630:fix/issue-668-param-validation
Nov 3, 2026
Merged

vladimirrott merged 4 commits into
lacs-project:mainfrom
dannyward630:fix/issue-668-param-validation

Conversation

@dannyward630

@dannyward630 dannyward630 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rejects present optional action parameters with the wrong JSON type while preserving the established meaning of null as absent. Optional strings, numbers, booleans, and arrays now treat null consistently; GrubSetKargs and ResolvectlSetDns use the shared string-array reader, while ObtainCertificate retains its null-aware optional array so a single domain can be used as a fallback.

Related issue

Closes #668

Validation

  • Tests cover null-as-absent, wrong-typed numeric/boolean/string/array inputs, mixed-type certificate domains, and a string SetAptPin.priority.
  • Security impact considered: malformed values are rejected before an action spec is built.
  • Trust boundary preserved: the daemon remains the only privileged executor.
  • Rebased onto current main, preserving fix: security fixes for 0.28.0 #703's log-rotation path validation; updated the workspace test baseline to 2,093.
  • git diff --check — passed.
  • All commits carry the required DCO sign-off.
  • All required GitHub Actions checks pass at fc22892a; container-smoke is skipped as configured.

Assisted by Codex (GPT-6).

Notes for Reviewers

Null remains equivalent to omission for optional action parameters, matching existing request behavior. A null domains value falls through to the single domain form for ObtainCertificate.

@dannyward630

Copy link
Copy Markdown
Contributor Author

The first Linux CI run caught a borrow mismatch in the certificate-domain conversion. I fixed it in 01f3826; the new run is underway.

@dannyward630
dannyward630 marked this pull request as ready for review October 29, 2026 00:31

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at d4c15c34.

Thanks, Danny. You went past the issue's list in the right places: besides the numeric and boolean sites #668 listed, you converted every loose optional string and array read in build_action_spec, and you moved the domain read above the if let, so a wrong-typed domain gets refused even when domains wins. The {"domains": [...], "domain": 42} row pins that case.

I ran clippy and the suite in a no-network container at d4c15c34 (2,007 tests plus the 15 GUI ones gives your 2,022), then put each converted read back to its old .and_then(|v| v.as_*()) form, one at a time. 35 of the 36 sites went red, each on its own row, and so did the optional_validated helper and the all-at-once revert.

One decision first, and it's mine to make: null. Your tables assert that "min_days": null gets refused. On main a null optional reads as absent, and str_array_or_empty still says so in its doc comment, so after this PR SetKernelArguments {"remove": null} passes while GrubSetKargs {"delete": null} fails. ObtainCertificate settles it for me: it takes domains or domain, and a client that fills its schema with "domains": null, "domain": "example.com" worked before and would now get InvalidParam("domains"). The operator approved a preview showing null, and applying nothing for that key matches what they saw. So I'd like null to mean absent for optional params: None | Some(Value::Null) => Ok(None) in the helpers, json!(null) out of the two invalid lists, and GrubSetKargs and ResolvectlSetDns can call the existing str_array_or_empty, which leaves optional_str_array for ObtainCertificate alone. Strings, negatives and floats keep failing, and those are the #668 bug.

While you're in there, the mutants found three behaviours that no test covers. The old code had no test for them either, so none of this is a regression of yours:

  • ObtainCertificate {"domains": ["example.com", 42]} should give InvalidParam("domains"). Main refused it too; swapping optional_str_array for a filter_map passes all 1,152 daemon tests. This is the row I'd add.
  • GrubSetKargs {"append": "quiet"}, a string where an array goes, now gives InvalidParam("append"). Your change fixed that, and a row would keep it fixed.
  • SetAptPin {"priority": "500"} gives InvalidParam("priority"). Optional; the action fails either way.

#703 landed on main while this was open and touches executor.rs next to you in two places: ConfigureLogRotation now validates path after rotate, and #703 rewrote the kernel-argument doc comment below str_array_or_empty. Keep #703's let path = validated_log_rotation(...) line above your compress line, and put your optional_str_array above #703's new comment. The test count on the merge comes to 2,093. That conflict comes from my side, so if you'd rather not touch it, say so and I'll resolve it when I merge.

@vladimirrott

Copy link
Copy Markdown
Member

The sign-off note on #698 applies here too: the same three commands, run from this branch, clear the dco check.

@dannyward630
dannyward630 force-pushed the fix/issue-668-param-validation branch from d4c15c3 to fc22892 Compare October 29, 2026 17:34

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at fc22892a. Approved.

Thanks, Danny. You took the null decision the way I asked and pinned it from both sides: each table now asserts that null reads as absent before it asserts that the wrong types fail. The ResolvectlSetDns special case is right too, since a null servers should still end in MissingParam("servers"). All three rows I listed are in, and the rebase onto #703 kept its validated_log_rotation line and its kernel-argument comment where they belong.

I ran the daemon's executor tests in a no-network container at fc22892a (cargo test -p sysknife-daemon --lib --offline --locked executor::tests, 114 tests), then took the Some(Value::Null) arm out of each helper in turn:

helper without the null arm first failing assertion
optional_str InstallFlatpak.remote must treat null as absent
optional_bool GetJournalLog.boot must treat null as absent
optional_u64 GetJournalLog.lines must treat null as absent
optional_i64 SetPasswordPolicy.dcredit must treat null as absent
optional_str_array ObtainCertificate.domains must treat null as absent
str_array_or_empty GrubSetKargs.append must treat null as absent

Each mutant fails on its own row. One other test, a_child_that_outlives_a_stdout_read_failure_is_stopped_not_orphaned, failed in every run, the unmutated one included. It fails the same way on main at 093436f0 in that container, it passes in CI, and your diff does not touch it, so it is my sandbox's problem and not yours. The test count moves from 2,091 to 2,093 with your two new tests, which matches workspace-tests.json.

Like #698 and #700, the branch is one commit behind main (the 0.29.0 release, version bumps only, no conflict). Once you rebase and the checks go green, I'll merge, provided the push changes nothing beyond the rebase. I'll write the CHANGELOG line then.

@vladimirrott

Copy link
Copy Markdown
Member

This is approved at fc22892a and ready to land. Main has moved by two commits since then (the 0.29.0 release and #709), neither touches executor.rs, and the branch merges cleanly. The fork doesn't allow maintainer edits, so I can't update it from my side. Could you rebase and force-push?

git fetch upstream && git rebase --signoff upstream/main && git push --force-with-lease

I'll merge as soon as CI is green on the new head.

@dannyward630
dannyward630 force-pushed the fix/issue-668-param-validation branch from fc22892 to 86a55be Compare October 30, 2026 19:08
@dannyward630

Copy link
Copy Markdown
Contributor Author

Rebased onto current main with git rebase --signoff and pushed with --force-with-lease. git range-diff confirms the four approved commits are unchanged apart from the rebase. The new head 86a55be7 is green: 14 checks passed, container-smoke skipped, and GitHub reports no conflicts. Thanks for the review. Assisted by Codex (GPT-6).

@vladimirrott
vladimirrott merged commit d221719 into lacs-project:main Nov 3, 2026
15 checks passed
vladimirrott added a commit to jabrailkhalil/sysknife that referenced this pull request Nov 3, 2026
Resolve the test baseline after lacs-project#701: main is at 2093 with lacs-project#701's two
tests, and this branch adds two more, so the count is 2095. Both sides
edited 2091 to 2093 identically, so git merged them silently to 2093.

Signed-off-by: Vladimir Rotariu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
vladimirrott added a commit to inmassat/sysknife that referenced this pull request Nov 3, 2026
Refresh the Rust test baseline: main is at 2095 after lacs-project#701 and lacs-project#695, and
this branch adds five tests, so 2100. Move async-trait below the
sysknife-daemon comment in the CLI's dev-dependencies, where it split
that comment from the line it describes.

Signed-off-by: Vladimir Rotariu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
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.

The daemon drops optional params of the wrong type, so a plan applies partly and reports success

2 participants