-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch implements the EncryptionKeyRotation spec for ceph-csi Signed-off-by: Niraj Yadav <[email protected]>
- Loading branch information
1 parent
29dde7a
commit 96b3e7d
Showing
17 changed files
with
1,147 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2024 The Ceph-CSI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package rbd | ||
|
||
import ( | ||
"context" | ||
|
||
ekr "github.com/csi-addons/spec/lib/go/encryptionkeyrotation" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/ceph/ceph-csi/internal/rbd" | ||
"github.com/ceph/ceph-csi/internal/util" | ||
) | ||
|
||
type EncryptionKeyRotationServer struct { | ||
*ekr.UnimplementedEncryptionKeyRotationControllerServer | ||
} | ||
|
||
func NewEncryptionKeyRotationServer() *EncryptionKeyRotationServer { | ||
return &EncryptionKeyRotationServer{} | ||
} | ||
|
||
func (ekrs *EncryptionKeyRotationServer) RegisterService(svc grpc.ServiceRegistrar) { | ||
ekr.RegisterEncryptionKeyRotationControllerServer(svc, ekrs) | ||
} | ||
|
||
func (ekrs *EncryptionKeyRotationServer) RotateEncryptionKey( | ||
ctx context.Context, | ||
req *ekr.EncryptionKeyRotateRequest, | ||
) (*ekr.EncryptionKeyRotateResponse, error) { | ||
// Get the volume ID from the request | ||
volID := req.GetVolumeId() | ||
if volID == "" { | ||
return nil, status.Error(codes.InvalidArgument, "empty volume id in request") | ||
} | ||
|
||
// Get the credentials required to authenticate | ||
// against a ceph cluster | ||
creds, err := util.NewUserCredentials(req.GetSecrets()) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
defer creds.DeleteCredentials() | ||
|
||
// Form the rbdVolume struct | ||
rbdVol, err := rbd.GenVolFromVolID(ctx, volID, creds, req.GetSecrets()) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Aborted, "failed to find volume with ID %q: %s", volID, err.Error()) | ||
} | ||
defer rbdVol.Destroy() | ||
|
||
err = rbdVol.RotateEncryptionKey(ctx) | ||
if err != nil { | ||
return nil, status.Errorf( | ||
codes.Aborted, "failed to rotate the key for volume with ID %q: %s", volID, err.Error()) | ||
} | ||
|
||
// Success | ||
return &ekr.EncryptionKeyRotateResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.