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 change-key -i' should cause a dataset to inherit its parent key
27#
28# STRATEGY:
29# 1. Create a parent encrypted dataset
30# 2. Create a child dataset as an encryption root
31# 3. Attempt to inherit the parent key
32# 4. Verify the key is inherited
33# 5. Unmount the parent and unload its key
34# 6. Verify the key is unavailable for parent and child
35# 7. Load the parent key
36# 8. Verify the key is available for parent and child
37# 9. Attempt to mount the datasets
38#
39
40verify_runnable "both"
41
42function cleanup
43{
44	datasetexists $TESTPOOL/$TESTFS1 && \
45		log_must zfs destroy -r $TESTPOOL/$TESTFS1
46}
47log_onexit cleanup
48
49log_assert "'zfs change-key -i' should cause a dataset to inherit its" \
50	"parent key"
51
52log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
53	"-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1"
54log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \
55	"-o keyformat=passphrase -o keylocation=prompt" \
56	"$TESTPOOL/$TESTFS1/child"
57
58log_must verify_encryption_root $TESTPOOL/$TESTFS1/child \
59	"$TESTPOOL/$TESTFS1/child"
60
61log_must zfs change-key -i $TESTPOOL/$TESTFS1/child
62log_must verify_encryption_root $TESTPOOL/$TESTFS1/child "$TESTPOOL/$TESTFS1"
63
64log_must zfs unmount $TESTPOOL/$TESTFS1
65log_must zfs unload-key $TESTPOOL/$TESTFS1
66
67log_must key_unavailable $TESTPOOL/$TESTFS1
68log_must key_unavailable $TESTPOOL/$TESTFS1/child
69
70log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1"
71
72log_must key_available $TESTPOOL/$TESTFS1
73log_must key_available $TESTPOOL/$TESTFS1/child
74
75log_must zfs mount $TESTPOOL/$TESTFS1
76log_must zfs mount $TESTPOOL/$TESTFS1/child
77
78log_pass "'zfs change-key -i' causes a dataset to inherit its parent key"
79