new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/zrepl/zrepl/platformtest"
|
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden(ctx *platformtest.Context) {
|
|
|
|
|
|
|
|
supported, err := zfs.EncryptionCLISupported(ctx)
|
|
|
|
check(err)
|
|
|
|
expectNotSupportedErr := !supported
|
|
|
|
|
|
|
|
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
|
|
|
DESTROYROOT
|
|
|
|
CREATEROOT
|
|
|
|
+ "send er"
|
|
|
|
+ "send er@a snap"
|
|
|
|
`)
|
|
|
|
|
|
|
|
fs := fmt.Sprintf("%s/send er", ctx.RootDataset)
|
|
|
|
props := mustGetProps(fs + "@a snap")
|
|
|
|
|
|
|
|
sendArgs := zfs.ZFSSendArgs{
|
|
|
|
FS: fs,
|
|
|
|
To: &zfs.ZFSSendArgVersion{
|
|
|
|
RelName: "@a snap",
|
|
|
|
GUID: props.Guid,
|
|
|
|
},
|
|
|
|
Encrypted: &zfs.NilBool{B: true},
|
|
|
|
ResumeToken: "",
|
|
|
|
}
|
|
|
|
stream, err := zfs.ZFSSend(ctx, sendArgs)
|
|
|
|
if err == nil {
|
|
|
|
defer stream.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if expectNotSupportedErr {
|
|
|
|
require.Error(ctx, err)
|
|
|
|
require.Equal(ctx, zfs.ErrEncryptedSendNotSupported, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.Error(ctx, err)
|
|
|
|
ctx.Logf("send err: %T %s", err, err)
|
|
|
|
validationErr, ok := err.(*zfs.ZFSSendArgsValidationError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.True(ctx, validationErr.What == zfs.ZFSSendArgsEncryptedSendRequestedButFSUnencrypted)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SendArgsValidationResumeTokenEncryptionMismatchForbidden(ctx *platformtest.Context) {
|
|
|
|
|
|
|
|
supported, err := zfs.EncryptionCLISupported(ctx)
|
|
|
|
check(err)
|
|
|
|
if !supported {
|
|
|
|
ctx.SkipNow()
|
|
|
|
}
|
|
|
|
supported, err = zfs.ResumeSendSupported()
|
|
|
|
check(err)
|
|
|
|
if !supported {
|
|
|
|
ctx.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
|
|
|
DESTROYROOT
|
|
|
|
CREATEROOT
|
|
|
|
+ "send er" encrypted
|
|
|
|
`)
|
|
|
|
|
|
|
|
sendFS := fmt.Sprintf("%s/send er", ctx.RootDataset)
|
|
|
|
unencRecvFS := fmt.Sprintf("%s/unenc recv", ctx.RootDataset)
|
|
|
|
encRecvFS := fmt.Sprintf("%s/enc recv", ctx.RootDataset)
|
|
|
|
|
|
|
|
src := makeDummyDataSnapshots(ctx, sendFS)
|
|
|
|
|
|
|
|
unencS := makeResumeSituation(ctx, src, unencRecvFS, zfs.ZFSSendArgs{
|
|
|
|
FS: sendFS,
|
|
|
|
To: src.snapA,
|
|
|
|
Encrypted: &zfs.NilBool{B: false}, // !
|
|
|
|
}, zfs.RecvOptions{
|
|
|
|
RollbackAndForceRecv: false,
|
|
|
|
SavePartialRecvState: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
encS := makeResumeSituation(ctx, src, encRecvFS, zfs.ZFSSendArgs{
|
|
|
|
FS: sendFS,
|
|
|
|
To: src.snapA,
|
|
|
|
Encrypted: &zfs.NilBool{B: true}, // !
|
|
|
|
}, zfs.RecvOptions{
|
|
|
|
RollbackAndForceRecv: false,
|
|
|
|
SavePartialRecvState: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
// threat model: use of a crafted resume token that requests an unencrypted send
|
|
|
|
// but send args require encrypted send
|
|
|
|
{
|
|
|
|
var maliciousSend zfs.ZFSSendArgs = encS.sendArgs
|
|
|
|
maliciousSend.ResumeToken = unencS.recvErrDecoded.ResumeTokenRaw
|
|
|
|
|
|
|
|
stream, err := zfs.ZFSSend(ctx, maliciousSend)
|
|
|
|
if err == nil {
|
|
|
|
defer stream.Close()
|
|
|
|
}
|
|
|
|
require.Nil(ctx, stream)
|
|
|
|
require.Error(ctx, err)
|
|
|
|
ctx.Logf("send err: %T %s", err, err)
|
|
|
|
validationErr, ok := err.(*zfs.ZFSSendArgsValidationError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, validationErr.What, zfs.ZFSSendArgsResumeTokenMismatch)
|
|
|
|
ctx.Logf("%s", validationErr)
|
|
|
|
|
|
|
|
mismatchError, ok := validationErr.Msg.(*zfs.ZFSSendArgsResumeTokenMismatchError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, mismatchError.What, zfs.ZFSSendArgsResumeTokenMismatchEncryptionNotSet)
|
|
|
|
}
|
|
|
|
|
2020-02-23 23:24:12 +01:00
|
|
|
// threat model: use of a crafted resume token that requests an encrypted send
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
// but send args require unencrypted send
|
|
|
|
{
|
|
|
|
var maliciousSend zfs.ZFSSendArgs = unencS.sendArgs
|
|
|
|
maliciousSend.ResumeToken = encS.recvErrDecoded.ResumeTokenRaw
|
|
|
|
|
|
|
|
stream, err := zfs.ZFSSend(ctx, maliciousSend)
|
|
|
|
if err == nil {
|
|
|
|
defer stream.Close()
|
|
|
|
}
|
|
|
|
require.Nil(ctx, stream)
|
|
|
|
require.Error(ctx, err)
|
|
|
|
ctx.Logf("send err: %T %s", err, err)
|
|
|
|
validationErr, ok := err.(*zfs.ZFSSendArgsValidationError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, validationErr.What, zfs.ZFSSendArgsResumeTokenMismatch)
|
|
|
|
ctx.Logf("%s", validationErr)
|
|
|
|
|
|
|
|
mismatchError, ok := validationErr.Msg.(*zfs.ZFSSendArgsResumeTokenMismatchError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, mismatchError.What, zfs.ZFSSendArgsResumeTokenMismatchEncryptionSet)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func SendArgsValidationResumeTokenDifferentFilesystemForbidden(ctx *platformtest.Context) {
|
|
|
|
|
|
|
|
supported, err := zfs.EncryptionCLISupported(ctx)
|
|
|
|
check(err)
|
|
|
|
if !supported {
|
|
|
|
ctx.SkipNow()
|
|
|
|
}
|
|
|
|
supported, err = zfs.ResumeSendSupported()
|
|
|
|
check(err)
|
|
|
|
if !supported {
|
|
|
|
ctx.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
|
|
|
DESTROYROOT
|
|
|
|
CREATEROOT
|
|
|
|
+ "send er1"
|
|
|
|
+ "send er2"
|
|
|
|
`)
|
|
|
|
|
|
|
|
sendFS1 := fmt.Sprintf("%s/send er1", ctx.RootDataset)
|
|
|
|
sendFS2 := fmt.Sprintf("%s/send er2", ctx.RootDataset)
|
|
|
|
recvFS := fmt.Sprintf("%s/unenc recv", ctx.RootDataset)
|
|
|
|
|
|
|
|
src1 := makeDummyDataSnapshots(ctx, sendFS1)
|
|
|
|
src2 := makeDummyDataSnapshots(ctx, sendFS2)
|
|
|
|
|
|
|
|
rs := makeResumeSituation(ctx, src1, recvFS, zfs.ZFSSendArgs{
|
|
|
|
FS: sendFS1,
|
|
|
|
To: src1.snapA,
|
|
|
|
Encrypted: &zfs.NilBool{B: false},
|
|
|
|
}, zfs.RecvOptions{
|
|
|
|
RollbackAndForceRecv: false,
|
|
|
|
SavePartialRecvState: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
// threat model: forged resume token tries to steal a full send of snapA on fs2 by
|
|
|
|
// presenting a resume token for full send of snapA on fs1
|
|
|
|
var maliciousSend zfs.ZFSSendArgs = zfs.ZFSSendArgs{
|
|
|
|
FS: sendFS2,
|
|
|
|
To: &zfs.ZFSSendArgVersion{
|
|
|
|
RelName: src2.snapA.RelName,
|
|
|
|
GUID: src2.snapA.GUID,
|
|
|
|
},
|
|
|
|
Encrypted: &zfs.NilBool{B: false},
|
|
|
|
ResumeToken: rs.recvErrDecoded.ResumeTokenRaw,
|
|
|
|
}
|
|
|
|
|
|
|
|
stream, err := zfs.ZFSSend(ctx, maliciousSend)
|
|
|
|
if err == nil {
|
|
|
|
defer stream.Close()
|
|
|
|
}
|
|
|
|
require.Nil(ctx, stream)
|
|
|
|
require.Error(ctx, err)
|
|
|
|
ctx.Logf("send err: %T %s", err, err)
|
|
|
|
validationErr, ok := err.(*zfs.ZFSSendArgsValidationError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, validationErr.What, zfs.ZFSSendArgsResumeTokenMismatch)
|
|
|
|
ctx.Logf("%s", validationErr)
|
|
|
|
|
|
|
|
mismatchError, ok := validationErr.Msg.(*zfs.ZFSSendArgsResumeTokenMismatchError)
|
|
|
|
require.True(ctx, ok)
|
|
|
|
require.Equal(ctx, mismatchError.What, zfs.ZFSSendArgsResumeTokenMismatchFilesystem)
|
|
|
|
}
|