-
-
Notifications
You must be signed in to change notification settings - Fork 267
Add password as fallback to LUKS #1135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,25 +8,26 @@ | |
... | ||
}: | ||
let | ||
passwordFd = | ||
if config.askPassword then | ||
''<(set +x; echo -n "$password"; set -x)'' | ||
else if config.passwordFile != null then | ||
''<(set +x; echo -n "$(cat ${config.passwordFile})"; set -x)'' | ||
else | ||
null; | ||
keyFile = | ||
if config.settings ? "keyFile" then | ||
config.settings.keyFile | ||
else if config.askPassword then | ||
''<(set +x; echo -n "$password"; set -x)'' | ||
else if | ||
config.passwordFile != null | ||
# do not print the password to the console | ||
then | ||
''<(set +x; echo -n "$(cat ${config.passwordFile})"; set -x)'' | ||
else if config.keyFile != null then | ||
lib.warn ( | ||
"The option `keyFile` is deprecated." | ||
+ "Use passwordFile instead if you want to use interactive login or settings.keyFile if you want to use key file login" | ||
) config.keyFile | ||
else | ||
null; | ||
addPasswordAsFallback = keyFile != null && passwordFd != null; | ||
keyFileArgs = '' | ||
${lib.optionalString (keyFile != null) "--key-file ${keyFile}"} \ | ||
--key-file ${if (keyFile != null) then keyFile else passwordFd} \ | ||
${lib.optionalString (lib.hasAttr "keyFileSize" config.settings) "--keyfile-size ${builtins.toString config.settings.keyFileSize}"} \ | ||
${lib.optionalString (lib.hasAttr "keyFileOffset" config.settings) "--keyfile-offset ${builtins.toString config.settings.keyFileOffset}"} \ | ||
''; | ||
|
@@ -165,6 +166,10 @@ in | |
if ! cryptsetup status "${config.name}" >/dev/null; then | ||
${cryptsetupOpen} --persistent | ||
fi | ||
|
||
${lib.optionalString addPasswordAsFallback '' | ||
cryptsetup luksAddKey "${config.device}" ${passwordFd} ${keyFileArgs} | ||
''} | ||
Comment on lines
+170
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: $password may be unset when adding fallback on existing LUKS with askPassword If the device already exists (no format), the earlier prompt isn’t executed, so Minimal fix: prompt only if we’re in the - ${lib.optionalString addPasswordAsFallback ''
- cryptsetup luksAddKey "${config.device}" ${passwordFd} ${keyFileArgs}
- ''}
+ ${lib.optionalString addPasswordAsFallback ''
+ ${lib.optionalString (config.passwordFile == null) ''
+ # Ensure $password is available when askPassword is used outside of format
+ if [ -z ''${password+x} ]; then
+ if [ -z ''${IN_DISKO_TEST+x} ]; then
+ set +x
+ echo "Enter password for ${config.device}"
+ IFS= read -r -s password
+ export password
+ set -x
+ else
+ export password=disko
+ fi
+ fi
+ ''}
+ cryptsetup luksAddKey "${config.device}" ${passwordFd} ${keyFileArgs}
+ ''} Alternative (safer, smaller scope): move the
🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand this remark. The same should apply to R175, adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainYou're absolutely right! Looking at the code more carefully, I can see that both blocks could have the same issue. @Sandarr95 You're absolutely correct, and I apologize for the incomplete analysis. Both blocks use keyFileArgs = ''
--key-file ${if (keyFile != null) then keyFile else passwordFd} \
...
''; So when The issue affects both:
The fix would need to ensure Thank you for catching this - you're right that my initial analysis was incomplete! 🏁 Script executed:
Length of output: 1296 Looking at the script output, I need to correct my analysis. Let me trace through this more carefully: For
For
So you're partially right - The fix should indeed ensure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block is an actual problem though: R191-R201
{
type = "luks";
name = "cryptroot";
settings.keyFile = "/mnt/key";
askPassword = true;
content = { /* ... */ };
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sandarr95 You're absolutely right! That's a critical UX issue. Looking at the mount block, there's indeed an inconsistency: Creation flow: When Mount flow: The password prompt always executes when ${lib.optionalString config.askPassword ''
# This runs even when settings.keyFile exists!
if [ -z ''${IN_DISKO_TEST+x} ]; then
set +x
echo "Enter password for ${config.device}"
IFS= read -r -s password
export password
set -x
else
export password=disko
fi
''}
${cryptsetupOpen} # Uses keyFileArgs which prefers keyFile over passwordFd So in your example config, users would be prompted for a password during mount, but The mount flow should mirror the creation logic: only prompt for password when no This definitely needs fixing for a consistent user experience. |
||
${toString ( | ||
lib.forEach config.additionalKeyFiles (keyFile: '' | ||
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
--key-file
is actually optional. The only way forkeyFile
(in the let binding) to be null is:This seems to be unsupported as
luksFormat
will still try to interactively get a password, which we explicitly tried to avoid withaskPassword = false
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would've technically worked before, where with this change it doesn't. Will add code to handle this case.