Skip to content

Make sudo optional for VeraCrypt operations on Linux/macOS - #40

Merged
srichs merged 1 commit into
mainfrom
claude/veracrypt-optional-sudo-itvn9f
Aug 8, 2026
Merged

Make sudo optional for VeraCrypt operations on Linux/macOS#40
srichs merged 1 commit into
mainfrom
claude/veracrypt-optional-sudo-itvn9f

Conversation

@srichs

@srichs srichs commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

Makes sudo optional for VeraCrypt CLI operations on Linux/macOS so that file-container creation can run with no root and no interactive prompt, while preserving today's behavior for existing callers.

Why

The *nix command builders (_create_nix, _mount_nix, _dismount_nix, _custom_nix) hardcoded sudo as the first element of the command. This caused two problems for headless / non-interactive callers such as a consuming steganography tool that uses only create_volume:

  1. Unnecessary privilege. Creating a file container does not require root — only mounting does — so the sudo prefix was an unneeded escalation (least-privilege violation).
  2. sudo/stdin password collision. create_volume feeds the volume password via subprocess.run(input=password + "\n"). When sudo itself needs a password, it consumes that volume password from stdin as its own, and the call fails.

Changes

  • Two new constructor params (backward-compatible defaults, so existing callers are unaffected):
    • use_sudo: bool = True — whether to prefix *nix commands with sudo. Pass use_sudo=False for least-privilege, non-interactive file-container creation. Mounting/dismounting generally need root, so keep sudo (or run elevated) for those.
    • sudo_non_interactive: bool = False — when use_sudo=True, invoke sudo -n so it never prompts, avoiding the sudo/stdin password collision.
  • New helper _privilege_prefix() returning [], ["sudo"], or ["sudo", "-n"].
  • Every *nix builder now splats *self._privilege_prefix() in place of the literal "sudo", so the command becomes [*self._privilege_prefix(), self.veracrypt_path, ...]. With defaults, output is byte-for-byte identical to before.
  • Version bump 0.1.20.2.0 (pyproject.toml; also corrected the stale __about__.py, which read 0.1.0, to 0.2.0).
  • README gains a "Privileges (Linux/macOS)" section and the class docstring documents both params (file-container creation typically wants use_sudo=False; mounting needs root — keep sudo or run elevated).

No changelog file exists in the repo, so none was added.

Testing

  • Added 9 unit tests: _privilege_prefix() in all states, and _create_nix / _mount_nix / _dismount_nix / _custom_nix under default (sudo), use_sudo=False (no sudo, command starts with the veracrypt path), and sudo_non_interactive=True (sudo -n).
  • pytest: 56 passed (47 existing + 9 new).
  • black --check, isort --check-only, ruff check, mypy: all clean.

Backward compatibility

Defaults (use_sudo=True, sudo_non_interactive=False) reproduce the previous commands exactly; no change for existing callers.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KmtFTMrCghkkNXAkvdXKS2


Generated by Claude Code

File-container creation does not require root, yet the *nix command
builders hardcoded `sudo` as the first argument. Worse, when `sudo`
itself needs a password it consumes the volume password fed via stdin,
breaking headless/non-interactive `create_volume` callers.

Add two constructor params (backward-compatible defaults):
- `use_sudo` (default True): whether to prefix commands with `sudo`.
- `sudo_non_interactive` (default False): use `sudo -n` so it never
  prompts, avoiding the sudo/stdin password collision.

A new `_privilege_prefix()` helper emits `[]`, `["sudo"]`, or
`["sudo", "-n"]`, and every *nix builder (_create_nix, _mount_nix,
_dismount_nix, _custom_nix) now splats it in place of the literal
"sudo". Defaults preserve today's behavior for existing callers.

Bump version to 0.2.0, document the params in the README and
docstrings, and add unit tests covering the prefix helper and each
builder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KmtFTMrCghkkNXAkvdXKS2
@srichs
srichs merged commit ae9ac3c into main Aug 8, 2026
9 checks passed
@srichs
srichs deleted the claude/veracrypt-optional-sudo-itvn9f branch August 8, 2026 21:16
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.

2 participants