Bug 263234 - Add support for OpenZFS encryption to adduser
Summary: Add support for OpenZFS encryption to adduser
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Warner Losh
URL: https://github.com/freebsd/freebsd-sr...
Keywords: feature, needs-patch
Depends on:
Blocks:
 
Reported: 2022-04-12 06:02 UTC by Graham Perrin
Modified: 2024-04-18 11:48 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Perrin freebsd_committer freebsd_triage 2022-04-12 06:02:05 UTC
From <https://openzfs.github.io/openzfs-docs/man/8/zfs-load-key.8.html#Encryption>: 

> … Creating an encrypted dataset requires specifying the 
> encryption and keyformat properties at creation time, …

– at, not after. 

If possible, please enhance adduser to allow: 

* specification of the required properties at the time of creation of the 
  file system for the home directory.

adduser(8)
<https://www.freebsd.org/cgi/man.cgi?query=adduser&sektion=8&manpath=FreeBSD>

Note, from <https://www.freebsd.org/cgi/man.cgi?query=passwd&sektion=5&manpath=FreeBSD#BUGS> for passwd(5): 

> User information should (and eventually will) be stored elsewhere. …
Comment 1 John Grafton 2023-10-05 17:06:09 UTC
This is a feature I've wanted myself.  I'll take a crack at it.
Comment 2 John Grafton 2023-10-31 17:56:25 UTC
Pull request: https://github.com/freebsd/freebsd-src/pull/881
Comment 3 Xin LI freebsd_committer freebsd_triage 2023-10-31 19:18:22 UTC
(In reply to John Grafton from comment #2)
This should really be an opt-out feature instead of an opt-in one (in other words, if `zfs list -o name "${homeprefix}" 2>/dev/null` returned a dataset, then ZFS should be used, unless the administrator specified otherwise).

And the ZFS options should be mostly inherited from the parent, especially `mountpoint`.  It can cause a lot of problem when the system is being backed up to a remote one with `zfs send`.  For compression, atime, etc. it's usually specified by the parent instead of being set individually, therefore I'd recommend not providing default for zfs creation options and tell user that they can say encryption=on, etc. if they choose to.
Comment 4 John Grafton 2023-11-02 19:44:42 UTC
(In reply to Xin LI from comment #3)
The PR has been updated to your specification from comment #3.

For the encryption option, my thought is to default to using a passphrase that's asked for at the end of the question list in interactive mode.  In batch mode, the user would need to provide a file with the key?  Haven't decided on the best way to handle this scenario.  Opinions welcome!

These sound like sane defaults to me keeping in mind that the key can always be changed later on with 'zfs change-key'.


Interactive session w/ encryption enabled example:

root@freebsd:/usr/src/usr.sbin/adduser # sh adduser.sh
Username: bob
Full name: bob mcbob
Uid [1009]:
Login group [bob]:
Login group is bob. Invite bob into other groups? []:
Login class [default]:
Shell (sh csh tcsh git-shell nologin) [sh]:
Home directory [/home/bob]:
Home directory permissions (Leave empty for default):
Encrypt ZFS home dataset? [no]: yes
Use password-based authentication? [no]:
Lock out the account after creation? [no]:
Username    : bob
Password    : <disabled>
Full Name   : bob mcbob
Uid         : 1009
ZFS dataset : zroot/home/bob
Encrypted   : yes
Class       :
Groups      : bob
Home        : /home/bob
Home Mode   :
Shell       : /bin/sh
Locked      : no
OK? (yes/no) [yes]: yes
Encryption passphrase for dataset (must be at least 8 characters)
Enter new passphrase:
Re-enter new passphrase:
adduser.sh: INFO: Successfully created ZFS dataset (zroot/home/bob).
adduser.sh: INFO: Successfully added (bob) to the user database.
Add another user? (yes/no) [no]:
Goodbye!
Comment 6 Mateusz Piotrowski freebsd_committer freebsd_triage 2024-04-18 11:47:29 UTC
Ah, sorry, I've mistakenly assigned this PR to imp@ as I thought that it has been resolved (and the patch has been committed by imp@).

Reopening..
Comment 7 Mateusz Piotrowski freebsd_committer freebsd_triage 2024-04-18 11:48:51 UTC
Nevermind, the commit message says:

> Also support ZFS default encryption on user's home directory.

So I guess that this PR can be closed.