mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 12:12:13 +03:00
Native Encryption for ZFS on Linux
This change incorporates three major pieces: The first change is a keystore that manages wrapping and encryption keys for encrypted datasets. These commands mostly involve manipulating the new DSL Crypto Key ZAP Objects that live in the MOS. Each encrypted dataset has its own DSL Crypto Key that is protected with a user's key. This level of indirection allows users to change their keys without re-encrypting their entire datasets. The change implements the new subcommands "zfs load-key", "zfs unload-key" and "zfs change-key" which allow the user to manage their encryption keys and settings. In addition, several new flags and properties have been added to allow dataset creation and to make mounting and unmounting more convenient. The second piece of this patch provides the ability to encrypt, decyrpt, and authenticate protected datasets. Each object set maintains a Merkel tree of Message Authentication Codes that protect the lower layers, similarly to how checksums are maintained. This part impacts the zio layer, which handles the actual encryption and generation of MACs, as well as the ARC and DMU, which need to be able to handle encrypted buffers and protected data. The last addition is the ability to do raw, encrypted sends and receives. The idea here is to send raw encrypted and compressed data and receive it exactly as is on a backup system. This means that the dataset on the receiving system is protected using the same user key that is in use on the sending side. By doing so, datasets can be efficiently backed up to an untrusted system without fear of data being compromised. Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Tom Caputi <tcaputi@datto.com> Closes #494 Closes #5769
This commit is contained in:
committed by
Brian Behlendorf
parent
376994828f
commit
b525630342
+66
-19
@@ -1169,6 +1169,8 @@ spa_activate(spa_t *spa, int mode)
|
||||
spa_error_entry_compare, sizeof (spa_error_entry_t),
|
||||
offsetof(spa_error_entry_t, se_avl));
|
||||
|
||||
spa_keystore_init(&spa->spa_keystore);
|
||||
|
||||
/*
|
||||
* This taskq is used to perform zvol-minor-related tasks
|
||||
* asynchronously. This has several advantages, including easy
|
||||
@@ -1246,10 +1248,11 @@ spa_deactivate(spa_t *spa)
|
||||
* still have errors left in the queues. Empty them just in case.
|
||||
*/
|
||||
spa_errlog_drain(spa);
|
||||
|
||||
avl_destroy(&spa->spa_errlist_scrub);
|
||||
avl_destroy(&spa->spa_errlist_last);
|
||||
|
||||
spa_keystore_fini(&spa->spa_keystore);
|
||||
|
||||
spa->spa_state = POOL_STATE_UNINITIALIZED;
|
||||
|
||||
mutex_enter(&spa->spa_proc_lock);
|
||||
@@ -2094,8 +2097,8 @@ spa_load_verify(spa_t *spa)
|
||||
|
||||
if (spa_load_verify_metadata) {
|
||||
error = traverse_pool(spa, spa->spa_verify_min_txg,
|
||||
TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA,
|
||||
spa_load_verify_cb, rio);
|
||||
TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA |
|
||||
TRAVERSE_NO_DECRYPT, spa_load_verify_cb, rio);
|
||||
}
|
||||
|
||||
(void) zio_wait(rio);
|
||||
@@ -2301,7 +2304,7 @@ spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type,
|
||||
spa->spa_loaded_ts.tv_nsec = 0;
|
||||
}
|
||||
if (error != EBADF) {
|
||||
zfs_ereport_post(ereport, spa, NULL, NULL, 0, 0);
|
||||
zfs_ereport_post(ereport, spa, NULL, NULL, NULL, 0, 0);
|
||||
}
|
||||
}
|
||||
spa->spa_load_state = error ? SPA_LOAD_ERROR : SPA_LOAD_NONE;
|
||||
@@ -3978,12 +3981,28 @@ spa_l2cache_drop(spa_t *spa)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify encryption parameters for spa creation. If we are encrypting, we must
|
||||
* have the encryption feature flag enabled.
|
||||
*/
|
||||
static int
|
||||
spa_create_check_encryption_params(dsl_crypto_params_t *dcp,
|
||||
boolean_t has_encryption)
|
||||
{
|
||||
if (dcp->cp_crypt != ZIO_CRYPT_OFF &&
|
||||
dcp->cp_crypt != ZIO_CRYPT_INHERIT &&
|
||||
!has_encryption)
|
||||
return (SET_ERROR(ENOTSUP));
|
||||
|
||||
return (dmu_objset_create_crypt_check(NULL, dcp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Pool Creation
|
||||
*/
|
||||
int
|
||||
spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
nvlist_t *zplprops)
|
||||
nvlist_t *zplprops, dsl_crypto_params_t *dcp)
|
||||
{
|
||||
spa_t *spa;
|
||||
char *altroot = NULL;
|
||||
@@ -3994,8 +4013,11 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
uint64_t txg = TXG_INITIAL;
|
||||
nvlist_t **spares, **l2cache;
|
||||
uint_t nspares, nl2cache;
|
||||
uint64_t version, obj;
|
||||
uint64_t version, obj, root_dsobj = 0;
|
||||
boolean_t has_features;
|
||||
boolean_t has_encryption;
|
||||
spa_feature_t feat;
|
||||
char *feat_name;
|
||||
nvpair_t *elem;
|
||||
int c, i;
|
||||
char *poolname;
|
||||
@@ -4038,10 +4060,28 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
spa->spa_import_flags |= ZFS_IMPORT_TEMP_NAME;
|
||||
|
||||
has_features = B_FALSE;
|
||||
has_encryption = B_FALSE;
|
||||
for (elem = nvlist_next_nvpair(props, NULL);
|
||||
elem != NULL; elem = nvlist_next_nvpair(props, elem)) {
|
||||
if (zpool_prop_feature(nvpair_name(elem)))
|
||||
if (zpool_prop_feature(nvpair_name(elem))) {
|
||||
has_features = B_TRUE;
|
||||
|
||||
feat_name = strchr(nvpair_name(elem), '@') + 1;
|
||||
VERIFY0(zfeature_lookup_name(feat_name, &feat));
|
||||
if (feat == SPA_FEATURE_ENCRYPTION)
|
||||
has_encryption = B_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* verify encryption params, if they were provided */
|
||||
if (dcp != NULL) {
|
||||
error = spa_create_check_encryption_params(dcp, has_encryption);
|
||||
if (error != 0) {
|
||||
spa_deactivate(spa);
|
||||
spa_remove(spa);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_features || nvlist_lookup_uint64(props,
|
||||
@@ -4131,8 +4171,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
}
|
||||
|
||||
spa->spa_is_initializing = B_TRUE;
|
||||
spa->spa_dsl_pool = dp = dsl_pool_create(spa, zplprops, txg);
|
||||
spa->spa_meta_objset = dp->dp_meta_objset;
|
||||
spa->spa_dsl_pool = dp = dsl_pool_create(spa, zplprops, dcp, txg);
|
||||
spa->spa_is_initializing = B_FALSE;
|
||||
|
||||
/*
|
||||
@@ -4157,9 +4196,6 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
cmn_err(CE_PANIC, "failed to add pool config");
|
||||
}
|
||||
|
||||
if (spa_version(spa) >= SPA_VERSION_FEATURES)
|
||||
spa_feature_create_zap_objects(spa, tx);
|
||||
|
||||
if (zap_add(spa->spa_meta_objset,
|
||||
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_CREATION_VERSION,
|
||||
sizeof (uint64_t), 1, &version, tx) != 0) {
|
||||
@@ -4220,15 +4256,26 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
|
||||
|
||||
dmu_tx_commit(tx);
|
||||
|
||||
spa->spa_sync_on = B_TRUE;
|
||||
txg_sync_start(spa->spa_dsl_pool);
|
||||
mmp_thread_start(spa);
|
||||
|
||||
/*
|
||||
* We explicitly wait for the first transaction to complete so that our
|
||||
* bean counters are appropriately updated.
|
||||
* If the root dataset is encrypted we will need to create key mappings
|
||||
* for the zio layer before we start to write any data to disk and hold
|
||||
* them until after the first txg has been synced. Waiting for the first
|
||||
* transaction to complete also ensures that our bean counters are
|
||||
* appropriately updated.
|
||||
*/
|
||||
txg_wait_synced(spa->spa_dsl_pool, txg);
|
||||
if (dp->dp_root_dir->dd_crypto_obj != 0) {
|
||||
root_dsobj = dsl_dir_phys(dp->dp_root_dir)->dd_head_dataset_obj;
|
||||
VERIFY0(spa_keystore_create_mapping_impl(spa, root_dsobj,
|
||||
dp->dp_root_dir, FTAG));
|
||||
}
|
||||
|
||||
spa->spa_sync_on = B_TRUE;
|
||||
txg_sync_start(dp);
|
||||
mmp_thread_start(spa);
|
||||
txg_wait_synced(dp, txg);
|
||||
|
||||
if (dp->dp_root_dir->dd_crypto_obj != 0)
|
||||
VERIFY0(spa_keystore_remove_mapping(spa, root_dsobj, FTAG));
|
||||
|
||||
spa_config_sync(spa, B_FALSE, B_TRUE);
|
||||
spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_CREATE);
|
||||
|
||||
Reference in New Issue
Block a user