Make sudo optional for VeraCrypt operations on Linux/macOS - #40
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
sudooptional 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
*nixcommand builders (_create_nix,_mount_nix,_dismount_nix,_custom_nix) hardcodedsudoas the first element of the command. This caused two problems for headless / non-interactive callers such as a consuming steganography tool that uses onlycreate_volume:sudoprefix was an unneeded escalation (least-privilege violation).create_volumefeeds the volume password viasubprocess.run(input=password + "\n"). Whensudoitself needs a password, it consumes that volume password from stdin as its own, and the call fails.Changes
use_sudo: bool = True— whether to prefix*nixcommands withsudo. Passuse_sudo=Falsefor 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— whenuse_sudo=True, invokesudo -nso it never prompts, avoiding the sudo/stdin password collision._privilege_prefix()returning[],["sudo"], or["sudo", "-n"].*nixbuilder 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.0.1.2→0.2.0(pyproject.toml; also corrected the stale__about__.py, which read0.1.0, to0.2.0).use_sudo=False; mounting needs root — keep sudo or run elevated).No changelog file exists in the repo, so none was added.
Testing
_privilege_prefix()in all states, and_create_nix/_mount_nix/_dismount_nix/_custom_nixunder default (sudo),use_sudo=False(no sudo, command starts with the veracrypt path), andsudo_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