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

provider: avoid CSI secret name collisions #2537

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jarrpa
Copy link
Member

@jarrpa jarrpa commented Mar 28, 2024

Previously, when fetching a storage claim config, a remote consumer was given information for creating the Ceph CSI Secrets that was identical to the secret names on the provider side. Running a consumer in the same namespace as the provider introduced namespace collisions.

Hilariously, by virtue of being the same information, things just kinda worked out anyway. Still, this is likely going to produce massive problems later, so better to fix it now.

Signed-off-by: Jose A. Rivera jarrpa@redhat.com

Fixing a really small but obnoxious typo as well as a nil reference
panic found during development on that same variable.

Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Copy link
Contributor

openshift-ci bot commented Mar 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jarrpa

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 28, 2024
@jarrpa jarrpa force-pushed the jarrpa/csi-secret-collision branch from c9bb002 to 77ce704 Compare March 29, 2024 14:44
@leelavg
Copy link
Contributor

leelavg commented Mar 29, 2024

LGTM.

services/provider/server/server.go Outdated Show resolved Hide resolved
services/provider/server/server.go Outdated Show resolved Hide resolved
services/provider/server/server.go Show resolved Hide resolved
@@ -393,6 +393,10 @@ func (s *OCSProviderServer) getCephClientInformation(ctx context.Context, name s
return cephClient.Status.Info["secretName"], cephClient.Annotations[controllers.StorageCephUserTypeAnnotation], nil
}

func scrCephClientCsiSecretName(secretType, suffix string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be called storageClaimCepCSISecretName mainly because it produces a name for a secret reconciled by the storage claim, not the request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, done.

services/provider/server/server.go Show resolved Hide resolved
// This field was named before a small refactor to clarify
// what it actually represents, but is being kept as-is so as
// to not change the generative logic.
StorageClassClaimName string `json:"storageClassRequestName"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be called StorageClaimName? we moved away from StorageClassClaim API and replaced it with StorageClaim API

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't think it was worth the effort to unify that everywhere in the codebase on the provider side. That's another follow-up PR, if anything.
image

Copy link
Member

Choose a reason for hiding this comment

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

As the final results are changes we don't need to keep storageClassRequestName in the json we can just change it to storageclaimName. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jarrpa I am not asking to change existing misleading names. Just to not add new fields/renames into misleading names

func getStorageClassRequestName(consumerUUID, storageClassRequestName string) string {
// getStorageClassRequestHash generates a hash for a StorageClassRequest based
// on the MD5 hash of the StorageClassClaim name and storageConsumer UUID.
func getStorageClassRequestHash(consumerUUID, storageClassClaimName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are doing this change then you need to change the call sites on storageClassRequestManager that refer to the same param as StorageClassRequestName which I agree is misleading

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair, done.

Copy link
Member

Choose a reason for hiding this comment

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

change storageClassClaimName to storageClaimName ?

@jarrpa jarrpa force-pushed the jarrpa/csi-secret-collision branch from 44dbbb8 to d7b072f Compare April 1, 2024 20:59
Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

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

LGTM, can we switch from storageclassclaim to storageclaim as we are changing things respect to Marhsal/Unmarshal to generate names as we also need to handle migration in this PR or are we going to handle that in followup PR?

TicketAnnotation = "ocs.openshift.io/provider-onboarding-ticket"
ProviderCertsMountPoint = "/mnt/cert"
onboardingTicketKeySecret = "onboarding-ticket-key"
storageClassClaimNameLabel = "ocs.openshift.io/storageclassclaim-name"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
storageClassClaimNameLabel = "ocs.openshift.io/storageclassclaim-name"
storageClaimNameLabel = "ocs.openshift.io/storageclaim-name"

it should be storageClaimNameLabel?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is more dangerous (and might have side effects) and regardless should not be part of this PR

func getStorageClassRequestName(consumerUUID, storageClassRequestName string) string {
// getStorageClassRequestHash generates a hash for a StorageClassRequest based
// on the MD5 hash of the StorageClassClaim name and storageConsumer UUID.
func getStorageClassRequestHash(consumerUUID, storageClassClaimName string) string {
Copy link
Member

Choose a reason for hiding this comment

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

change storageClassClaimName to storageClaimName ?

// This field was named before a small refactor to clarify
// what it actually represents, but is being kept as-is so as
// to not change the generative logic.
StorageClassClaimName string `json:"storageClassRequestName"`
Copy link
Member

Choose a reason for hiding this comment

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

As the final results are changes we don't need to keep storageClassRequestName in the json we can just change it to storageclaimName. WDYT?

@leelavg
Copy link
Contributor

leelavg commented Apr 2, 2024

LGTM, can we switch from storageclassclaim to storageclaim as we are changing things respect to Marhsal/Unmarshal to generate names as we also need to handle migration in this PR or are we going to handle that in followup PR?

  • I believe there'll be two followup PRs (mostly I'll be the one working on it), one that changes gRPC which renames StorageClassClaims to StorageClaims and another that changes StorageClassRequests to StorageRequests.

Edit: I see you mentioned a follow-up in one of the comments, from above what will you be working on @jarrpa?

@jarrpa
Copy link
Member Author

jarrpa commented Apr 2, 2024

@Madhu-1: To all your StrorageClassClaim to StorageClaim comments: no. That should be handled by a larger PR that comes and does that across the entire code base.

@leelavg Neither! The follow-up PR will be to refactor the logic in the FulfillStorageClassClaim function and has nothing to do with the renaming.

Probably as a holdover from a previous design, the provider server code
uses "storageClassRequestName" in multiple places where it is not
appropriate. These often hold the name for the *StorageClassClaim* that
came in as part of the FulfillStorageClassClaim() call. I seriously
lost hours of my time before I figured out this mistake, so I'm saving
everyone else the headache in the future.

Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Previously, when fetching a storage claim config, a remote consumer was
given information for creating the Ceph CSI Secrets that was identical
to the secret names on the provider side. Running a consumer in the same
namespace as the provider introduced namespace collisions.

Hilariously, by virtue of being the same information, things just kinda
worked out anyway. Still, this is likely going to produce massive
problems later, so better to fix it now.

Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
@jarrpa jarrpa force-pushed the jarrpa/csi-secret-collision branch from d7b072f to b1da566 Compare April 2, 2024 13:43
@leelavg
Copy link
Contributor

leelavg commented Apr 2, 2024

@nb-ohad @Madhu-1 wrt reviews could we pls consider this PR as bug fix only, unless I'm missing something which needs more changes ie, update secret names correctly and ntg more?

@nb-ohad
Copy link
Contributor

nb-ohad commented Apr 2, 2024

@nb-ohad @Madhu-1 wrt reviews could we pls consider this PR as bug fix only, unless I'm missing something which needs more changes ie, update secret names correctly and ntg more?

I agree with a small caveat. If you are renaming existing names or adding new vars/fields with new names you should use the correct terminology with this new stuff. This does not mean you need to go and rename the entirety of the existing codebase

@leelavg
Copy link
Contributor

leelavg commented Apr 8, 2024

to author & reviewers, may I know the status quo of this PR? if it makes sense, can we resist the renames not to ride on a bug fix?

yes, we renamed storageclassclaim api to storageclaim api in client side and storageclassrequest gets the fields indirectly from client via gRPC and gRPC methods aren't updated yet, can we not do some part here and some part in another PR?

I understand the refactor of func to get hash, however at the end it'll neither be storageclassrequest nor storageclassclaim and can we not make diff there?

@leelavg
Copy link
Contributor

leelavg commented Apr 19, 2024

Superseded by #2571, thanks for working on this!

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 19, 2024
@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants