Skip to content

Commit

Permalink
rbd: add migration secret support to controllerserver functions
Browse files Browse the repository at this point in the history
This commit adds the migration secret request validation to expand,
create controller functions.

Ref # ceph#2509

Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Nov 24, 2021
1 parent 929e17d commit 70c6d26
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.Crea
return nil
}

// parseVolCreateRequest take create volume `request` argument and `secret map` as its args.
// the secretmap will be passed to genVolFromVolumeOptions() function further. Even though
// the request carry the secretmap, we dont directly consume it from the request due to the
// possibility that the secret can be of the form migration secret. As we are not touching the
// request from caller in any stage, this model has been kept.
func (cs *ControllerServer) parseVolCreateRequest(
ctx context.Context,
req *csi.CreateVolumeRequest) (*rbdVolume, error) {
Expand Down Expand Up @@ -271,13 +276,21 @@ func checkValidCreateVolumeRequest(rbdVol, parentVol *rbdVolume, rbdSnap *rbdSna
func (cs *ControllerServer) CreateVolume(
ctx context.Context,
req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
if err := cs.validateVolumeReq(ctx, req); err != nil {
err := cs.validateVolumeReq(ctx, req)
if err != nil {
return nil, err
}

// TODO: create/get a connection from the the ConnPool, and do not pass
// the credentials to any of the utility functions.
cr, err := util.NewUserCredentials(req.GetSecrets())
secrets := req.GetSecrets()
if util.IsMigrationSecret(secrets) {
secrets, err = util.ParseAndSetSecretMapFromMigSecret(secrets)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
}
cr, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -1432,7 +1445,8 @@ func (cs *ControllerServer) DeleteSnapshot(
func (cs *ControllerServer) ControllerExpandVolume(
ctx context.Context,
req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil {
err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
if err != nil {
log.ErrorLog(ctx, "invalid expand volume req: %v", protosanitizer.StripSecrets(req))

return nil, err
Expand All @@ -1456,13 +1470,21 @@ func (cs *ControllerServer) ControllerExpandVolume(
}
defer cs.VolumeLocks.Release(volID)

cr, err := util.NewUserCredentials(req.GetSecrets())
secrets := req.GetSecrets()
if util.IsMigrationSecret(secrets) {
secrets, err = util.ParseAndSetSecretMapFromMigSecret(secrets)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
}

cr, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
defer cr.DeleteCredentials()

rbdVol, err := genVolFromVolID(ctx, volID, cr, req.GetSecrets())
rbdVol, err := genVolFromVolID(ctx, volID, cr, secrets)
defer rbdVol.Destroy()
if err != nil {
switch {
Expand Down

0 comments on commit 70c6d26

Please sign in to comment.