Add send:encrypted test

Create tests for the new send:encrypted permission

Sponsored-by: Klara, Inc.
Sponsored-by: Karakun AG
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: JT Pennington <jt.pennington@klarasystems.com>
Closes #17543
This commit is contained in:
JT Pennington 2025-07-15 19:32:23 +00:00 committed by Brian Behlendorf
parent 6c4ede4026
commit 43a9d9ac57
8 changed files with 456 additions and 0 deletions

View File

@ -323,6 +323,10 @@ tests = ['zfs_send_001_pos', 'zfs_send_002_pos', 'zfs_send_003_pos',
'zfs_send_raw', 'zfs_send_sparse', 'zfs_send-b', 'zfs_send_skip_missing']
tags = ['functional', 'cli_root', 'zfs_send']
[tests/functional/cli_root/zfs_send_delegation]
tests = ['zfs_send_test']
tags = ['functional', 'cli_root', 'zfs_send_delegation']
[tests/functional/cli_root/zfs_set]
tests = ['cache_001_pos', 'cache_002_neg', 'canmount_001_pos',
'canmount_002_pos', 'canmount_003_pos', 'canmount_004_pos',
@ -637,6 +641,10 @@ tests = ['zfs_list_001_pos', 'zfs_list_002_pos', 'zfs_list_003_pos',
user =
tags = ['functional', 'cli_user', 'zfs_list']
[tests/functional/cli_root/zfs_send_delegation_user]
tests = ['zfs_send_usertest']
tags = ['functional', 'cli_root', 'zfs_send_delegation_user']
[tests/functional/cli_user/zpool_iostat]
tests = ['zpool_iostat_001_neg', 'zpool_iostat_002_pos',
'zpool_iostat_003_neg', 'zpool_iostat_004_pos',

View File

@ -892,6 +892,9 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zfs_send/zfs_send_raw.ksh \
functional/cli_root/zfs_send/zfs_send_skip_missing.ksh \
functional/cli_root/zfs_send/zfs_send_sparse.ksh \
functional/cli_root/zfs_send_delegation/cleanup.ksh \
functional/cli_root/zfs_send_delegation/setup.ksh \
functional/cli_root/zfs_send_delegation/zfs_send_test.ksh \
functional/cli_root/zfs_set/cache_001_pos.ksh \
functional/cli_root/zfs_set/cache_002_neg.ksh \
functional/cli_root/zfs_set/canmount_001_pos.ksh \
@ -1409,6 +1412,9 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_user/zfs_list/zfs_list_005_neg.ksh \
functional/cli_user/zfs_list/zfs_list_007_pos.ksh \
functional/cli_user/zfs_list/zfs_list_008_neg.ksh \
functional/cli_user/zfs_send_delegation_user/cleanup.ksh \
functional/cli_user/zfs_send_delegation_user/setup.ksh \
functional/cli_user/zfs_send_delegation_user/zfs_send_usertest.ksh \
functional/cli_user/zpool_iostat/cleanup.ksh \
functional/cli_user/zpool_iostat/setup.ksh \
functional/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh \

View File

@ -0,0 +1,43 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
poolexists $TESTPOOL1 && \
destroy_pool $TESTPOOL1
del_user $STAFF1
del_user $STAFF2
del_group $STAFF_GROUP
del_user $OTHER1
del_user $OTHER2
del_group $OTHER_GROUP
default_cleanup

View File

@ -0,0 +1,50 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
# Create staff group and add two user to it
log_must add_group $STAFF_GROUP
if ! id $STAFF1 > /dev/null 2>&1; then
log_must add_user $STAFF_GROUP $STAFF1
fi
if ! id $STAFF2 > /dev/null 2>&1; then
log_must add_user $STAFF_GROUP $STAFF2
fi
# Create other group and add two user to it
log_must add_group $OTHER_GROUP
if ! id $OTHER1 > /dev/null 2>&1; then
log_must add_user $OTHER_GROUP $OTHER1
fi
if ! id $OTHER2 > /dev/null 2>&1; then
log_must add_user $OTHER_GROUP $OTHER2
fi
DISK=${DISKS%% *}
default_raidz_setup $DISKS

View File

@ -0,0 +1,111 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
# STRATEGY:
# 1. Create a pool (this is done by the test framework)
# 2. Create an encrypted dataset
# 3. Write random data to the encrypted dataset
# 4. Snapshot the dataset
# 5. As root: attempt a send and raw send (both should succeed)
# 6. Create a delegation (zfs allow -u user send testpool/encrypted_dataset)
# 7. As root: attempt a send and raw send (both should succeed)
# 8. Create a delegation (zfs allow -u user send:raw testpool/encrypted_dataset)
# 9. As root: attempt a send and raw send (both should succeed)
# 10. Disable delegation (zfs unallow)
# 11. As root: attempt a send and raw send (both should succeed)
# 12. Clean up (handled by framework)
#
# Tested as a user under ../cli_user/zfs_send_delegation_user/
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
. $STF_SUITE/tests/functional/delegate/delegate.cfg
# create encrypted dataset
log_must eval "echo $PASSPHRASE | zfs create -o encryption=on -o keyformat=passphrase $TESTPOOL/$TESTFS1"
# create target dataset for receives
if ! zfs list | grep testfs2 >/dev/null 2>&1; then
dataset_created="TRUE"
log_must zfs create $TESTPOOL/$TESTFS2
fi
# create user and group
typeset perms="snapshot,reservation,compression,checksum,userprop,receive"
log_note "Added permissions to the $OTHER1 user."
log_must zfs allow $OTHER1 $perms $TESTPOOL/$TESTFS1
log_must zfs allow $OTHER1 $perms $TESTPOOL/$TESTFS2
# create random data
log_must fill_fs $TESTPOOL/$TESTFS1/child 1 2047 1024 1 R
# snapshot
log_must zfs snapshot $TESTPOOL/$TESTFS1@snap1
# check baseline send abilities (should pass)
log_must eval "zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv0_datastream.$$"
log_must eval "zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv0raw_datastream.$$"
# create delegation
log_must zfs allow $OTHER1 send $TESTPOOL/$TESTFS1
# attempt send with full allow
log_must eval "zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv1_datastream.$$"
log_must eval "zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv1raw_datastream.$$"
# create raw delegation
log_must zfs allow $OTHER1 send:raw $TESTPOOL/$TESTFS1
log_must zfs unallow $OTHER1 send $TESTPOOL/$TESTFS1
# test new send abilities (should pass)
log_must eval "zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv2_datastream.$$"
log_must eval "zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv2raw_datastream.$$"
# disable raw delegation
zfs unallow $OTHER1 send:raw $TESTPOOL/$TESTFS1
zfs allow $OTHER1 send $TESTPOOL/$TESTFS1
# verify original send abilities (should pass)
log_must eval "zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv3_datastream.$$"
log_must eval "zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive $TESTPOOL/$TESTFS2/zfsrecv3raw_datastream.$$"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
destroy_dataset $TESTPOOL/$TESTFS1 -r \
destroy_dataset $TESTPOOL/$TESTFS2 -r
}

View File

@ -0,0 +1,43 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
poolexists $TESTPOOL1 && \
destroy_pool $TESTPOOL1
del_user $STAFF1
del_user $STAFF2
del_group $STAFF_GROUP
del_user $OTHER1
del_user $OTHER2
del_group $OTHER_GROUP
default_cleanup

View File

@ -0,0 +1,50 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
# Create staff group and add two user to it
log_must add_group $STAFF_GROUP
if ! id $STAFF1 > /dev/null 2>&1; then
log_must add_user $STAFF_GROUP $STAFF1
fi
if ! id $STAFF2 > /dev/null 2>&1; then
log_must add_user $STAFF_GROUP $STAFF2
fi
# Create other group and add two user to it
log_must add_group $OTHER_GROUP
if ! id $OTHER1 > /dev/null 2>&1; then
log_must add_user $OTHER_GROUP $OTHER1
fi
if ! id $OTHER2 > /dev/null 2>&1; then
log_must add_user $OTHER_GROUP $OTHER2
fi
DISK=${DISKS%% *}
default_raidz_setup $DISKS

View File

@ -0,0 +1,145 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara Inc.
#
# STRATEGY:
# 1. Create a pool (this is done by the test framework)
# 2. Create a user
# 3. Create an encrypted dataset
# 4. Write random data to the encrypted dataset
# 5. Snapshot the dataset
# 6. As root: attempt a send and raw send (both should succeed)
# 7. As user: attempt a send and raw send (both should fail, no permission)
# 8. Create a delegation (zfs allow -u user send testpool/encrypted_dataset)
# 9. As root: attempt a send and raw send (both should succeed)
# 10. As user: attempt a send and raw send (both should succeed)
# 11. Create a delegation (zfs allow -u user sendraw testpool/encrypted_dataset)
# 12. As root: attempt a send and raw send (both should succeed)
# 13. As user: attempt a send and raw send (send should fail, raw send should succeed)
# 14. Disable delegation (zfs unallow)
# 15. As root: attempt a send and raw send (both should succeed)
# 16. As user: attempt a send and raw send (both should fail, no permission)
# 17. Clean up (handled by framework)
# root tests to verify this doesnt affect root user under ../cli_root/zfs_send_delegation/
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
. $STF_SUITE/tests/functional/delegate/delegate.cfg
# create encrypted dataset
log_must eval "echo $PASSPHRASE | zfs create -o encryption=on -o keyformat=passphrase $TESTPOOL/$TESTFS1"
# create target dataset for receives
log_must zfs create $TESTPOOL/$TESTFS2
# set user perms
# need to run chown for fs permissions for $OTHER1
typeset perms="snapshot,reservation,compression,checksum,userprop,receive,mount,create"
log_must zfs allow $OTHER1 $perms $TESTPOOL/$TESTFS1
log_must zfs allow $OTHER1 $perms $TESTPOOL/$TESTFS2
log_must chown ${OTHER1}:${OTHER_GROUP} /$TESTPOOL/$TESTFS2
# create random data
log_must fill_fs $TESTPOOL/$TESTFS1/child 1 2047 1024 1 R
# snapshot
log_must zfs snapshot $TESTPOOL/$TESTFS1@snap1
# note
# we need to use `sh -c` here becuase the quoting on <<<"$*" in the user_run wrapper is broken once pipes and redirects get involved
# check baseline send abilities (should fail)
log_mustnot user_run $OTHER1 sh -c "'zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv0_user_datastream.$$'"
# verify nothing went through
if [ -s $TESTPOOL/$TESTFS2/zfsrecv0_user_datastream.$$ ]
then
log_fail "A zfs recieve was completed in $TESTPOOL/$TESTFS2/zfsrecv0_user_datastream !"
fi
log_mustnot user_run $OTHER1 sh -c "'zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv0raw_user_datastream.$$'"
# verify nothing went through
if [ -s $TESTPOOL/$TESTFS2/zfsrecv0raw_user_datastream.$$ ]
then
log_fail "A zfs recieve was completed in $TESTPOOL/$TESTFS2/zfsrecv0raw_user_datastream !"
fi
# create delegation
log_must zfs allow $OTHER1 send $TESTPOOL/$TESTFS1
# attempt send with full allow (should pass)
log_must user_run $OTHER1 sh -c "'zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv1_user_datastream.$$'"
log_must user_run $OTHER1 sh -c "'zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv1raw_user_datastream.$$'"
# create raw delegation
log_must zfs allow $OTHER1 send:raw $TESTPOOL/$TESTFS1
# We have to remove 'send' to confirm 'send raw' only allows what we want
log_must zfs unallow -u $OTHER1 send $TESTPOOL/$TESTFS1
# test new sendraw abilities (send should fail, sendraw should pass)
log_mustnot user_run $OTHER1 sh -c "'zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv2_user_datastream.$$'"
verify nothing went through
if [ -s $TESTPOOL/$TESTFS2/zfsrecv2_user_datastream.$$ ]
then
log_fail "A zfs recieve was completed in $TESTPOOL/$TESTFS2/zfsrecv2_user_datastream !"
fi
log_must user_run $OTHER1 sh -c "'zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv2raw_user_datastream.$$'"
# disable raw delegation
log_must zfs unallow -u $OTHER1 send:raw $TESTPOOL/$TESTFS1
log_must zfs allow $OTHER1 send $TESTPOOL/$TESTFS1
# test with raw taken away (should pass)
log_must user_run $OTHER1 sh -c "'zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv3_user_datastream.$$'"
log_must user_run $OTHER1 sh -c "'zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv3raw_user_datastream.$$'"
# disable send abilities
log_must zfs unallow -u $OTHER1 send $TESTPOOL/$TESTFS1
# verify original send abilities (should fail)
log_mustnot user_run $OTHER1 sh -c "'zfs send $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv4_user_datastream.$$'"
verify nothing went through
if [ -s $TESTPOOL/$TESTFS2/zfsrecv4_user_datastream.$$ ]
then
log_fail "A zfs recieve was completed in $TESTPOOL/$TESTFS2/zfsrecv4_user_datastream !"
fi
log_mustnot user_run $OTHER1 sh -c "'zfs send -w $TESTPOOL/$TESTFS1@snap1 | zfs receive -u $TESTPOOL/$TESTFS2/zfsrecv4raw_user_datastream.$$'"
verify nothing went through
if [ -s $TESTPOOL/$TESTFS2/zfsrecv4raw_user_datastream.$$ ]
then
log_fail "A zfs recieve was completed in $TESTPOOL/$TESTFS2/zfsrecv4raw_user_datastream !"
fi
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
destroy_dataset $TESTPOOL/$TESTFS1 -r \
destroy_dataset $TESTPOOL/$TESTFS2 -r
}