mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 03:37:45 +03:00
pam: implement a zfs_key pam module
Implements a pam module for automatically loading zfs encryption keys
for home datasets. The pam module:
- loads a zfs key and mounts the dataset when a session opens.
- unmounts the dataset and unloads the key when the session closes.
- when the user is logged on and changes the password, the module
changes the encryption key.
Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: @jengelh <jengelh@inai.de>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Closes #9886
Closes #9903
This commit is contained in:
@@ -128,6 +128,10 @@ tags = ['functional', 'mmp']
|
||||
tests = ['umount_unlinked_drain']
|
||||
tags = ['functional', 'mount']
|
||||
|
||||
[tests/functional/pam:Linux]
|
||||
tests = ['pam_basic', 'pam_nounmount']
|
||||
tags = ['functional', 'pam']
|
||||
|
||||
[tests/functional/procfs:Linux]
|
||||
tests = ['procfs_list_basic', 'procfs_list_concurrent_readers',
|
||||
'procfs_list_stale_read', 'pool_state']
|
||||
|
||||
@@ -239,6 +239,7 @@ maybe = {
|
||||
'userquota/setup': ['SKIP', exec_reason],
|
||||
'vdev_zaps/vdev_zaps_004_pos': ['FAIL', '6935'],
|
||||
'zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos': ['FAIL', '5848'],
|
||||
'pam/setup': ['SKIP', "pamtester might be not available"],
|
||||
}
|
||||
|
||||
if sys.platform.startswith('freebsd'):
|
||||
|
||||
@@ -61,6 +61,7 @@ export SYSTEM_FILES_COMMON='arp
|
||||
net
|
||||
od
|
||||
openssl
|
||||
pamtester
|
||||
pax
|
||||
pgrep
|
||||
ping
|
||||
|
||||
@@ -46,6 +46,7 @@ SUBDIRS = \
|
||||
no_space \
|
||||
nopwrite \
|
||||
online_offline \
|
||||
pam \
|
||||
persist_l2arc \
|
||||
pool_checkpoint \
|
||||
pool_names \
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/pam
|
||||
dist_pkgdata_SCRIPTS = \
|
||||
setup.ksh \
|
||||
cleanup.ksh \
|
||||
pam_basic.ksh \
|
||||
pam_nounmount.ksh \
|
||||
utilities.kshlib
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/ksh -p
|
||||
#
|
||||
# CDDL HEADER START
|
||||
#
|
||||
# The contents of this file are subject to the terms of the
|
||||
# Common Development and Distribution License (the "License").
|
||||
# You may not use this file except in compliance with the License.
|
||||
#
|
||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
# or http://www.opensolaris.org/os/licensing.
|
||||
# See the License for the specific language governing permissions
|
||||
# and limitations under the License.
|
||||
#
|
||||
# When distributing Covered Code, include this CDDL HEADER in each
|
||||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
# If applicable, add the following below this CDDL HEADER, with the
|
||||
# fields enclosed by brackets "[]" replaced with your own identifying
|
||||
# information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
#
|
||||
# CDDL HEADER END
|
||||
#
|
||||
|
||||
. $STF_SUITE/tests/functional/pam/utilities.kshlib
|
||||
|
||||
destroy_pool $TESTPOOL
|
||||
del_user ${username}
|
||||
del_group pamtestgroup
|
||||
|
||||
rm -rf "$runstatedir"
|
||||
for dir in $TESTDIRS; do
|
||||
rm -rf $dir
|
||||
done
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/ksh -p
|
||||
#
|
||||
# CDDL HEADER START
|
||||
#
|
||||
# The contents of this file are subject to the terms of the
|
||||
# Common Development and Distribution License (the "License").
|
||||
# You may not use this file except in compliance with the License.
|
||||
#
|
||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
# or http://www.opensolaris.org/os/licensing.
|
||||
# See the License for the specific language governing permissions
|
||||
# and limitations under the License.
|
||||
#
|
||||
# When distributing Covered Code, include this CDDL HEADER in each
|
||||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
# If applicable, add the following below this CDDL HEADER, with the
|
||||
# fields enclosed by brackets "[]" replaced with your own identifying
|
||||
# information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
#
|
||||
# CDDL HEADER END
|
||||
#
|
||||
|
||||
. $STF_SUITE/tests/functional/pam/utilities.kshlib
|
||||
|
||||
log_mustnot ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus unavailable
|
||||
|
||||
genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir}"
|
||||
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session
|
||||
references 1
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus available
|
||||
|
||||
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session
|
||||
references 2
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus available
|
||||
|
||||
log_must pamtester pam_zfs_key_test ${username} close_session
|
||||
references 1
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus available
|
||||
|
||||
log_must pamtester pam_zfs_key_test ${username} close_session
|
||||
references 0
|
||||
log_mustnot ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus unavailable
|
||||
|
||||
log_pass "done."
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/ksh -p
|
||||
#
|
||||
# CDDL HEADER START
|
||||
#
|
||||
# The contents of this file are subject to the terms of the
|
||||
# Common Development and Distribution License (the "License").
|
||||
# You may not use this file except in compliance with the License.
|
||||
#
|
||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
# or http://www.opensolaris.org/os/licensing.
|
||||
# See the License for the specific language governing permissions
|
||||
# and limitations under the License.
|
||||
#
|
||||
# When distributing Covered Code, include this CDDL HEADER in each
|
||||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
# If applicable, add the following below this CDDL HEADER, with the
|
||||
# fields enclosed by brackets "[]" replaced with your own identifying
|
||||
# information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
#
|
||||
# CDDL HEADER END
|
||||
#
|
||||
|
||||
. $STF_SUITE/tests/functional/pam/utilities.kshlib
|
||||
|
||||
log_mustnot ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus unavailable
|
||||
|
||||
genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir} nounmount"
|
||||
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session
|
||||
references 1
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
keystatus available
|
||||
|
||||
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session
|
||||
references 2
|
||||
keystatus available
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
|
||||
log_must pamtester pam_zfs_key_test ${username} close_session
|
||||
references 1
|
||||
keystatus available
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
|
||||
log_must pamtester pam_zfs_key_test ${username} close_session
|
||||
references 0
|
||||
keystatus available
|
||||
log_must ismounted "$TESTPOOL/pam/${username}"
|
||||
log_must zfs unmount "$TESTPOOL/pam/${username}"
|
||||
log_must zfs unload-key "$TESTPOOL/pam/${username}"
|
||||
|
||||
log_pass "done."
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/ksh -p
|
||||
#
|
||||
# CDDL HEADER START
|
||||
#
|
||||
# The contents of this file are subject to the terms of the
|
||||
# Common Development and Distribution License (the "License").
|
||||
# You may not use this file except in compliance with the License.
|
||||
#
|
||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
# or http://www.opensolaris.org/os/licensing.
|
||||
# See the License for the specific language governing permissions
|
||||
# and limitations under the License.
|
||||
#
|
||||
# When distributing Covered Code, include this CDDL HEADER in each
|
||||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
# If applicable, add the following below this CDDL HEADER, with the
|
||||
# fields enclosed by brackets "[]" replaced with your own identifying
|
||||
# information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
#
|
||||
# CDDL HEADER END
|
||||
#
|
||||
|
||||
. $STF_SUITE/tests/functional/pam/utilities.kshlib
|
||||
|
||||
if ! which pamtester; then
|
||||
log_unsupported "pam tests require the pamtester utility to be installed"
|
||||
fi
|
||||
|
||||
DISK=${DISKS%% *}
|
||||
create_pool $TESTPOOL "$DISK"
|
||||
|
||||
log_must zfs create -o mountpoint="$TESTDIR" "$TESTPOOL/pam"
|
||||
log_must add_group pamtestgroup
|
||||
log_must add_user pamtestgroup ${username}
|
||||
log_must mkdir -p "$runstatedir"
|
||||
|
||||
echo "testpass" | zfs create -o encryption=aes-256-gcm -o keyformat=passphrase -o keylocation=prompt "$TESTPOOL/pam/${username}"
|
||||
log_must zfs unmount "$TESTPOOL/pam/${username}"
|
||||
log_must zfs unload-key "$TESTPOOL/pam/${username}"
|
||||
|
||||
log_pass
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/ksh -p
|
||||
#
|
||||
# CDDL HEADER START
|
||||
#
|
||||
# The contents of this file are subject to the terms of the
|
||||
# Common Development and Distribution License (the "License").
|
||||
# You may not use this file except in compliance with the License.
|
||||
#
|
||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
# or http://www.opensolaris.org/os/licensing.
|
||||
# See the License for the specific language governing permissions
|
||||
# and limitations under the License.
|
||||
#
|
||||
# When distributing Covered Code, include this CDDL HEADER in each
|
||||
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
# If applicable, add the following below this CDDL HEADER, with the
|
||||
# fields enclosed by brackets "[]" replaced with your own identifying
|
||||
# information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
#
|
||||
# CDDL HEADER END
|
||||
#
|
||||
|
||||
. $STF_SUITE/include/libtest.shlib
|
||||
|
||||
username="pamTestuser"
|
||||
runstatedir="${TESTDIR}_run"
|
||||
function keystatus {
|
||||
log_must [ "$(zfs list -Ho keystatus "$TESTPOOL/pam/${username}")" == "$1" ]
|
||||
}
|
||||
|
||||
function genconfig {
|
||||
for i in password auth session; do
|
||||
printf "%s\trequired\tpam_permit.so\n%s\toptional\tpam_zfs_key.so\t%s\n" "$i" "$i" "$1"
|
||||
done > /etc/pam.d/pam_zfs_key_test
|
||||
}
|
||||
|
||||
function references {
|
||||
log_must [ "$(cat "${runstatedir}/$(id -u ${username})")" == "$1" ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user