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

Replace templates in SC parameter with PVC annotations #808

Closed
wants to merge 4 commits into from

Conversation

vinli-cn
Copy link

@vinli-cn vinli-cn commented Nov 8, 2022

What type of PR is this?
/kind feature

What this PR does / why we need it:
Replace templates in SC parameter with PVC annotations, this fixes issue 428 in csi-driver-smb repo: kubernetes-csi/csi-driver-smb#428

This change has been tested manually with SMB CSI Driver which uses SC parameter subDir in SMB mount path, code example as below

Storage Class

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: smb
provisioner: smb.csi.k8s.io
parameters:
  subDir: ${pvc.annotations['subDirInPVC']}

PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-smb
  annotations:
    subDirInPVC: "dir1"

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Replace SC parameter template with PVC annotations

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 8, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @vinli-cn. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 8, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vinli-cn
Once this PR has been reviewed and has the lgtm label, please assign xing-yang for approval by writing /assign @xing-yang in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@andyzhangx
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 8, 2022
@andyzhangx
Copy link
Member

@vinli-cn could you add more details in PR description? thanks.

pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Show resolved Hide resolved
pkg/controller/controller.go Show resolved Hide resolved
@vinli-cn vinli-cn marked this pull request as ready for review November 9, 2022 12:33
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2022
@vinli-cn vinli-cn changed the title Replace SC parameter template with PVC annotations Replace templates in SC parameter with PVC annotations Nov 10, 2022
Copy link
Member

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

pls add ut for this PR, and also I found resolveTemplate does not have any ut, I think you could submit a separate PR for resolveTemplate ut

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 10, 2022
@andyzhangx
Copy link
Member

andyzhangx commented Nov 10, 2022

@xing-yang could you take a look? this is actually a requirement from smb csi driver, user wants to use subDir: ${pvc.annotations['key']} and we already supports ${pvc.annotations[key] for following parameters, this PR would support ${pvc.annotations[key] for all paramaters in storage class.

csi.storage.k8s.io/provisioner-secret-name
csi.storage.k8s.io/provisioner-secret-namespace
csi.storage.k8s.io/controller-publish-secret-name
csi.storage.k8s.io/controller-publish-secret-namespace
csi.storage.k8s.io/node-stage-secret-name
csi.storage.k8s.io/node-stage-secret-namespace
csi.storage.k8s.io/node-publish-secret-name
csi.storage.k8s.io/node-publish-secret-namespace

e.g.
https://kubernetes-csi.github.io/docs/secrets-and-credentials-storage-class.html

  csi.storage.k8s.io/node-publish-secret-name: ${pvc.annotations['team.example.com/key']}
  csi.storage.k8s.io/node-publish-secret-namespace: ${pvc.namespace}

@humblec humblec requested a review from jsafrane November 11, 2022 03:38
@vinli-cn vinli-cn requested review from andyzhangx and removed request for xing-yang, jsafrane, chrishenzie and jingxu97 November 15, 2022 05:02
@andyzhangx
Copy link
Member

/assign @xing-yang

@andyzhangx
Copy link
Member

/assign @msau42 @jsafrane

@xing-yang
Copy link
Contributor

In the past, we have rejected enhancement requests like this for portability reasons. I think we need to have a discuss on this.
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 21, 2022
@xing-yang
Copy link
Contributor

See this issue here: #86

@andyzhangx
Copy link
Member

See this issue here: #86

@xing-yang this is not Adding PVC's annotation to CreateVolumeRequest.Parameters, and since csi.storage.k8s.io/node-publish-secret-name already supports pvc.annotations translation, this PR extends the translation support for other storage class fields, as long as it's defined as ${pvc.annotations['team.example.com/key']}, it would be translated for other fields.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: fast-storage
provisioner: csi-driver.team.example.com
parameters:
  type: pd-ssd
  csi.storage.k8s.io/node-publish-secret-name: ${pvc.annotations['team.example.com/key']}
  csi.storage.k8s.io/node-publish-secret-namespace: ${pvc.namespace}

@vinli-cn
Copy link
Author

See this issue here: #86

As Andy mentioned above, external-provisioner can replace templates in secret parameters in Storage Class with values from PVC annotations already, and this PR extends similar "translation" for other parameters in Storage Class, eg: ${pvc.annotations['subDirInPVC']} in my example. We've seen lots of user cases from community.

This PR doesn't have any correlation with #86. In fact, I've sent below PR for similar issue in #86 but it's being discussed now.
#800

@jsafrane
Copy link
Contributor

I understand that passing annotations (or any other per-PVC configuration) to CSI driver can have mane useful use cases and is frequently asked for, my personal favorite is a way to tag volumes in a cloud by user (PVC author) provided tags.

However, it's a double edged sword.

  1. As mentioned above, it makes PVCs not portable. This is a huge change, so far you could take PVCs to any Kubernetes with any CSI driver and they would work. All platform specific info was in StorageClass. How a random Helm chart author of a stateful application knows what annotations a particular CSI driver supports? So far they needed to care only about StorageClass name.

  2. It opens doors for security issues. For example, Cannot mount an existing share via subDir parameter csi-driver-smb#428 - with that feature, anyone who can create a PVC can actually read data of other PVs that are dynamically provisioned from the same StorageClass, just by guessing the subdirectory name. It may work well in clusters where users trust each other, but it absolute no-go for multi-tenant clusters. It's not obvious from StorageClass parameter description that it lowers security. My experience is that CSI driver authors do not care or do not understand security too much and we end up with very insecure clusters.

Not that I'd like to have some way how to pass custom parameters from PVC to PV and to CSI driver, however, it must be done carefully. I don't have a magic solution that would solve both problems mentioned above, but it may exist.

@andyzhangx
Copy link
Member

andyzhangx commented Nov 24, 2022

I understand that passing annotations (or any other per-PVC configuration) to CSI driver can have mane useful use cases and is frequently asked for, my personal favorite is a way to tag volumes in a cloud by user (PVC author) provided tags.

However, it's a double edged sword.

  1. As mentioned above, it makes PVCs not portable. This is a huge change, so far you could take PVCs to any Kubernetes with any CSI driver and they would work. All platform specific info was in StorageClass. How a random Helm chart author of a stateful application knows what annotations a particular CSI driver supports? So far they needed to care only about StorageClass name.
  2. It opens doors for security issues. For example, Cannot mount an existing share via subDir parameter csi-driver-smb#428 - with that feature, anyone who can create a PVC can actually read data of other PVs that are dynamically provisioned from the same StorageClass, just by guessing the subdirectory name. It may work well in clusters where users trust each other, but it absolute no-go for multi-tenant clusters. It's not obvious from StorageClass parameter description that it lowers security. My experience is that CSI driver authors do not care or do not understand security too much and we end up with very insecure clusters.

Not that I'd like to have some way how to pass custom parameters from PVC to PV and to CSI driver, however, it must be done carefully. I don't have a magic solution that would solve both problems mentioned above, but it may exist.

@jsafrane thanks for the comments. Regrading to point 1 & 2, I am thinking is it possible to add a feature flag for this feature(by default disable), so if users want this feature, they could turn it on in csi-provisioner themselves, by that way, this feature won't affect all csi-provisioner users, and it could also satisfy specific csi driver users.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 22, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 24, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants