zrepl/zfs
Christian Schwarz 2d8c3692ec rework resume token validation to allow resuming from raw sends of unencrypted datasets
Before this change, resuming from an unencrypted dataset with
send.raw=true specified wouldn't work with zrepl due to overly
restrictive resume token checking.

An initial PR to fix this was made in https://github.com/zrepl/zrepl/pull/503
but it didn't address the core of the problem.
The core of the problem was that zrepl assumed that if a resume token
contained `rawok=true, compressok=true`, the resulting send would be
encrypted. But if the sender dataset was unencrypted, such a resume would
actually result in an unencrypted send.
Which could be totally legitimate but zrepl failed to recognize that.

BACKGROUND
==========

The following snippets of OpenZFS code are insightful regarding how the
various ${X}ok values in the resume token are handled:

- 6c3c5fcfbe/module/zfs/dmu_send.c (L1947-L2012)
- 6c3c5fcfbe/module/zfs/dmu_recv.c (L877-L891)
- https://github.com/openzfs/zfs/blob/6c3c5fc/lib/libzfs/libzfs_sendrecv.c#L1663-L1672

Basically, some zfs send flags make the DMU send code set some DMU send
stream featureflags, although it's not a pure mapping, i.e, which DMU
send stream flags are used depends somewhat on the dataset (e.g., is it
encrypted or not, or, does it use zstd or not).

Then, the receiver looks at some (but not all) feature flags and maps
them to ${X}ok dataset zap attributes.

These are funnelled back to the sender 1:1 through the resume_token.

And the sender turns them into lzc flags.

As an example, let's look at zfs send --raw.
if the sender requests a raw send on an unencrypted dataset, the send
stream (and hence the resume token) will not have the raw stream
featureflag set, and hence the resume token will not have the rawok
field set. Instead, it will have compressok, embedok, and depending
on whether large blocks are present in the dataset, largeblockok set.

WHAT'S ZREPL'S ROLE IN THIS?
============================

zrepl provides a virtual encrypted sendflag that is like `raw`,
but further ensures that we only send encrypted datasets.

For any other resume token stuff, it shoudn't do any checking,
because it's a futile effort to keep up with ZFS send/recv features
that are orthogonal to encryption.

CHANGES MADE IN THIS COMMIT
===========================

- Rip out a bunch of needless checking that zrepl would do during
  planning. These checks were there to give better error messages,
  but actually, the error messages created by the endpoint.Sender.Send
  RPC upon send args validation failure are good enough.
- Add platformtests to validate all combinations of
  (Unencrypted/Encrypted FS) x (send.encrypted = true | false) x (send.raw = true | false)
  for cases both non-resuming and resuming send.

Additional manual testing done:
1. With zrepl 0.5, setup with unencrypted dataset, send.raw=true specified, no send.encrypted specified.
2. Observe that regular non-resuming send works, but resuming doesn't work.
3. Upgrade zrepl to this change.
4. Observe that both regular and resuming send works.

closes https://github.com/zrepl/zrepl/pull/613
2022-09-25 17:32:02 +02:00
..
property [#285] support setting zfs send / recv flags in the config (send: -wLcepbS, recv: -ox) 2021-02-20 17:20:45 +01:00
test_helpers Implement DatasetMapping + basic ZFS list functionality. 2017-04-26 17:39:16 +02:00
zfscmd zfs: rewrite SendStream, fix bug in Close() on FreeBSD, add platformtests 2021-09-19 20:11:31 +02:00
datasetpath_visitor_test.go [#342] endpoint: always create unencrypted placeholder filesystems 2020-07-26 20:32:35 +02:00
datasetpath_visitor.go [#342] endpoint: always create unencrypted placeholder filesystems 2020-07-26 20:32:35 +02:00
encryption.go [#285] support setting zfs send / recv flags in the config (send: -wLcepbS, recv: -ox) 2021-02-20 17:20:45 +01:00
filesystemplaceholdercreateencryptionvalue_enumer.go fix encrypt-on-receive with placeholders 2021-12-18 15:12:47 +01:00
holds.go endpoint: refactor, fix stale holds on initial replication failure, zfs-abstractions subcmd, more efficient ZFS queries 2020-04-18 12:26:03 +02:00
mapping.go endpoint: refactor, fix stale holds on initial replication failure, zfs-abstractions subcmd, more efficient ZFS queries 2020-04-18 12:26:03 +02:00
namecheck_test.go new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold 2020-02-14 22:00:13 +01:00
namecheck.go new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold 2020-02-14 22:00:13 +01:00
placeholder.go fix encrypt-on-receive with placeholders 2021-12-18 15:12:47 +01:00
prometheus.go bring back prometheus metrics, with new metrics for replication state machine 2018-09-07 22:22:34 -07:00
propertysource_enumer.go zfs: PropertySource: set type to uint32 so that enumer-generated code is platform-independent 2021-03-14 22:32:45 +01:00
resume_token.go zfs: ResumeToken: parse embedok, largeblockok, savedok if available 2021-02-20 17:04:57 +01:00
versions_destroy_test.go zfs: use exec.CommandContext everywhere 2020-03-27 13:08:43 +01:00
versions_destroy.go add ZREPL_DESTROY_MAX_BATCH_SIZE env var to control max batch destroy size 2022-06-30 09:22:26 +02:00
versions.go [#285] support setting zfs send / recv flags in the config (send: -wLcepbS, recv: -ox) 2021-02-20 17:20:45 +01:00
zfs_debug.go run golangci-lint and apply suggested fixes 2019-03-27 13:12:26 +01:00
zfs_pipe_linux.go zfs: pipe size: default to value of /proc/sys/fs/pipe-max-siz 2021-03-25 22:24:50 +01:00
zfs_pipe.go go1.17: run goimports to supports the new //go:build lines 2021-10-09 16:51:08 +02:00
zfs_test.go [#285] support setting zfs send / recv flags in the config (send: -wLcepbS, recv: -ox) 2021-02-20 17:20:45 +01:00
zfs.go rework resume token validation to allow resuming from raw sends of unencrypted datasets 2022-09-25 17:32:02 +02:00