Skip to content

fix(cli): implement ./install.sh config --harden flag - #77

Merged
TrezorHannes merged 1 commit into
mainfrom
fix/config-harden-flag
Nov 26, 2026
Merged

TrezorHannes merged 1 commit into
mainfrom
fix/config-harden-flag

Conversation

@TrezorHannes

Copy link
Copy Markdown
Owner

Summary of Changes

Fixes ./install.sh config --harden referenced by ./install.sh doctor when group/world-readable config files are detected:

  • lpt_installer/configs.py: added harden_existing_configs() to enforce 0o600 on existing config files (config.ini, Magma/magma_config.ini, feeConfig.json, wallets.json) and 0o700 on logs/ / data/ without copying missing *.example templates or running full 19-tool validation.
  • lpt_installer/cli.py: added --harden to config subcommand (supports --dry-run and --json).
  • lpt_installer/env.py, docs/CONFIGURATION.md, docs/TROUBLESHOOTING.md: updated doctor remediation hint (./install.sh config --harden) and docs.
  • tests/test_lpt_installer.py: added regression test test_cli_config_harden_tightens_existing_without_copying_templates.

Verification

  • .venv/bin/pytest tests/ -v --cov=... --cov-fail-under=35: 227 passed.
  • .venv/bin/pytest tests/test_lpt_installer.py tests/test_ca_trust_hardening.py --cov=lpt_installer --cov-fail-under=85: 16 passed.
  • Note: Greptile is not enabled / unavailable locally (greptile-guard), so this PR is verified via GitHub Actions CI + TunnelSentinel.

- Add harden_existing_configs() in lpt_installer/configs.py to tighten chmod 0600 on existing config files and 0700 on logs/ and data/ without copying missing *.example templates or validating unrelated tools.
- Wire --harden into ./install.sh config, clarify doctor's suggestion to './install.sh config --harden', and document the flag in docs/CONFIGURATION.md and docs/TROUBLESHOOTING.md.
- Add unit test covering --harden and --harden --dry-run (227/227 passing).
@TrezorHannes TrezorHannes added bug Something isn't working documentation Improvements or additions to documentation python Pull requests that update python code labels Nov 26, 2026
@TrezorHannes TrezorHannes self-assigned this Nov 26, 2026
@tunnelsentinel

Copy link
Copy Markdown

🛡️⚡ TunnelSentinel Code Review

Verdict: APPROVE | Confidence: 5/5 | Risk Tier: LOW
"Zero leaks. Fail-closed verification."


Latest commit: 0e2d088 | Status: success | Reviewed: 2026-11-26 22:21 UTC

Executive Summary

  • Risk Tier: LOW (prod_lines_changed=43, net_lines_changed=90, 3 production files + 2 doc files + 1 test file).
  • Scope Reviewed: Full origin/main...HEAD diff across lpt_installer/configs.py, lpt_installer/cli.py, lpt_installer/env.py, docs/CONFIGURATION.md, docs/TROUBLESHOOTING.md, and tests/test_lpt_installer.py (commit 0e2d0882fbaccd1dc23598258f243fcc3ba84fb1).

Edge-Case & State-Transition Verification

  • harden_existing_configs() (lpt_installer/configs.py): Uses dst.is_file() for CONFIG_TEMPLATES (0o600) and dir_path.is_dir() for logs / data (0o700), safely skipping missing paths, directories, FIFOs, and broken symlinks without copying *.example templates, creating missing directories, or invoking validate_configs().
  • --dry-run & --json (lpt_installer/cli.py): --dry-run reports existing targets in hardened and hardened_dirs without calling os.chmod(), and --json emits structured JSON ({"hardened": [...], "hardened_dirs": [...]}). --harden intentionally short-circuits as a standalone hardening mode before --tools/--edit/validation.
  • doctor & Documentation Alignment (lpt_installer/env.py, docs/CONFIGURATION.md, docs/TROUBLESHOOTING.md): run_doctor() remediation hint updated to ./install.sh config --harden, matching docs/CONFIGURATION.md and docs/TROUBLESHOOTING.md; os.chmod(dst, 0o600) clears the mode & 0o077 check in run_doctor().

Empirical Test Results

  • .venv/bin/pytest tests/ -v --cov=LNDg --cov=Magma --cov=Other --cov=Peerswap --cov=LNBits --cov=lpt_installer --cov-report=term --cov-fail-under=35: 227 passed (48.78% total coverage).
  • .venv/bin/pytest tests/test_lpt_installer.py tests/test_ca_trust_hardening.py --cov=lpt_installer --cov-fail-under=85: 16 passed (88.94% lpt_installer coverage).

Verdict

  • LGTM (5/5 Confidence) — Zero P0/P1 findings.

Review history

  • 0e2d088: APPROVE, 5/5, LOW risk, status success, 2026-11-26 22:21 UTC

@TrezorHannes
TrezorHannes merged commit 6ba26f2 into main Nov 26, 2026
12 checks passed
@TrezorHannes
TrezorHannes deleted the fix/config-harden-flag branch November 26, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant