@@ -86,11 +86,12 @@ func (c *Controller) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequ
86
86
}
87
87
} else {
88
88
volumeReq := & request.CreateStorageRequest {
89
- Zone : c .zone ,
90
- Title : req .GetName (),
91
- Size : storageSizeGB ,
92
- Tier : tier ,
93
- Labels : c .storageLabels ,
89
+ Zone : c .zone ,
90
+ Title : req .GetName (),
91
+ Size : storageSizeGB ,
92
+ Tier : tier ,
93
+ Labels : c .storageLabels ,
94
+ Encrypted : upcloud .FromBool (createVolumeRequestEncryptionAtRest (req )),
94
95
}
95
96
logger .WithServiceRequest (log , volumeReq ).Info ("creating volume" )
96
97
if vol , err = c .svc .CreateStorage (ctx , volumeReq ); err != nil {
@@ -167,15 +168,20 @@ func (c *Controller) createVolumeFromSource(ctx context.Context, req *csi.Create
167
168
}
168
169
return nil , status .Errorf (codes .InvalidArgument , err .Error ())
169
170
}
171
+ if src .Encrypted .Bool () != createVolumeRequestEncryptionAtRest (req ) {
172
+ // To prevent unexpected dst device properties, only allow cloning from device with same encryption policy.
173
+ return nil , status .Errorf (codes .InvalidArgument , "source and destination volumes needs to have same encryption policy" )
174
+ }
170
175
log .Info ("checking that source storage is online" )
171
176
if err := c .svc .RequireStorageOnline (ctx , & src .Storage ); err != nil {
172
177
return nil , status .Error (codes .Internal , err .Error ())
173
178
}
174
179
volumeReq := & request.CloneStorageRequest {
175
- UUID : src .Storage .UUID ,
176
- Zone : c .zone ,
177
- Tier : tier ,
178
- Title : req .GetName (),
180
+ UUID : src .Storage .UUID ,
181
+ Zone : c .zone ,
182
+ Tier : tier ,
183
+ Title : req .GetName (),
184
+ Encrypted : src .Encrypted ,
179
185
}
180
186
logger .WithServiceRequest (log , volumeReq ).Info ("cloning volume" )
181
187
vol , err := c .svc .CloneStorage (ctx , volumeReq , c .storageLabels ... )
@@ -750,6 +756,14 @@ func createVolumeRequestTier(r *csi.CreateVolumeRequest) (string, error) {
750
756
return "" , status .Error (codes .InvalidArgument , fmt .Sprintf ("storage tier '%s' not supported" , tier ))
751
757
}
752
758
759
+ func createVolumeRequestEncryptionAtRest (r * csi.CreateVolumeRequest ) bool {
760
+ e , ok := r .Parameters ["encryption" ]
761
+ if ok && e == "data-at-rest" {
762
+ return true
763
+ }
764
+ return false
765
+ }
766
+
753
767
func validateCreateVolumeRequest (r * csi.CreateVolumeRequest , zone string ) error {
754
768
if r .GetName () == "" {
755
769
return status .Error (codes .InvalidArgument , "CreateVolume Name cannot be empty" )
0 commit comments