1*eb633035STom Caputi#!/bin/ksh -p 2*eb633035STom Caputi# 3*eb633035STom Caputi# CDDL HEADER START 4*eb633035STom Caputi# 5*eb633035STom Caputi# This file and its contents are supplied under the terms of the 6*eb633035STom Caputi# Common Development and Distribution License ("CDDL"), version 1.0. 7*eb633035STom Caputi# You may only use this file in accordance with the terms of version 8*eb633035STom Caputi# 1.0 of the CDDL. 9*eb633035STom Caputi# 10*eb633035STom Caputi# A full copy of the text of the CDDL should have accompanied this 11*eb633035STom Caputi# source. A copy of the CDDL is also available via the Internet at 12*eb633035STom Caputi# http://www.illumos.org/license/CDDL. 13*eb633035STom Caputi# 14*eb633035STom Caputi# CDDL HEADER END 15*eb633035STom Caputi# 16*eb633035STom Caputi 17*eb633035STom Caputi# 18*eb633035STom Caputi# Copyright (c) 2017 Datto, Inc. All rights reserved. 19*eb633035STom Caputi# 20*eb633035STom Caputi 21*eb633035STom Caputi. $STF_SUITE/include/libtest.shlib 22*eb633035STom Caputi. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib 23*eb633035STom Caputi 24*eb633035STom Caputi# 25*eb633035STom Caputi# DESCRIPTION: 26*eb633035STom Caputi# Unencrypted datasets should only allow keylocation of 'none', encryption 27*eb633035STom Caputi# roots should only allow keylocation of 'prompt' and file URI, and encrypted 28*eb633035STom Caputi# child datasets should not be able to change their keylocation. 29*eb633035STom Caputi# 30*eb633035STom Caputi# STRATEGY: 31*eb633035STom Caputi# 1. Verify the key location of the default dataset is 'none' 32*eb633035STom Caputi# 2. Attempt to change the key location of the default dataset 33*eb633035STom Caputi# 3. Create an encrypted dataset using a key file 34*eb633035STom Caputi# 4. Attempt to change the key location of the encrypted dataset to 'none', 35*eb633035STom Caputi# an invalid location, its current location, and 'prompt' 36*eb633035STom Caputi# 5. Attempt to reload the encrypted dataset key using the new key location 37*eb633035STom Caputi# 6. Create a encrypted child dataset 38*eb633035STom Caputi# 7. Verify the key location of the child dataset is 'none' 39*eb633035STom Caputi# 8. Attempt to change the key location of the child dataset 40*eb633035STom Caputi# 9. Verify the key location of the child dataset has not changed 41*eb633035STom Caputi# 42*eb633035STom Caputi 43*eb633035STom Caputiverify_runnable "both" 44*eb633035STom Caputi 45*eb633035STom Caputifunction cleanup 46*eb633035STom Caputi{ 47*eb633035STom Caputi datasetexists $TESTPOOL/$TESTFS1 && \ 48*eb633035STom Caputi log_must zfs destroy -r $TESTPOOL/$TESTFS1 49*eb633035STom Caputi} 50*eb633035STom Caputilog_onexit cleanup 51*eb633035STom Caputi 52*eb633035STom Caputilog_assert "Key location can only be 'prompt' or a file path for encryption" \ 53*eb633035STom Caputi "roots, and 'none' for unencrypted volumes" 54*eb633035STom Caputi 55*eb633035STom Caputilog_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" 56*eb633035STom Caputi 57*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS "none" 58*eb633035STom Caputilog_must zfs set keylocation=none $TESTPOOL/$TESTFS 59*eb633035STom Caputilog_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS 60*eb633035STom Caputilog_mustnot zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS 61*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS "none" 62*eb633035STom Caputi 63*eb633035STom Caputilog_must zfs create -o encryption=on -o keyformat=passphrase \ 64*eb633035STom Caputi -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 65*eb633035STom Caputi 66*eb633035STom Caputilog_mustnot zfs set keylocation=none $TESTPOOL/$TESTFS1 67*eb633035STom Caputilog_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1 68*eb633035STom Caputi 69*eb633035STom Caputilog_must zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 70*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1 "file:///$TESTPOOL/pkey" 71*eb633035STom Caputi 72*eb633035STom Caputilog_must zfs set keylocation=prompt $TESTPOOL/$TESTFS1 73*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1 "prompt" 74*eb633035STom Caputi 75*eb633035STom Caputilog_must zfs unmount $TESTPOOL/$TESTFS1 76*eb633035STom Caputilog_must zfs unload-key $TESTPOOL/$TESTFS1 77*eb633035STom Caputi 78*eb633035STom Caputilog_must rm /$TESTPOOL/pkey 79*eb633035STom Caputilog_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" 80*eb633035STom Caputilog_must zfs mount $TESTPOOL/$TESTFS1 81*eb633035STom Caputi 82*eb633035STom Caputilog_must zfs create $TESTPOOL/$TESTFS1/child 83*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1/child "none" 84*eb633035STom Caputi 85*eb633035STom Caputilog_mustnot zfs set keylocation=none $TESTPOOL/$TESTFS1/child 86*eb633035STom Caputilog_mustnot zfs set keylocation=prompt $TESTPOOL/$TESTFS1/child 87*eb633035STom Caputilog_mustnot zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child 88*eb633035STom Caputilog_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child 89*eb633035STom Caputi 90*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1/child "none" 91*eb633035STom Caputi 92*eb633035STom Caputilog_pass "Key location can only be 'prompt' or a file path for encryption" \ 93*eb633035STom Caputi "roots, and 'none' for unencrypted volumes" 94