Skip to content

Conversation

@arnongilboa
Copy link
Collaborator

What this PR does / why we need it:
Add ServiceAccountName to DataImportCron spec, replacing CreatedBy which was added in #3946.

In case of DataImportCron with PVC source, the controller checks the ServiceAccount is authorized to clone the source PVC.

Release note:

Simplify DataImportCron ServiceAccount authorization

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 3, 2025
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign aglitke for approval. For more information see the 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

@akalenyu
Copy link
Collaborator

akalenyu commented Dec 3, 2025

/test pull-cdi-linter
/test pull-containerized-data-importer-e2e-nfs
unrelated issues with ci

@akalenyu
Copy link
Collaborator

akalenyu commented Dec 3, 2025

@arnongilboa real linter issues in there

Copy link
Collaborator

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

skimmed through, looks good, will try to properly go over this later and find releases containing this API

Just a note, this might've been easier to review if it was split to

  • revert commit
  • reintroduce with new api

@arnongilboa
Copy link
Collaborator Author

skimmed through, looks good, will try to properly go over this later and find releases containing this API

Just a note, this might've been easier to review if it was split to

  • revert commit
  • reintroduce with new api

sure, fixing.

@kubevirt-bot kubevirt-bot added dco-signoff: no Indicates the PR's author has not DCO signed all their commits. and removed dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 3, 2025
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Dec 3, 2025
arnongilboa added a commit to arnongilboa/containerized-data-importer that referenced this pull request Dec 3, 2025
In case of DataImportCron with PVC source, the controller checks the
namespace default ServiceAccount is authorized to clone the source PVC.

This is a minimally partial backport of kubevirt#3970.

Signed-off-by: Arnon Gilboa <[email protected]>
arnongilboa added a commit to arnongilboa/containerized-data-importer that referenced this pull request Dec 3, 2025
In case of DataImportCron with PVC source, the controller checks the
namespace default ServiceAccount is authorized to clone the source PVC.

This is a minimally partial backport of kubevirt#3970.

Signed-off-by: Arnon Gilboa <[email protected]>
arnongilboa added a commit to arnongilboa/containerized-data-importer that referenced this pull request Dec 3, 2025
In case of DataImportCron with PVC source, the controller checks the
namespace default ServiceAccount is authorized to clone the source PVC.

This is a minimally partial backport of kubevirt#3970.

Signed-off-by: Arnon Gilboa <[email protected]>
arnongilboa added a commit to arnongilboa/containerized-data-importer that referenced this pull request Dec 3, 2025
In case of DataImportCron with PVC source, the controller checks the
namespace default ServiceAccount is authorized to clone the source PVC.

This is a minimally partial backport of kubevirt#3970.

Signed-off-by: Arnon Gilboa <[email protected]>
arnongilboa added a commit to arnongilboa/containerized-data-importer that referenced this pull request Dec 3, 2025
In case of DataImportCron with PVC source, the controller checks the
namespace default ServiceAccount is authorized to clone the source PVC.

This is a minimally partial backport of kubevirt#3970.

Signed-off-by: Arnon Gilboa <[email protected]>
// ServiceAccountName is the name of the ServiceAccount for creating DataVolumes.
// +optional
CreatedBy *string `json:"createdBy,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a pointer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In PodSpec it's ServiceAccountName string. Afaik this is the standard choice in Kubernetes, as the zero value ("") represents the "not set" state when combined with the omitempty tag.

Copy link
Member

Choose a reason for hiding this comment

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

Pod spec has been around for a long time, likely predating API conventions

https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#optional-vs-required

Maybe make it a pointer and add: +kubebuilder:validation:MinLength=1


var userInfo authenticationv1.UserInfo
if err := json.Unmarshal([]byte(*createdBy), &userInfo); err != nil {
if resp, err := dv.AuthorizeSA(dv.Namespace, dv.Name, r, dataImportCron.Namespace, dataImportCron.Spec.ServiceAccountName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I'll use "default" in this case, but note that in your link if somehow vol.ServiceAccount.ServiceAccountName == "" it will also be used instead of "default".

Copy link
Member

Choose a reason for hiding this comment

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

pretty sure you can't have a serviceaccount volume with empty sa name

@arnongilboa arnongilboa force-pushed the dic_sa branch 2 times, most recently from 5d5b676 to 32acdbf Compare December 4, 2025 09:08
@arnongilboa
Copy link
Collaborator Author

/retest

Copy link
Collaborator

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

Looks good, some comments, but the approach looks ok for me

})
})

Context("DataImportCron controller authorization when cloning from PVC source", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

bit of a shame to use functional tests for this, it's all just a bunch of APIs that could be faked

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. I just recycled the tests of the previous PR which involved the webhooks, so I felt func tests are appropriate. I'll sure change to utests.

return true, nil
}

func (r *DataImportCronReconciler) CreateSar(sar *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'll read nicer if there was a separate struct for AuthorizationHelperProxy impl

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I'll fix.

Add ServiceAccountName to DataImportCron spec, replacing CreatedBy
which was added in kubevirt#3946.

In case of DataImportCron with PVC source, the controller checks the
ServiceAccount is authorized to clone the source PVC.

Signed-off-by: Arnon Gilboa <[email protected]>
@kubevirt-bot
Copy link
Contributor

@arnongilboa: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cdi-linter 12de3c3 link false /test pull-cdi-linter

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-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants