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

Include Encryption In-Transit state as part of the desired state hash sent to clients #2837

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 57 additions & 10 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,17 @@ func (s *OCSProviderServer) GetStorageConfig(ctx context.Context, req *pb.Storag
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to construct status response: %v", err)
}
desiredClientConfigHash := getDesiredClientConfigHash(channelName, consumerObj)

storageCluster, err := s.getStorageCluster(ctx)
if err != nil {
return nil, err
}

desiredClientConfigHash := getDesiredClientConfigHash(
channelName,
consumerObj,
isEncryptionInTransitEnabled(storageCluster.Spec.Network),
)

klog.Infof("successfully returned the config details to the consumer.")
return &pb.StorageConfigResponse{
Expand Down Expand Up @@ -751,15 +761,12 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
"csi.storage.k8s.io/controller-expand-secret-name": provisionerSecretName,
}

storageClusters := &ocsv1.StorageClusterList{}
if err := s.client.List(ctx, storageClusters, client.InNamespace(s.namespace), client.Limit(2)); err != nil {
return nil, status.Errorf(codes.Internal, "failed to get storage cluster: %v", err)
}
if len(storageClusters.Items) != 1 {
return nil, status.Errorf(codes.Internal, "expecting one single storagecluster to exist")
storageCluster, err := s.getStorageCluster(ctx)
if err != nil {
return nil, err
}
var kernelMountOptions map[string]string
for _, option := range strings.Split(util.GetCephFSKernelMountOptions(&storageClusters.Items[0]), ",") {
for _, option := range strings.Split(util.GetCephFSKernelMountOptions(storageCluster), ",") {
if kernelMountOptions == nil {
kernelMountOptions = map[string]string{}
}
Expand Down Expand Up @@ -847,18 +854,28 @@ func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStat
return nil, status.Errorf(codes.Internal, "Failed to construct status response: %v", err)
}

desiredClientConfigHash := getDesiredClientConfigHash(channelName, storageConsumer)
storageCluster, err := s.getStorageCluster(ctx)
if err != nil {
return nil, err
}

desiredClientConfigHash := getDesiredClientConfigHash(
channelName,
storageConsumer,
isEncryptionInTransitEnabled(storageCluster.Spec.Network),
)

return &pb.ReportStatusResponse{
DesiredClientOperatorChannel: channelName,
DesiredConfigHash: desiredClientConfigHash,
}, nil
}

func getDesiredClientConfigHash(channelName string, storageConsumer *ocsv1alpha1.StorageConsumer) string {
func getDesiredClientConfigHash(channelName string, storageConsumer *ocsv1alpha1.StorageConsumer, encryptionInTransit bool) string {
var arr = []any{
channelName,
storageConsumer.Spec.StorageQuotaInGiB,
encryptionInTransit,
}
return util.CalculateMD5Hash(arr)
}
Expand All @@ -878,6 +895,36 @@ func (s *OCSProviderServer) getOCSSubscriptionChannel(ctx context.Context) (stri
return subscription.Spec.Channel, nil
}

func (s *OCSProviderServer) getStorageCluster(ctx context.Context) (*ocsv1.StorageCluster, error) {
scList := &ocsv1.StorageClusterList{}
if err := s.client.List(ctx, scList, client.InNamespace(s.namespace)); err != nil {
return nil, status.Errorf(codes.Internal, "failed to list storage clusters: %v", err)
}

var foundSc *ocsv1.StorageCluster
for i := range scList.Items {
sc := &scList.Items[i]
if sc.Spec.ExternalStorage.Enable { // skip external storage clusters
continue
}
if foundSc != nil {
return nil, status.Errorf(codes.FailedPrecondition, "multiple storage clusters found")
}
foundSc = sc
}
if foundSc == nil {
return nil, status.Errorf(codes.NotFound, "no storage cluster found")
}
return foundSc, nil
}

func isEncryptionInTransitEnabled(networkSpec *rookCephv1.NetworkSpec) bool {
return networkSpec != nil &&
networkSpec.Connections != nil &&
networkSpec.Connections.Encryption != nil &&
networkSpec.Connections.Encryption.Enabled
}

func extractMonitorIps(data string) ([]string, error) {
var ips []string
mons := strings.Split(data, ",")
Expand Down
5 changes: 5 additions & 0 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ func TestGetExternalResources(t *testing.T) {
ocsSubscription.Spec = ocsSubscriptionSpec
assert.NoError(t, client.Create(ctx, ocsSubscription))

storageCluster := &ocsv1.StorageCluster{}
storageCluster.Name = "test-storagecluster"
storageCluster.Namespace = serverNamespace
assert.NoError(t, client.Create(ctx, storageCluster))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the test for encryption in transit is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this just creates a storagecluster, as I am adding a util function in our code path which expects a storagecluster otherwise it will return an error. This is just to prevent that.


// When ocsv1alpha1.StorageConsumerStateReady
req := pb.StorageConfigRequest{
StorageConsumerUUID: string(consumerResource.UID),
Expand Down
Loading