Skip to content

Commit 3191362

Browse files
committed
Simplify DataImportCron ServiceAccount authorization
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. Signed-off-by: Arnon Gilboa <[email protected]>
1 parent a19c17e commit 3191362

File tree

20 files changed

+55
-399
lines changed

20 files changed

+55
-399
lines changed

api/openapi-spec/swagger.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,10 +4377,6 @@
43774377
"managedDataSource"
43784378
],
43794379
"properties": {
4380-
"createdBy": {
4381-
"description": "CreatedBy is the JSON-marshaled UserInfo of the user who created this DataImportCron. This field is set by the mutating webhook and cannot be set by users.",
4382-
"type": "string"
4383-
},
43844380
"garbageCollect": {
43854381
"description": "GarbageCollect specifies whether old PVCs should be cleaned up after a new PVC is imported. Options are currently \"Outdated\" and \"Never\", defaults to \"Outdated\".",
43864382
"type": "string"
@@ -4404,6 +4400,10 @@
44044400
"type": "string",
44054401
"default": ""
44064402
},
4403+
"serviceAccountName": {
4404+
"description": "ServiceAccountName is the name of the ServiceAccount for creating DataVolumes.",
4405+
"type": "string"
4406+
},
44074407
"template": {
44084408
"description": "Template specifies template for the DVs to be created",
44094409
"default": {},

pkg/apis/core/v1beta1/openapi_generated.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apiserver/apiserver.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ const (
7979

8080
dataImportCronValidatePath = "/dataimportcron-validate"
8181

82-
dataImportCronMutatePath = "/dataimportcron-mutate"
83-
8482
populatorValidatePath = "/populator-validate"
8583

8684
healthzPath = "/healthz"
@@ -216,11 +214,6 @@ func NewCdiAPIServer(bindAddress string,
216214
return nil, errors.Errorf("failed to create DataImportCron validating webhook: %s", err)
217215
}
218216

219-
err = app.createDataImportCronMutatingWebhook()
220-
if err != nil {
221-
return nil, errors.Errorf("failed to create DataImportCron mutating webhook: %s", err)
222-
}
223-
224217
err = app.createPopulatorValidatingWebhook()
225218
if err != nil {
226219
return nil, errors.Errorf("failed to create Populator validating webhook: %s", err)
@@ -563,11 +556,6 @@ func (app *cdiAPIApp) createDataImportCronValidatingWebhook() error {
563556
return nil
564557
}
565558

566-
func (app *cdiAPIApp) createDataImportCronMutatingWebhook() error {
567-
app.container.ServeMux.Handle(dataImportCronMutatePath, webhooks.NewDataImportCronMutatingWebhook())
568-
return nil
569-
}
570-
571559
func (app *cdiAPIApp) createPopulatorValidatingWebhook() error {
572560
app.container.ServeMux.Handle(populatorValidatePath, webhooks.NewPopulatorValidatingWebhook(app.client, app.cdiClient))
573561
return nil

pkg/apiserver/webhooks/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go_library(
44
name = "go_default_library",
55
srcs = [
66
"cdi-validate.go",
7-
"dataimportcron-mutate.go",
87
"dataimportcron-validate.go",
98
"datavolume-mutate.go",
109
"datavolume-validate.go",
@@ -30,7 +29,6 @@ go_library(
3029
"//vendor/github.com/robfig/cron/v3:go_default_library",
3130
"//vendor/k8s.io/api/admission/v1:go_default_library",
3231
"//vendor/k8s.io/api/admissionregistration/v1:go_default_library",
33-
"//vendor/k8s.io/api/authentication/v1:go_default_library",
3432
"//vendor/k8s.io/api/authorization/v1:go_default_library",
3533
"//vendor/k8s.io/api/core/v1:go_default_library",
3634
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
@@ -53,7 +51,6 @@ go_test(
5351
name = "go_default_test",
5452
srcs = [
5553
"cdi-validate_test.go",
56-
"dataimportcron-mutate_test.go",
5754
"dataimportcron-validate_test.go",
5855
"datavolume-mutate_test.go",
5956
"datavolume-validate_test.go",
@@ -73,7 +70,6 @@ go_test(
7370
"//vendor/github.com/onsi/ginkgo/v2:go_default_library",
7471
"//vendor/github.com/onsi/gomega:go_default_library",
7572
"//vendor/k8s.io/api/admission/v1:go_default_library",
76-
"//vendor/k8s.io/api/authentication/v1:go_default_library",
7773
"//vendor/k8s.io/api/authorization/v1:go_default_library",
7874
"//vendor/k8s.io/api/core/v1:go_default_library",
7975
"//vendor/k8s.io/api/storage/v1:go_default_library",

pkg/apiserver/webhooks/dataimportcron-mutate.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

pkg/apiserver/webhooks/dataimportcron-mutate_test.go

Lines changed: 0 additions & 129 deletions
This file was deleted.

pkg/apiserver/webhooks/dataimportcron-validate.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,5 @@ func (wh *dataImportCronValidatingWebhook) validateDataImportCronSpec(request *a
161161
return causes
162162
}
163163

164-
if request.Operation == admissionv1.Create {
165-
userInfoStr, err := getUserInfoString(&request.UserInfo)
166-
if err != nil {
167-
causes = append(causes, metav1.StatusCause{
168-
Type: metav1.CauseTypeInternal,
169-
Message: fmt.Sprintf("Cannot marshal UserInfo to string: %v", err),
170-
Field: field.Child("CreatedBy").String(),
171-
})
172-
return causes
173-
}
174-
if spec.CreatedBy != nil && *userInfoStr != *spec.CreatedBy {
175-
causes = append(causes, metav1.StatusCause{
176-
Type: metav1.CauseTypeForbidden,
177-
Message: "CreatedBy field is set automatically and cannot be specified by users",
178-
Field: field.Child("CreatedBy").String(),
179-
})
180-
return causes
181-
}
182-
}
183-
184164
return causes
185165
}

pkg/apiserver/webhooks/dataimportcron-validate_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ var _ = Describe("Validating Webhook", func() {
148148
resp := validateDataImportCronCreate(cron)
149149
Expect(resp.Allowed).To(BeFalse())
150150
})
151-
It("should reject DataImportCron with CreatedBy field set by user on create", func() {
152-
cron := newDataImportCron(cdiv1.DataVolumeSourceRegistry{URL: &testRegistryURL})
153-
createdBy := `{"username":"hacker"}`
154-
cron.Spec.CreatedBy = &createdBy
155-
resp := validateDataImportCronCreate(cron)
156-
Expect(resp.Allowed).To(BeFalse())
157-
Expect(resp.Result.Message).To(ContainSubstring("CreatedBy field is set automatically"))
158-
})
159151
It("should reject invalid DataImportCron spec update", func() {
160152
newCron := newDataImportCron(cdiv1.DataVolumeSourceRegistry{URL: &testRegistryURL})
161153
newBytes, _ := json.Marshal(&newCron)

pkg/apiserver/webhooks/handler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ func NewDataImportCronValidatingWebhook(k8sClient kubernetes.Interface, cdiClien
9191
return newAdmissionHandler(&dataImportCronValidatingWebhook{dataVolumeValidatingWebhook{k8sClient: k8sClient, cdiClient: cdiClient}})
9292
}
9393

94-
// NewDataImportCronMutatingWebhook creates a new DataImportCron mutating webhook
95-
func NewDataImportCronMutatingWebhook() http.Handler {
96-
return newAdmissionHandler(&dataImportCronMutatingWebhook{})
97-
}
98-
9994
// NewPopulatorValidatingWebhook creates a new DataVolumeValidation webhook
10095
func NewPopulatorValidatingWebhook(k8sClient kubernetes.Interface, cdiClient cdiclient.Interface) http.Handler {
10196
return newAdmissionHandler(&populatorValidatingWebhook{dataVolumeValidatingWebhook{k8sClient: k8sClient, cdiClient: cdiClient}})

pkg/controller/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ go_library(
4040
"//vendor/github.com/pkg/errors:go_default_library",
4141
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
4242
"//vendor/github.com/robfig/cron/v3:go_default_library",
43-
"//vendor/k8s.io/api/authentication/v1:go_default_library",
4443
"//vendor/k8s.io/api/authorization/v1:go_default_library",
4544
"//vendor/k8s.io/api/batch/v1:go_default_library",
4645
"//vendor/k8s.io/api/core/v1:go_default_library",

0 commit comments

Comments
 (0)