1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 Datto, Inc. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
23
24#
25# DESCRIPTION:
26# 'zfs clone' should create encrypted clones of encrypted datasets
27#
28# STRATEGY:
29# 1. Create an encrypted dataset
30# 2. Create a snapshot of the dataset
31# 3. Attempt to clone the snapshot as an unencrypted dataset
32# 4. Attempt to clone the snapshot with a new key
33# 5. Attempt to clone the snapshot as a child of an unencrypted dataset
34# 6. Attempt to clone the snapshot as a child of an encrypted dataset
35# 7. Verify the encryption root of the datasets
36# 8. Unmount all datasets and unload their keys
37# 9. Attempt to load the encryption root's key
38# 10. Verify each dataset's key is loaded
39# 11. Attempt to mount each dataset
40#
41
42verify_runnable "both"
43
44function cleanup
45{
46	datasetexists $TESTPOOL/$TESTFS2 && \
47		log_must zfs destroy -f $TESTPOOL/$TESTFS2
48	datasetexists $TESTPOOL/$TESTFS1 && \
49		log_must zfs destroy -r $TESTPOOL/$TESTFS1
50}
51log_onexit cleanup
52
53log_assert "'zfs clone' should create encrypted clones of encrypted datasets"
54
55log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
56	"-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1"
57log_must zfs snapshot $TESTPOOL/$TESTFS1@now
58
59log_mustnot zfs clone -o encryption=off $TESTPOOL/$TESTFS1@now \
60	$TESTPOOL/$TESTFS2
61log_mustnot eval "echo $PASSPHRASE1 | zfs clone -o keyformat=passphrase" \
62	"$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2"
63log_must zfs clone $TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2
64log_must zfs clone $TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS1/child
65
66log_must verify_encryption_root $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS1
67log_must verify_encryption_root $TESTPOOL/$TESTFS1/child $TESTPOOL/$TESTFS1
68
69log_must zfs unmount $TESTPOOL/$TESTFS1
70log_must zfs unmount $TESTPOOL/$TESTFS2
71log_must zfs unload-key -a
72
73log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1"
74
75log_must key_available $TESTPOOL/$TESTFS1
76log_must key_available $TESTPOOL/$TESTFS1/child
77log_must key_available $TESTPOOL/$TESTFS2
78
79log_must zfs mount $TESTPOOL/$TESTFS1
80log_must zfs mount $TESTPOOL/$TESTFS1/child
81log_must zfs mount $TESTPOOL/$TESTFS2
82
83log_pass "'zfs clone' creates encrypted clones of encrypted datasets"
84