google / fscrypt

Go tool for managing Linux filesystem encryption
Apache License 2.0
905 stars 99 forks source link

Poor scriptability due to --name not being easily checkable #376

Open nh2 opened 1 year ago

nh2 commented 1 year ago

I'm scripting the creation of some encrypted ext4 folders by calling the fscrypt CLI.

While most of the CLI seems designed for scriptability (prompts can be overridden by passing the information with CLI arguments), an unresolved pain point seems to be key names:

The only workaround seems to be parsing the output of fscrypt status /, which does not look very stable at all.

The bash completion currently does that in this ugly parsing hack:

https://github.com/google/fscrypt/blob/97700817e737eabf45033cdb4a42fa5c6e74f877/cmd/fscrypt/fscrypt_bash_completion#L86-L94


Other parts of fscrypt provide programmatic queries of whether something already exists, e.g. to check whether a dir is already encrypted one can check the status code of fscrypt status, which as per --help

will fail if PATH is not setup for encryption with fscrypt


Some ideas to improve scriptability:

nh2 commented 1 year ago

Another scripting pain point:

fscrypt unlock fails if already unlocked, and provides no way to check if it is.

So one has to resort to brittle stderr parsing for automatic unlocking:

LANG=C fscrypt unlock mydir/ --key secret.key 2>&1 >/dev/null | grep "already unlocked"

if one still wants other unlocking errors to manifest as exit codes.

jamesps-ebi commented 1 year ago

fscrypt unlock fails if already unlocked, and provides no way to check if it is.

+1 for some form of lock/unlock check. Being able to determine if a folder is locked or unlocked would be essential for using fscrypt in more complex scripts.