xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded.ksh (revision eb633035c80613ec93d62f90482837adaaf21a0a)
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
23*eb633035STom Caputi#
24*eb633035STom Caputi# DESCRIPTION:
25*eb633035STom Caputi# ZFS should not perform unencrypted sends from encrypted datasets
26*eb633035STom Caputi# with unloaded keys.
27*eb633035STom Caputi#
28*eb633035STom Caputi# STRATEGY:
29*eb633035STom Caputi# 1. Create an encrypted dataset
30*eb633035STom Caputi# 2. Snapshot the dataset
31*eb633035STom Caputi# 3. Unload the dataset key
32*eb633035STom Caputi# 4. Verify sending the stream fails
33*eb633035STom Caputi#
34*eb633035STom Caputi
35*eb633035STom Caputiverify_runnable "both"
36*eb633035STom Caputi
37*eb633035STom Caputifunction cleanup
38*eb633035STom Caputi{
39*eb633035STom Caputi    datasetexists $TESTPOOL/$TESTFS1 && \
40*eb633035STom Caputi        log_must zfs destroy -r $TESTPOOL/$TESTFS1
41*eb633035STom Caputi}
42*eb633035STom Caputi
43*eb633035STom Caputilog_onexit cleanup
44*eb633035STom Caputi
45*eb633035STom Caputilog_assert "ZFS should not perform unencrypted sends from encrypted datasets" \
46*eb633035STom Caputi	"with unloaded keys."
47*eb633035STom Caputi
48*eb633035STom Caputitypeset passphrase="password"
49*eb633035STom Caputitypeset snap="$TESTPOOL/$TESTFS1@snap"
50*eb633035STom Caputi
51*eb633035STom Caputilog_must eval "echo $passphrase | zfs create -o encryption=on" \
52*eb633035STom Caputi	"-o keyformat=passphrase $TESTPOOL/$TESTFS1"
53*eb633035STom Caputilog_must zfs snapshot $snap
54*eb633035STom Caputilog_must zfs unmount $TESTPOOL/$TESTFS1
55*eb633035STom Caputilog_must zfs unload-key $TESTPOOL/$TESTFS1
56*eb633035STom Caputilog_mustnot eval "zfs send $snap > /dev/null"
57*eb633035STom Caputi
58*eb633035STom Caputilog_pass "ZFS does not perform unencrypted sends from encrypted datasets" \
59*eb633035STom Caputi	"with unloaded keys."
60