Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot restore backups to encrypted pools #286

Closed
artw opened this issue Feb 5, 2021 · 23 comments · Fixed by #292 or openebs/velero-plugin#147
Closed

Cannot restore backups to encrypted pools #286

artw opened this issue Feb 5, 2021 · 23 comments · Fixed by #292 or openebs/velero-plugin#147

Comments

@artw
Copy link

artw commented Feb 5, 2021

I'm having trouble restoring PVs with velero, it always fails with mysterious error

  Cluster:  error executing PVAction for persistentvolumes/pvc-10e06ec5-293a-4ec9-a47b-12613bf74396: rpc error: code = Unknown desc = zfs: error in restoring pvc-10e06ec5-293a-4ec9-a47b-12613bf
74396.redis, status:{Failed}

The detailed info is posted at velero-plugin repo, as it seemed more relevant. Would be glad if someone helps me to debug this.

openebs/velero-plugin#145

@pawanpraka1
Copy link
Contributor

@artw can I get the node daemonset(openebs-zfs-node-xxxx) log in kube-system namespace?

@artw
Copy link
Author

artw commented Feb 5, 2021

@pawanpraka1 that was fast, thank you! I did not know where to look

│ could not restore the volume data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3 cmd [-c nc -w 3 10.42.0.35 9010 | zfs recv -F data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3] error: cannot receive new filesystem stream: zfs receive -F cannot be used to destroy an encrypted filesystem or overwrite an unencrypted one with an encrypted one

any workarounds?

@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 5, 2021

can you share zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test.zfsvol from the backup? Is there any encryption setting?

@artw
Copy link
Author

artw commented Feb 5, 2021

The pool is encrypted with aes-256-gcm, the snapshot is not (I can recv it on another box w/ encryption=off and it stays off)

snapshot metadata:

        "metadata": {
                "name": "pvc-51791429-c865-4439-8c76-387d335c8cd3",
                "namespace": "openebs",
                "uid": "50365668-58ba-45d2-9339-b23c684b4061",
                "resourceVersion": "1703137",
                "generation": 2,
                "creationTimestamp": "2021-02-05T08:16:01Z",
                "labels": {
                        "kubernetes.io/nodename": "con-d1",
                        "velero.io/namespace": "redis-test"
                },
                "finalizers": [
                        "zfs.openebs.io/finalizer"
                ],
                "managedFields": [
                        {
                                "manager": "zfs-driver",
                                "operation": "Update",
                                "apiVersion": "zfs.openebs.io/v1",
                                "time": "2021-02-05T08:16:01Z"
                        }
                ]
        },
        "spec": {
                "ownerNodeID": "con-d1",
                "poolName": "data/k3s/pv",
                "capacity": "5368709120",
                "recordsize": "4k",
                "compression": "on",
                "dedup": "off",
                "volumeType": "DATASET",
                "fsType": "zfs"
        },
        "status": {
                "state": "Ready"
        }

The data (pipe through base64 and gunzip)

H4sIANgbHWAAA+3deXxM9/7H8e9MVlsSexAEiSURZCF2iWREiERWEiEiC7FEKrFrxVYUtYRW1aX2LajSq7ag3NquWhpdLG1RVFFK7UvumZiTK4nX7zdxf78/euf7aT3eOc/MJzP95nu+Z86ZMRXiZWUf23lfq2R5IfQhcl849NWnfqOs8qf/rG7jK8yf+cRwc5EYnxHfdJBnetO0Ecq/CW7N3b1buXt5tHJLaNmiuZuXl2crt5YJ3i3cPFt6J3p6Nk9omZDo6TMsKTEl3S0jKT1D/NVLW2RbY8ii42RqdTq4dpa1kgu7XjtgbS5EuwGbFnXSaMTjCs80H+kaF4yTmpXVxoIBffkdUxvHP05/n7+f7bnYc8xcKyFsZo26fuCAVkRWtbs6sdwOYW64nTpu6njlGcrUxkutvg0bfaWsWWLi0uXtdysD2DFxXY73txbiyv2IHgHT8zTqeKnTq6Lyp7EBPn3lO6Y2frXP5cbq9706y0am1FQG5ewut95Zm0uLOq0/buG1YLR5TPemQmtuL1ZOKNzXOdciP6+ZiUJZ1/B9/Ty1nizEQcPx467bKA99lnS7YJ4byuzfX9ot1dRSwsdxuqig3/bRp7p/FCwjcv/Ir2XbhtxxUHLJ7VCxs7YQvpVHDFyyroqInzO4au08z7LqeKnj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Uu3pijjNuzgzM0Lxq6ige2O/e36/d8of3j2E19Lva4YWG43dR2saFfKreLHp+Yl9fCVXidy7nkdD1q0bwzHXNPTovcYWrj2HfkyfqHlfGw3NJ+9uytrqLj/mYrLni2Wh3zaNikXSc95/0LjMkyzNC4AAA=

I can do recv (without -F) on the same pool fine and it inherits encryption from parent

cat zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test | zfs recv -v data/tst
receiving full stream of data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3@redis-test into data/tst@redis-test
received 45.9K stream in 1 seconds (45.9K/sec)
$ zfs get all data/tst@redis-test
NAME                 PROPERTY              VALUE                  SOURCE
data/tst@redis-test  type                  snapshot               -
data/tst@redis-test  creation              Fri Feb  5 10:16 2021  -
data/tst@redis-test  used                  112K                   -
data/tst@redis-test  referenced            168K                   -
data/tst@redis-test  compressratio         1.00x                  -
data/tst@redis-test  devices               on                     default
data/tst@redis-test  exec                  on                     default
data/tst@redis-test  setuid                on                     default
data/tst@redis-test  createtxg             386261                 -
data/tst@redis-test  xattr                 sa                     inherited from data
data/tst@redis-test  version               5                      -
data/tst@redis-test  utf8only              on                     -
data/tst@redis-test  normalization         formD                  -
data/tst@redis-test  casesensitivity       sensitive              -
data/tst@redis-test  nbmand                off                    default
data/tst@redis-test  guid                  18053967813387586919   -
data/tst@redis-test  primarycache          all                    default
data/tst@redis-test  secondarycache        all                    default
data/tst@redis-test  defer_destroy         off                    -
data/tst@redis-test  userrefs              0                      -
data/tst@redis-test  objsetid              566                    -
data/tst@redis-test  mlslabel              none                   default
data/tst@redis-test  refcompressratio      1.00x                  -
data/tst@redis-test  written               168K                   -
data/tst@redis-test  clones                                       -
data/tst@redis-test  logicalreferenced     67.5K                  -
data/tst@redis-test  acltype               posixacl               inherited from data
data/tst@redis-test  context               none                   default
data/tst@redis-test  fscontext             none                   default
data/tst@redis-test  defcontext            none                   default
data/tst@redis-test  rootcontext           none                   default
**data/tst@redis-test  encryption            aes-256-gcm            -**
data/tst@redis-test  encryptionroot        data                   -
data/tst@redis-test  keystatus             available              -

@pawanpraka1
Copy link
Contributor

are you restoring it on the same cluster and on the same node? If it is the different node where we are restoring then can you try keeping encryption setting same on both the node? can you try the recv with -F and let me know the error?

@artw
Copy link
Author

artw commented Feb 5, 2021

all nodes are the same, I can import it fine with -F.
I redid the restore. The problem is that zfs-plugin first creates the volume manually, then tries to overwrite it with the snapshot. Is that step really needed?

I0205 10:48:20.848786       1 volume.go:116] Got add event for ZV data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:20.930788       1 zfs_util.go:394] created volume data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:20.953178       1 volume.go:246] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3'
I0205 10:48:25.888559       1 restore.go:107] Got add event for Restore pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test vol pvc-51791429-c865-4439-8c76-387d335c8cd3
E0205 10:48:26.010247       1 zfs_util.go:809] zfs: could not restore the volume data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3 cmd [-c nc -w 3 10.42.0.35 9010 | zfs recv -F data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3] error: cannot receive new filesystem stream: zfs receive -F cannot be used to destroy an encrypted filesystem or overwrite an unencrypted one with an encrypted one
E0205 10:48:26.010466       1 restore.go:88] restore pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test failed pvc-51791429-c865-4439-8c76-387d335c8cd3 err exit status 1
I0205 10:48:26.020497       1 restore.go:235] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test'
I0205 10:48:30.931621       1 restore.go:125] Got update event for Restore pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test vol pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:30.931686       1 restore.go:235] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test'
I0205 10:48:31.065821       1 volume.go:136] Got update event for ZV data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:31.109955       1 zfs_util.go:629] destroyed volume data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:31.137310       1 volume.go:161] Got delete event for ZV data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
I0205 10:48:31.137463       1 volume.go:246] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3'
E0205 10:48:31.137519       1 volume.go:50] zfsvolume 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3' has been deleted
I0205 10:48:31.137536       1 volume.go:246] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3'
I0205 10:48:31.808775       1 restore.go:150] Got delete event for Restore pvc-51791429-c865-4439-8c76-387d335c8cd3
E0205 10:48:31.808857       1 restore.go:51] zfs restore 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test' has been deleted
I0205 10:48:31.808867       1 restore.go:235] Successfully synced 'openebs/pvc-51791429-c865-4439-8c76-387d335c8cd3.redis-test'

@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 5, 2021

I see using "-F" while doing restore is a problem for encrypted volumes as zfs does not allow to use -F on it. It was done to roll back any changs which might have done, but it is highly unlikely that it happens. Probably we can safely remove -F option from here https://github.com/openebs/zfs-localpv/blob/master/pkg/zfs/zfs_util.go#L345.

@artw
Copy link
Author

artw commented Feb 5, 2021

I see using "-F" while doing restore is a problem for encrypted volumes as zfs does not allow to use -F on it. It was done to roll back any changs which might have be done, but it is highly unlikely that it happens. Probably we can safely remove -F option from here https://github.com/openebs/zfs-localpv/blob/master/pkg/zfs/zfs_util.go#L345.

No, this would not work. -F is needed to overwrite a dataset. The proper solution would be to create and use another function, like CreateVolumeFromSnapshot, that will not do zfs create first, but recv, and would still create all needed metadata abstractions.

$ zfs create data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3 
$ cat zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test| zfs recv -F data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
cannot receive new filesystem stream: zfs receive -F cannot be used to destroy an encrypted filesystem or overwrite an unencrypted one with an encrypted one
$ cat zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test| zfs recv data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
cannot receive new filesystem stream: destination 'data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3' exists
must specify -F to overwrite it

@pawanpraka1
Copy link
Contributor

is that step really needed?

To answer this question, we need to have ZFSVolume object, which in turns creates the volume. Then we restore on that volume. This object is needed so that we can mount the volume and do various operation like zfs property change etc.

@artw artw changed the title Restore of PV (zfs-localpv) from snapshot fails with (rpc error: code = Unknown) Cannot restore backups to encrypted pools Feb 5, 2021
@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 5, 2021

No, this would not work. -F is needed to overwrite a dataset. The proper solution would be to create and use another function, like CreateVolumeFromSnapshot, that will not do zfs create first, but recv, and would still create all needed metadata abstractions.

Good point. yeah, if dataset exists then we need to provide "-F" option. Can you confirm if we are creating a dataset in the encrypted pool and then restore with "-F" will fail on that dataset?

@artw
Copy link
Author

artw commented Feb 5, 2021

Can you confirm if we are creating a dataset in the encrypted pool and then restore with "-F" fails?

Already did, please see the snippet below my previous comment

@artw
Copy link
Author

artw commented Feb 5, 2021

I tried to receive a "raw" snapshot created using zfs send -w, it fails the same way. I suppose it is not possible to overwrite an encrypted volume at all with openzfs...

$ zfs snapshot data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3@new
$ zfs send -w data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3@new > zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test.encrypted
$ zfs destroy -r data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
$ zfs create data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
$ cat zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test.encrypted| zfs recv -F data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3
cannot receive new filesystem stream: zfs receive -F cannot be used to destroy an encrypted filesystem or overwrite an unencrypted one with an encrypted one

@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 5, 2021

hmmm, so that means we can never restore the data on already existing encryption volume (strange!!! new learning for me) as we have to provide -F option. However it is possible do that on non encrypted volumes.

@artw
Copy link
Author

artw commented Feb 5, 2021

It seems that the only way you can work with existing encrypted volumes is through replication streams (incremental backups). And you need to use -w then (raw data).

  If the -i or -I flags are used in conjunction with the -R flag, an incremental replication stream is generated.  The current values of properties, and current snapshot and file
           system names are set when the stream is received.  If the -F flag is specified when this stream is received, snapshots and file systems that do not exist on the sending side are
           destroyed. If the -R flag is used to send encrypted datasets, then -w must also be specified.

By the way the zfs-localpv does not use -w. Is it configurable somewhere? It is less portable, but snapshots are both encrypted and compressed if the source is. It may be desirable. In my case I don't really care about encrypting the backup, it is stored in safe location, but portable one is twice as large.

-rw-r--r-- 1 1337 1337  47K Feb  5 12:43 zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test
-rw-rw-r-- 1 1337 1337  24K Feb  5 13:53 zfs-pvc-51791429-c865-4439-8c76-387d335c8cd3-redis-test.encrypted

@pawanpraka1
Copy link
Contributor

Is it configurable by the way?

no, not as of now. We need to find out a proper solution for this which can work for all cases.

@pawanpraka1
Copy link
Contributor

@artw we need to make some design changes to fix this. The only solution I can think of right now is to restore the volume first and then create the ZFSVolume object. If volume already exists, the creation of ZFSVolume does not do anything.

For now, if you want to recover the data, you can manually create the volume without encryption and then do the velero restore.
zfs create -o encryption=off data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3

@artw
Copy link
Author

artw commented Feb 5, 2021

@pawanpraka1 yes, this is a tricky one.

zfs create -o encryption=off
Yes, this works. Biggest problem is that there is no way to re-encrypt the restored dataset, apart from using something like rsync. I was sure you could do something like send/receive locally to encrypt, but no. ZoL encryption still ways to go I guess

#openzfs/zfs#10484

edit: wrong, can encrypt by send/receive -o encryption=on

But it is something at least, thanks!

@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 5, 2021

Yes @artw, we will fix it so that we don't need to restore it in not encrypted dataset. We are working on the design, will ping to test the fix once it is ready.

@artw
Copy link
Author

artw commented Feb 5, 2021

Biggest problem is that there is no way to re-encrypt the restored dataset

actually I was wrong, zfs recv -o encryption=aes-256-gcm works, that issue I referred is not relevant. so its not too bad

$ zfs snapshot data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3@plain
$ zfs send data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3@plain | zfs recv -o encryption=aes-256-gcm data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3_enc
$ zfs get encryption data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3_enc 
NAME                                                      PROPERTY    VALUE        SOURCE
data/k3s/pv/pvc-51791429-c865-4439-8c76-387d335c8cd3_enc  encryption  aes-256-gcm  -

@pawanpraka1
Copy link
Contributor

adding the openzfs issue for reference here : openzfs/zfs#6793.

@pawanpraka1
Copy link
Contributor

@artw I have made some design changes where we are creating the ZFSVolume after the restore is done. Here are the PR links (still work in progress)

  1. ZFS-LocalPV: fix(restore): adding support to restore in an encrypted pool #292
  2. Velero: fix(restore): adding support to restore in an encrypted pool for ZFS-LocalPV velero-plugin#147

I don't have encrypted pool setup, could you help me verify this change. To verify, we need to install the below zfs operator yaml

kubectl apply -f https://raw.githubusercontent.com/pawanpraka1/zfs-localpv/encr/deploy/zfs-operator.yaml

This operator is using my local build (amd64) image pawanpraka1/zfs-driver:ep. Once installation is done use pawanpraka1/velero-plugin:ep velero plugin instead of openebs/velero-plugin and see if restore is working fine for you.

@artw
Copy link
Author

artw commented Feb 17, 2021

@pawanpraka1 wow, that was fast! Just tested it, worked fine. Encryption is preserved after restore

$ velero backup create redis --snapshot-volumes --include-namespaces=redis
$ velero backup describe --details redis

Name:         redis
Namespace:    velero
Labels:       velero.io/storage-location=default
Annotations:  velero.io/source-cluster-k8s-gitversion=v1.20.2+k3s1
              velero.io/source-cluster-k8s-major-version=1
              velero.io/source-cluster-k8s-minor-version=20

Phase:  Completed

Errors:    0
Warnings:  0

Namespaces:
  Included:  redis
  Excluded:  <none>

Resources:
  Included:        *
  Excluded:        <none>
  Cluster-scoped:  auto

Label selector:  <none>

Storage Location:  default

Velero-Native Snapshot PVs:  true

TTL:  720h0m0s

Hooks:  <none>

Backup Format Version:  1.1.0

Started:    2021-02-17 10:56:39 +0200 EET
Completed:  2021-02-17 10:56:53 +0200 EET

Expiration:  2021-03-19 10:56:39 +0200 EET

Total items to be backed up:  15
Items backed up:              15

Resource List:
  apps/v1/ControllerRevision:
    - redis/redis-5d47b58654
    - redis/redis-745597d796
  apps/v1/StatefulSet:
    - redis/redis
  discovery.k8s.io/v1beta1/EndpointSlice:
    - redis/redis-8w7v9
    - redis/redis-t57zb
  v1/ConfigMap:
    - redis/kube-root-ca.crt
    - redis/redis-config
  v1/Endpoints:
    - redis/redis
  v1/Namespace:
    - redis
  v1/PersistentVolume:
    - pvc-0239c3a2-d5ab-4755-a2e4-8ebddd2bb510
  v1/PersistentVolumeClaim:
    - redis/redis-storage-redis-0
  v1/Pod:
    - redis/redis-0
  v1/Secret:
    - redis/default-token-m8cxk
  v1/Service:
    - redis/redis
  v1/ServiceAccount:
    - redis/default

Velero-Native Snapshots:
  pvc-0239c3a2-d5ab-4755-a2e4-8ebddd2bb510:
    Snapshot ID:        pvc-0239c3a2-d5ab-4755-a2e4-8ebddd2bb510..redis
    Type:               zfs-localpv
    Availability Zone:
    IOPS:               <N/A>

velero backup logs redis

$ velero restore create --from-backup redis --restore-volumes=true --namespace-mappings redis:redis-test
$ velero restore describe redis-20210217105707                                                                                    ~ (0) [10:57:18]
Name:         redis-20210217105707
Namespace:    velero
Labels:       <none>
Annotations:  <none>

Phase:  Completed

Started:    2021-02-17 10:57:07 +0200 EET
Completed:  2021-02-17 10:57:19 +0200 EET

Backup:  redis

Namespaces:
  Included:  all namespaces found in the backup
  Excluded:  <none>

Resources:
  Included:        *
  Excluded:        nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io
  Cluster-scoped:  auto

Namespace mappings:  redis=redis-test

Label selector:  <none>

velero restore logs redis-20210217105707

{
	"metadata": {
		"name": "pvc-0239c3a2-d5ab-4755-a2e4-8ebddd2bb510",
		"namespace": "openebs",
		"uid": "f4d2260f-77df-467d-999f-2b0fb85da87a",
		"resourceVersion": "1589120",
		"generation": 2,
		"creationTimestamp": "2021-02-04T23:43:01Z",
		"labels": {
			"kubernetes.io/nodename": "con-d1",
			"velero.io/namespace": "redis"
		},
		"finalizers": [
			"zfs.openebs.io/finalizer"
		],
		"managedFields": [
			{
				"manager": "zfs-driver",
				"operation": "Update",
				"apiVersion": "zfs.openebs.io/v1",
				"time": "2021-02-04T23:43:02Z"
			}
		]
	},
	"spec": {
		"ownerNodeID": "con-d1",
		"poolName": "data/k3s/pv",
		"capacity": "5368709120",
		"recordsize": "4k",
		"compression": "on",
		"dedup": "off",
		"volumeType": "DATASET",
		"fsType": "zfs"
	},
	"status": {
		"state": "Ready"
	}
}

@pawanpraka1
Copy link
Contributor

pawanpraka1 commented Feb 17, 2021

thanks for confirming @artw. would you mind mentioning your use case in our Adopters file openebs/openebs#2719.

@kmova kmova closed this as completed in #292 Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants