Skip to content

Harden configuration lint boundaries - #307

Draft
leynos wants to merge 1 commit into
harden-lint-modules-20260924from
harden-lint-weaver-config-20260924
Draft

leynos wants to merge 1 commit into
harden-lint-modules-20260924from
harden-lint-weaver-config-20260924

Conversation

@leynos

@leynos leynos commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

This branch removes unsafe configuration-test environment mutation, uses safe effective-user ID access, and makes parsing and path preparation compatible with the selected Rust lint baseline. It follows module-structure PR #306 in the stack. Final lint enforcement remains in a later layer.

Review walkthrough

Validation

  • The eight existing Make gates passed sequentially: make check-fmt, make spelling, make lint, make typecheck, make test, make markdownlint, make nixie, and make test-workflow-contracts. The full suite passed 1,585 tests with four skipped; 187 workflow contracts passed.
  • In an isolated scratch checkout with temporary final-policy settings, weaver-config passed Clippy across all targets and features, strict docsrs rustdoc, and Whitaker. The configuration-precedence test also passed with external WEAVER_* variables set.
  • Independent static review found no substantive issue. The committed diff contains 12 files and no fixture or generated-configuration churn.

Notes

The full-workspace temporary-policy Clippy probe still reports five std::env method violations: four in weaver-sandbox and one in weaver-build-util. Five dependent packages were not reached, so this is a lower-bound measurement, not a clean estate verdict. Full-workspace strict rustdoc and Whitaker passed. Sandbox and build-util fixes remain assigned to later source waves.

The ancestor stack's hosted CI is blocked at Whitaker installation on Ubuntu 22.04; this PR's current-head CI result will be reported separately when terminal.

References

Summary by Sourcery

Harden weaver-config environment boundaries, Unix identity handling, and lint-compatible parsing and path preparation.

Bug Fixes:

  • Replace unsafe configuration-test environment mutation with scoped environment overrides that isolate configuration inputs and restore external values safely.

Enhancements:

  • Use safe effective-user ID access for runtime and socket ownership handling.
  • Harden configuration and socket path handling against lint-sensitive indexing and path-component cases.
  • Improve public API documentation and annotate suitable configuration accessors and defaults for compile-time and unused-result checks.

Build:

  • Update Unix configuration dependencies from libc to nix and add the scoped test-environment dependency.

Documentation:

  • Add API documentation for configuration, runtime path, socket, parsing, and error-model interfaces.

Tests:

  • Strengthen configuration precedence tests to cover externally contaminated environments without mutating the process environment unsafely.

Replace unsafe test environment mutation with scoped temporary values
and use safe Unix UID access for runtime path ownership. Make parsing,
path preparation, and configuration tests compatible with the selected
lint baseline while preserving existing wire formats and behaviour.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR hardens weaver-config lint boundaries by eliminating unsafe environment mutation from precedence tests, replacing libc effective-UID calls with safe nix APIs, making parsing and test setup more lint-compliant, and strengthening documentation and API annotations without changing runtime security checks.

Sequence diagram for isolated configuration precedence tests

sequenceDiagram
    participant Test as ConfigurationTest
    participant Env as ProcessEnvironment
    participant Config as Config
    participant Composer as MergeComposer

    Test->>Env: set_var / remove_var
    Test->>Config: load_from_iter
    Config->>Composer: push_defaults
    Config->>Composer: push_file
    Config->>Composer: push_environment
    Config->>Composer: push_cli
    Composer-->>Config: merged configuration
    Config-->>Test: OrthoResult<Config>
    Test->>Env: restore scoped environment
Loading

File-Level Changes

Change Details Files
Replace unsafe process-environment mutation in configuration precedence tests with scoped environment overrides.
  • Use temp_env::with_vars to provide discovery, configuration, and test-specific environment values.
  • Explicitly clear relevant variables while preserving externally contaminated WEAVER_* values after the scoped load.
  • Remove the global environment mutex, manual snapshot, unsafe mutation, and restoration guard.
crates/weaver-config/tests/configuration_precedence.rs
crates/weaver-config/Cargo.toml
Cargo.lock
Use safe effective-user ID APIs while preserving runtime and socket security behavior.
  • Replace direct libc::geteuid calls with nix::unistd::Uid::effective().
  • Continue namespacing fallback runtime paths by effective UID.
  • Keep directory ownership, permission, symlink, and traversal checks unchanged in behavior.
crates/weaver-config/src/defaults.rs
crates/weaver-config/src/runtime.rs
crates/weaver-config/src/socket/preparation.rs
crates/weaver-config/Cargo.toml
Cargo.lock
Make configuration parsing and test indexing compatible with the selected lint baseline.
  • Rename intermediate parsing and normalized-key bindings for clarity and use fallible indexing in precedence tests.
  • Avoid potentially panicking direct vector and JSON indexing in test setup.
  • Use clearer fallible conversions and owned-string APIs where required by lint policy.
crates/weaver-config/src/capability.rs
crates/weaver-config/src/lib.rs
crates/weaver-config/tests/configuration_precedence.rs
crates/weaver-config/tests/configuration_failfast.rs
crates/weaver-config/src/socket/mod.rs
crates/weaver-config/src/socket/preparation_tests.rs
crates/weaver-config/src/locale.rs
Expand API and data-model documentation and add lint-oriented annotations.
  • Document public fields, error fields, helper functions, and configuration loading failure cases.
  • Add #[must_use] and const qualifiers to applicable defaults and accessors.
  • Clarify path preparation, endpoint parsing, normalization, and runtime-directory contracts.
crates/weaver-config/src/defaults.rs
crates/weaver-config/src/lib.rs
crates/weaver-config/src/locale.rs
crates/weaver-config/src/runtime.rs
crates/weaver-config/src/socket/mod.rs
crates/weaver-config/src/socket/preparation.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

This branch has not been deployed

No deployments
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.

1 participant