Skip to content

Commit eb5b2e4

Browse files
committed
feat(backing encryption): backing image encryption support
ref: longhorn/longhorn 7051 Signed-off-by: Jack Lin <[email protected]>
1 parent 2ab49b9 commit eb5b2e4

File tree

215 files changed

+21335
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+21335
-9
lines changed

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/golang/protobuf v1.5.4
1010
github.com/gorilla/mux v1.8.1
1111
github.com/longhorn/backupstore v0.0.0-20240603134532-5ec9a300bef4
12+
github.com/longhorn/go-common-libs v0.0.0-20240411093823-b8862efb8e03
1213
github.com/longhorn/longhorn-engine v1.6.0-dev-20231217.0.20240418025706-519598108463
1314
github.com/longhorn/sparse-tools v0.0.0-20240513025352-ed49dd3f93eb
1415
github.com/longhorn/types v0.0.0-20240605091135-ef450e1c04cd
@@ -29,28 +30,34 @@ require (
2930
github.com/aws/aws-sdk-go v1.34.2 // indirect
3031
github.com/beorn7/perks v1.0.1 // indirect
3132
github.com/bits-and-blooms/bitset v1.12.0 // indirect
33+
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
3234
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3335
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
3436
github.com/felixge/httpsnoop v1.0.3 // indirect
3537
github.com/gammazero/deque v0.2.1 // indirect
3638
github.com/gammazero/workerpool v1.1.3 // indirect
3739
github.com/go-logr/logr v1.3.0 // indirect
40+
github.com/go-ole/go-ole v1.2.6 // indirect
3841
github.com/google/uuid v1.6.0 // indirect
3942
github.com/gorilla/handlers v1.5.2 // indirect
4043
github.com/jmespath/go-jmespath v0.3.0 // indirect
4144
github.com/kr/pretty v0.3.1 // indirect
4245
github.com/kr/text v0.2.0 // indirect
4346
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
47+
github.com/mitchellh/go-ps v1.0.0 // indirect
4448
github.com/moby/sys/mountinfo v0.6.2 // indirect
4549
github.com/mschoch/smat v0.2.0 // indirect
4650
github.com/pierrec/lz4/v4 v4.1.17 // indirect
51+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
4752
github.com/prometheus/client_golang v1.15.0 // indirect
4853
github.com/prometheus/client_model v0.3.0 // indirect
4954
github.com/prometheus/common v0.42.0 // indirect
5055
github.com/prometheus/procfs v0.9.0 // indirect
5156
github.com/rogpeppe/go-internal v1.10.0 // indirect
5257
github.com/russross/blackfriday/v2 v2.1.0 // indirect
58+
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
5359
github.com/slok/goresilience v0.2.0 // indirect
60+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
5461
golang.org/x/sys v0.20.0 // indirect
5562
golang.org/x/text v0.15.0 // indirect
5663
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect

go.sum

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1414
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
1515
github.com/bits-and-blooms/bitset v1.12.0 h1:U/q1fAF7xXRhFCrhROzIfffYnu+dlS38vCZtmFVPHmA=
1616
github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
17+
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 h1:SjZ2GvvOononHOpK84APFuMvxqsk3tEIaKH/z4Rpu3g=
18+
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE=
1719
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
1820
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
1921
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
@@ -33,11 +35,15 @@ github.com/gammazero/workerpool v1.1.3 h1:WixN4xzukFoN0XSeXF6puqEqFTl2mECI9S6W44
3335
github.com/gammazero/workerpool v1.1.3/go.mod h1:wPjyBLDbyKnUn2XwwyD3EEwo9dHutia9/fwNmSHWACc=
3436
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
3537
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
38+
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
39+
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
3640
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
3741
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3842
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
3943
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
4044
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
45+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
46+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4147
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4248
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4349
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -57,15 +63,20 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
5763
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5864
github.com/longhorn/backupstore v0.0.0-20240603134532-5ec9a300bef4 h1:FI2oBT6397aaQfspA3tDlYjkDaqhtXnwID4dMgVic0g=
5965
github.com/longhorn/backupstore v0.0.0-20240603134532-5ec9a300bef4/go.mod h1:n210xpMUVrSn/W4Za/9BZhyXLCTVfAOq5lNdLrRSyz8=
66+
github.com/longhorn/go-common-libs v0.0.0-20240411093823-b8862efb8e03 h1:RN7mq4FrbHcAeemI5tDha9u4X+RSRrPugD1cY1FHdvo=
67+
github.com/longhorn/go-common-libs v0.0.0-20240411093823-b8862efb8e03/go.mod h1:7onp+E4hSg2DnB40dJU0Y7adrvykGg6jHxOb48imPGg=
6068
github.com/longhorn/longhorn-engine v1.6.0-dev-20231217.0.20240418025706-519598108463 h1:KxddgUYC9InOhe8MxfbxzOL5v9q7f5DyThxQGGKvqVw=
6169
github.com/longhorn/longhorn-engine v1.6.0-dev-20231217.0.20240418025706-519598108463/go.mod h1:WNiZl2l51I36/c8dewxkyWd0yBA5Anznzki0knKO88U=
6270
github.com/longhorn/sparse-tools v0.0.0-20240513025352-ed49dd3f93eb h1:Kh89s6i5T1W6BT1Aq9W1YHXojbbcTXlDieWC5KWAs/E=
6371
github.com/longhorn/sparse-tools v0.0.0-20240513025352-ed49dd3f93eb/go.mod h1:vFvENahNfkr2VAyROaGHnZrLWuXwZJ0DHj8mBIh2miI=
6472
github.com/longhorn/types v0.0.0-20240605091135-ef450e1c04cd h1:gzvHnEc4vdHmOtxwgjC/7YmChbzDsfYiY0wpI3RgB1A=
6573
github.com/longhorn/types v0.0.0-20240605091135-ef450e1c04cd/go.mod h1:1oEh1cnDDqNSuFh/dH/lvJ3Ssq83SOweTAAPLRY4PMI=
74+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
6675
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
6776
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
6877
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
78+
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
79+
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
6980
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
7081
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
7182
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
@@ -78,6 +89,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7889
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7990
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8091
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
92+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
93+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
8194
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
8295
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
8396
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
@@ -97,6 +110,10 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
97110
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
98111
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
99112
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
113+
github.com/shirou/gopsutil/v3 v3.24.3 h1:eoUGJSmdfLzJ3mxIhmOAhgKEKgQkeOwKpz1NbhVnuPE=
114+
github.com/shirou/gopsutil/v3 v3.24.3/go.mod h1:JpND7O217xa72ewWz9zN2eIIkPWsDN/3pl0H8Qt0uwg=
115+
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
116+
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
100117
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
101118
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
102119
github.com/slok/goresilience v0.2.0 h1:dagdIiWlhTm7BK/r/LRKz+zvw0SCNk+nHf7obdsbzxQ=
@@ -116,8 +133,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
116133
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
117134
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
118135
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
136+
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
137+
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
119138
github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM=
120139
github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0=
140+
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
141+
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
121142
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
122143
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
123144
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -134,11 +155,16 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
134155
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
135156
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
136157
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
158+
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
137159
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138160
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
161+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
139162
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
140163
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
141164
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
165+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
166+
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
167+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
142168
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
143169
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
144170
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -149,6 +175,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
149175
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
150176
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
151177
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
178+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
152179
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
153180
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
154181
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=

pkg/client/sync_client.go

+42
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,48 @@ func (client *SyncClient) DownloadFromURL(downloadURL, filePath, uuid, diskUUID,
220220
return nil
221221
}
222222

223+
func (client *SyncClient) CloneFromBackingImage(sourceBackingImage, sourceBackingImageUUID, encryption, filePath, uuid, diskUUID, expectedChecksum string, credential map[string]string) error {
224+
httpClient := &http.Client{Timeout: 0}
225+
encodedCredential, err := json.Marshal(credential)
226+
if err != nil {
227+
return err
228+
}
229+
230+
requestURL := fmt.Sprintf("http://%s/v1/files", client.Remote)
231+
req, err := http.NewRequest("POST", requestURL, bytes.NewReader(encodedCredential))
232+
if err != nil {
233+
return err
234+
}
235+
req.Header.Set("Content-Type", "application/json")
236+
q := req.URL.Query()
237+
q.Add("action", "cloneFromBackingImage")
238+
q.Add("backing-image", sourceBackingImage)
239+
q.Add("backing-image-uuid", sourceBackingImageUUID)
240+
q.Add("encryption", encryption)
241+
q.Add("file-path", filePath)
242+
q.Add("uuid", uuid)
243+
q.Add("disk-uuid", diskUUID)
244+
q.Add("expected-checksum", expectedChecksum)
245+
246+
req.URL.RawQuery = q.Encode()
247+
248+
resp, err := httpClient.Do(req)
249+
if err != nil {
250+
return fmt.Errorf("clone from backing image failed, err: %s", err)
251+
}
252+
defer resp.Body.Close()
253+
254+
bodyContent, err := io.ReadAll(resp.Body)
255+
if err != nil {
256+
return fmt.Errorf("%s, failed to read the response body: %v", util.GetHTTPClientErrorPrefix(resp.StatusCode), err)
257+
}
258+
if resp.StatusCode != http.StatusOK {
259+
return fmt.Errorf("%s, response body content: %v", util.GetHTTPClientErrorPrefix(resp.StatusCode), string(bodyContent))
260+
}
261+
262+
return nil
263+
}
264+
223265
func (client *SyncClient) RestoreFromBackupURL(backupURL, concurrentLimit, filePath, uuid, diskUUID, expectedChecksum string, credential map[string]string) error {
224266
httpClient := &http.Client{Timeout: 0}
225267
encodedCredential, err := json.Marshal(credential)

pkg/crypto/crypto.go

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package crypto
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/pkg/errors"
8+
"github.com/sirupsen/logrus"
9+
10+
"github.com/longhorn/backing-image-manager/pkg/types"
11+
lhns "github.com/longhorn/go-common-libs/ns"
12+
lhtypes "github.com/longhorn/go-common-libs/types"
13+
)
14+
15+
const (
16+
MapperFilePathPrefix = "/dev/mapper"
17+
18+
CryptoKeyDefaultCipher = "aes-xts-plain64"
19+
CryptoKeyDefaultHash = "sha256"
20+
CryptoKeyDefaultSize = "256"
21+
CryptoDefaultPBKDF = "argon2i"
22+
)
23+
24+
// EncryptParams keeps the customized cipher options from the secret CR
25+
type EncryptParams struct {
26+
KeyProvider string
27+
KeyCipher string
28+
KeyHash string
29+
KeySize string
30+
PBKDF string
31+
}
32+
33+
func NewEncryptParams(keyProvider, keyCipher, keyHash, keySize, pbkdf string) *EncryptParams {
34+
return &EncryptParams{KeyProvider: keyProvider, KeyCipher: keyCipher, KeyHash: keyHash, KeySize: keySize, PBKDF: pbkdf}
35+
}
36+
37+
func (cp *EncryptParams) GetKeyCipher() string {
38+
if cp.KeyCipher == "" {
39+
return CryptoKeyDefaultCipher
40+
}
41+
return cp.KeyCipher
42+
}
43+
44+
func (cp *EncryptParams) GetKeyHash() string {
45+
if cp.KeyHash == "" {
46+
return CryptoKeyDefaultHash
47+
}
48+
return cp.KeyHash
49+
}
50+
51+
func (cp *EncryptParams) GetKeySize() string {
52+
if cp.KeySize == "" {
53+
return CryptoKeyDefaultSize
54+
}
55+
return cp.KeySize
56+
}
57+
58+
func (cp *EncryptParams) GetPBKDF() string {
59+
if cp.PBKDF == "" {
60+
return CryptoDefaultPBKDF
61+
}
62+
return cp.PBKDF
63+
}
64+
65+
// EncryptBackingImage encrypts provided device with LUKS.
66+
func EncryptBackingImage(devicePath, passphrase string, cryptoParams *EncryptParams) error {
67+
namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
68+
nsexec, err := lhns.NewNamespaceExecutor(lhtypes.ProcessNone, lhtypes.HostProcDirectory, namespaces)
69+
if err != nil {
70+
return err
71+
}
72+
73+
logrus.Infof("Encrypting device %s with LUKS", devicePath)
74+
if _, err := nsexec.LuksFormat(
75+
devicePath, passphrase,
76+
cryptoParams.GetKeyCipher(),
77+
cryptoParams.GetKeyHash(),
78+
cryptoParams.GetKeySize(),
79+
cryptoParams.GetPBKDF(),
80+
lhtypes.LuksTimeout); err != nil {
81+
return errors.Wrapf(err, "failed to encrypt device %s with LUKS", devicePath)
82+
}
83+
return nil
84+
}
85+
86+
// OpenBackingImage opens backing image so that it can be used by the client.
87+
func OpenBackingImage(devicePath, passphrase, uuid string) error {
88+
if isOpen, _ := IsDeviceOpen(types.BackingImageMapper(uuid)); isOpen {
89+
logrus.Infof("Device %s is already opened at %s", devicePath, types.BackingImageMapper(uuid))
90+
return nil
91+
}
92+
93+
namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
94+
nsexec, err := lhns.NewNamespaceExecutor(lhtypes.ProcessNone, lhtypes.HostProcDirectory, namespaces)
95+
if err != nil {
96+
return err
97+
}
98+
99+
logrus.Infof("Opening device %s with LUKS on %v", devicePath, types.BackingImageFileName)
100+
_, err = nsexec.LuksOpen(types.GetLuksBackingImageName(uuid), devicePath, passphrase, lhtypes.LuksTimeout)
101+
if err != nil {
102+
logrus.WithError(err).Warnf("Failed to open LUKS device %s", devicePath)
103+
}
104+
return err
105+
}
106+
107+
// CloseBackingImage closes encrypted backing image so it can be detached.
108+
func CloseBackingImage(uuid string) error {
109+
namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
110+
nsexec, err := lhns.NewNamespaceExecutor(lhtypes.ProcessNone, lhtypes.HostProcDirectory, namespaces)
111+
if err != nil {
112+
return err
113+
}
114+
115+
logrus.Infof("Closing LUKS device %s", types.GetLuksBackingImageName(uuid))
116+
_, err = nsexec.LuksClose(types.GetLuksBackingImageName(uuid), lhtypes.LuksTimeout)
117+
return err
118+
}
119+
120+
// IsDeviceOpen determines if encrypted device is already open.
121+
func IsDeviceOpen(device string) (bool, error) {
122+
_, mappedFile, err := DeviceEncryptionStatus(device)
123+
return mappedFile != "", err
124+
}
125+
126+
// DeviceEncryptionStatus looks to identify if the passed device is a LUKS mapping
127+
// and if so what the device is and the mapper name as used by LUKS.
128+
// If not, just returns the original device and an empty string.
129+
func DeviceEncryptionStatus(devicePath string) (mappedDevice, mapper string, err error) {
130+
if !strings.HasPrefix(devicePath, types.MapperFilePathPrefix) {
131+
return devicePath, "", nil
132+
}
133+
134+
namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
135+
nsexec, err := lhns.NewNamespaceExecutor(lhtypes.ProcessNone, lhtypes.HostProcDirectory, namespaces)
136+
if err != nil {
137+
return devicePath, "", err
138+
}
139+
140+
backingImage := strings.TrimPrefix(devicePath, types.MapperFilePathPrefix+"/")
141+
stdout, err := nsexec.LuksStatus(backingImage, lhtypes.LuksTimeout)
142+
if err != nil {
143+
logrus.WithError(err).Warnf("Device %s is not an active LUKS device", devicePath)
144+
return devicePath, "", nil
145+
}
146+
147+
lines := strings.Split(string(stdout), "\n")
148+
if len(lines) < 1 {
149+
return "", "", fmt.Errorf("device encryption status returned no stdout for %s", devicePath)
150+
}
151+
152+
if !strings.Contains(lines[0], " is active") {
153+
// Implies this is not a LUKS device
154+
return devicePath, "", nil
155+
}
156+
157+
for i := 1; i < len(lines); i++ {
158+
kv := strings.SplitN(strings.TrimSpace(lines[i]), ":", 2)
159+
if len(kv) < 1 {
160+
return "", "", fmt.Errorf("device encryption status output for %s is badly formatted: %s",
161+
devicePath, lines[i])
162+
}
163+
if strings.Compare(kv[0], "device") == 0 {
164+
return strings.TrimSpace(kv[1]), backingImage, nil
165+
}
166+
}
167+
// Identified as LUKS, but failed to identify a mapped device
168+
return "", "", fmt.Errorf("mapped device not found in path %s", devicePath)
169+
}

0 commit comments

Comments
 (0)