zdb: add decryption support

The approach is straightforward: for dataset ops, if a key was offered,
find the encryption root and the various encryption parameters, derive a
wrapping key if necessary, and then unlock the encryption root. After
that all the regular dataset ops will return unencrypted data, and
that's kinda the whole thing.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #11551
Closes #12707
Closes #14503
This commit is contained in:
Rob N
2023-03-03 08:39:09 +11:00
committed by GitHub
parent 5f42d1dbf2
commit 163f3d3a1f
7 changed files with 262 additions and 15 deletions
+1
View File
@@ -573,6 +573,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zdb/zdb_decompress.ksh \
functional/cli_root/zdb/zdb_decompress_zstd.ksh \
functional/cli_root/zdb/zdb_display_block.ksh \
functional/cli_root/zdb/zdb_encrypted.ksh \
functional/cli_root/zdb/zdb_label_checksum.ksh \
functional/cli_root/zdb/zdb_object_range_neg.ksh \
functional/cli_root/zdb/zdb_object_range_pos.ksh \
@@ -57,7 +57,7 @@ set -A args "create" "add" "destroy" "import fakepool" \
"add raidz1 fakepool" "add raidz2 fakepool" \
"setvprop" "blah blah" "-%" "--?" "-*" "-=" \
"-a" "-f" "-g" "-j" "-n" "-o" "-p" "-p /tmp" \
"-t" "-w" "-z" "-E" "-H" "-I" "-J" "-K" \
"-t" "-w" "-z" "-E" "-H" "-I" "-J" \
"-Q" "-R" "-T" "-W"
log_assert "Execute zdb using invalid parameters."
@@ -0,0 +1,69 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
#
# Copyright (c) 2017, Datto, Inc. All rights reserved.
# Copyright (c) 2023, Rob Norris <robn@despairlabs.com>
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
#
# DESCRIPTION:
# 'zdb -K ...' should enable reading from an encrypt dataset
#
# STRATEGY:
# 1. Create an encrypted dataset
# 2. Write some data to a file
# 3. Run zdb -dddd on the file, confirm it can't be read
# 4. Run zdb -K ... -ddddd on the file, confirm it can be read
#
verify_runnable "both"
dataset="$TESTPOOL/$TESTFS2"
file="$TESTDIR2/somefile"
function cleanup
{
datasetexists $dataset && destroy_dataset $dataset -f
default_cleanup_noexit
}
log_onexit cleanup
log_must default_setup_noexit $DISKS
log_assert "'zdb -K' should enable reading from an encrypted dataset"
log_must eval "echo $PASSPHRASE | zfs create -o mountpoint=$TESTDIR2" \
"-o encryption=on -o keyformat=passphrase $dataset"
echo 'my great encrypted text' > $file
obj="$(ls -i $file | cut -d' ' -f1)"
size="$(wc -c < $file)"
log_note "test file $file is objid $obj, size $size"
sync_pool $TESTPOOL true
log_must eval "zdb -dddd $dataset $obj | grep -q 'object encrypted'"
log_must eval "zdb -K $PASSPHRASE -dddd $dataset $obj | grep -q 'size\s$size$'"
log_pass "'zdb -K' enables reading from an encrypted dataset"