Skip to content

Commit 920432f

Browse files
committed
Use operator-controller SA by default, make SA field optional
Changes the ClusterExtension API field spec.ServiceAccount to be optional. Operator-controller will use its own service account by default unless the spec.ServiceAccount field is set. RBAC PreAuthorization only happens if the optional SA field is set, as well. Give operator-controller's SA cluster-admin by default.
1 parent d204888 commit 920432f

File tree

10 files changed

+33
-52
lines changed

10 files changed

+33
-52
lines changed

api/v1/clusterextension_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ type ClusterExtensionSpec struct {
6767
// +kubebuilder:validation:Required
6868
Namespace string `json:"namespace"`
6969

70-
// serviceAccount is a reference to a ServiceAccount used to perform all interactions
71-
// with the cluster that are required to manage the extension.
70+
// serviceAccount is an optional field that references a ServiceAccount used to
71+
// perform all interactions with the cluster that are required to manage the extension.
72+
// If not set, operator-controller will use its own ServiceAccount for extension management.
7273
// The ServiceAccount must be configured with the necessary permissions to perform these interactions.
7374
// The ServiceAccount must exist in the namespace referenced in the spec.
74-
// serviceAccount is required.
7575
//
76-
// +kubebuilder:validation:Required
77-
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
76+
// +optional
77+
ServiceAccount ServiceAccountReference `json:"serviceAccount,omitzero"`
7878

7979
// source is a required field which selects the installation source of content
8080
// for this ClusterExtension. Selection is performed by setting the sourceType.
@@ -374,7 +374,7 @@ type CatalogFilter struct {
374374
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
375375
}
376376

377-
// ServiceAccountReference identifies the serviceAccount used fo install a ClusterExtension.
377+
// ServiceAccountReference identifies the serviceAccount used to install a ClusterExtension.
378378
type ServiceAccountReference struct {
379379
// name is a required, immutable reference to the name of the ServiceAccount
380380
// to be used for installation and management of the content for the package
@@ -403,7 +403,7 @@ type ServiceAccountReference struct {
403403
// +kubebuilder:validation:MaxLength:=253
404404
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
405405
// +kubebuilder:validation:XValidation:rule="self.matches(\"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$\")",message="name must be a valid DNS1123 subdomain. It must contain only lowercase alphanumeric characters, hyphens (-) or periods (.), start and end with an alphanumeric character, and be no longer than 253 characters"
406-
// +kubebuilder:validation:Required
406+
// +kubebuilder:validation:Optional
407407
Name string `json:"name"`
408408
}
409409

helm/olmv1/base/operator-controller/crd/experimental/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ spec:
171171
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
172172
serviceAccount:
173173
description: |-
174-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
175-
with the cluster that are required to manage the extension.
174+
serviceAccount is an optional field that references a ServiceAccount used to
175+
perform all interactions with the cluster that are required to manage the extension.
176+
If not set, operator-controller will use its own ServiceAccount for extension management.
176177
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
177178
The ServiceAccount must exist in the namespace referenced in the spec.
178-
serviceAccount is required.
179179
properties:
180180
name:
181181
description: |-
@@ -212,8 +212,6 @@ spec:
212212
(.), start and end with an alphanumeric character, and be
213213
no longer than 253 characters
214214
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
215-
required:
216-
- name
217215
type: object
218216
source:
219217
description: |-
@@ -498,7 +496,6 @@ spec:
498496
has(self.catalog) : !has(self.catalog)'
499497
required:
500498
- namespace
501-
- serviceAccount
502499
- source
503500
type: object
504501
status:

helm/olmv1/base/operator-controller/crd/standard/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ spec:
132132
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
133133
serviceAccount:
134134
description: |-
135-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
136-
with the cluster that are required to manage the extension.
135+
serviceAccount is an optional field that references a ServiceAccount used to
136+
perform all interactions with the cluster that are required to manage the extension.
137+
If not set, operator-controller will use its own ServiceAccount for extension management.
137138
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
138139
The ServiceAccount must exist in the namespace referenced in the spec.
139-
serviceAccount is required.
140140
properties:
141141
name:
142142
description: |-
@@ -173,8 +173,6 @@ spec:
173173
(.), start and end with an alphanumeric character, and be
174174
no longer than 253 characters
175175
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
176-
required:
177-
- name
178176
type: object
179177
source:
180178
description: |-
@@ -459,7 +457,6 @@ spec:
459457
has(self.catalog) : !has(self.catalog)'
460458
required:
461459
- namespace
462-
- serviceAccount
463460
- source
464461
type: object
465462
status:

helm/olmv1/templates/rbac/clusterrolebinding-operator-controller-manager-rolebinding.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ metadata:
88
labels:
99
app.kubernetes.io/name: operator-controller
1010
{{- include "olmv1.labels" $ | nindent 4 }}
11-
{{- if has "BoxcutterRuntime" .Values.options.operatorController.features.enabled }}
12-
name: operator-controller-manager-admin-rolebinding
13-
{{- else }}
1411
name: operator-controller-manager-rolebinding
15-
{{- end }}
1612
roleRef:
1713
apiGroup: rbac.authorization.k8s.io
1814
kind: ClusterRole
19-
{{- if has "BoxcutterRuntime" .Values.options.operatorController.features.enabled }}
2015
name: cluster-admin
21-
{{- else }}
22-
name: operator-controller-manager-role
23-
{{- end }}
2416
subjects:
2517
- kind: ServiceAccount
2618
name: operator-controller-controller-manager

internal/operator-controller/action/restconfig.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func ServiceAccountRestConfigMapper(tokenGetter *authentication.TokenGetter) fun
4444
if err != nil {
4545
return nil, err
4646
}
47+
48+
// If ServiceAccount is not set, just use operator-controller's service account
49+
if cExt.Spec.ServiceAccount.Name == "" {
50+
return c, nil
51+
}
52+
4753
saConfig := rest.AnonymousClientConfig(c)
4854
saConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper {
4955
return &authentication.TokenInjectingRoundTripper{

internal/operator-controller/applier/helm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func (h *Helm) Apply(ctx context.Context, contentFS fs.FS, ext *ocv1.ClusterExte
113113
labels: objectLabels,
114114
}
115115

116-
if h.PreAuthorizer != nil {
116+
// Only run pre-Authorization if optional ServiceAccount field name is set
117+
if h.PreAuthorizer != nil && ext.Spec.ServiceAccount.Name != "" {
117118
err := h.runPreAuthorizationChecks(ctx, ext, chrt, values, post)
118119
if err != nil {
119120
// Return the pre-authorization error directly

manifests/experimental-e2e.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,11 @@ spec:
976976
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
977977
serviceAccount:
978978
description: |-
979-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
980-
with the cluster that are required to manage the extension.
979+
serviceAccount is an optional field that references a ServiceAccount used to
980+
perform all interactions with the cluster that are required to manage the extension.
981+
If not set, operator-controller will use its own ServiceAccount for extension management.
981982
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
982983
The ServiceAccount must exist in the namespace referenced in the spec.
983-
serviceAccount is required.
984984
properties:
985985
name:
986986
description: |-
@@ -1017,8 +1017,6 @@ spec:
10171017
(.), start and end with an alphanumeric character, and be
10181018
no longer than 253 characters
10191019
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
1020-
required:
1021-
- name
10221020
type: object
10231021
source:
10241022
description: |-
@@ -1303,7 +1301,6 @@ spec:
13031301
has(self.catalog) : !has(self.catalog)'
13041302
required:
13051303
- namespace
1306-
- serviceAccount
13071304
- source
13081305
type: object
13091306
status:

manifests/experimental.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,11 @@ spec:
941941
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
942942
serviceAccount:
943943
description: |-
944-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
945-
with the cluster that are required to manage the extension.
944+
serviceAccount is an optional field that references a ServiceAccount used to
945+
perform all interactions with the cluster that are required to manage the extension.
946+
If not set, operator-controller will use its own ServiceAccount for extension management.
946947
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
947948
The ServiceAccount must exist in the namespace referenced in the spec.
948-
serviceAccount is required.
949949
properties:
950950
name:
951951
description: |-
@@ -982,8 +982,6 @@ spec:
982982
(.), start and end with an alphanumeric character, and be
983983
no longer than 253 characters
984984
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
985-
required:
986-
- name
987985
type: object
988986
source:
989987
description: |-
@@ -1268,7 +1266,6 @@ spec:
12681266
has(self.catalog) : !has(self.catalog)'
12691267
required:
12701268
- namespace
1271-
- serviceAccount
12721269
- source
12731270
type: object
12741271
status:

manifests/standard-e2e.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,11 @@ spec:
723723
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
724724
serviceAccount:
725725
description: |-
726-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
727-
with the cluster that are required to manage the extension.
726+
serviceAccount is an optional field that references a ServiceAccount used to
727+
perform all interactions with the cluster that are required to manage the extension.
728+
If not set, operator-controller will use its own ServiceAccount for extension management.
728729
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
729730
The ServiceAccount must exist in the namespace referenced in the spec.
730-
serviceAccount is required.
731731
properties:
732732
name:
733733
description: |-
@@ -764,8 +764,6 @@ spec:
764764
(.), start and end with an alphanumeric character, and be
765765
no longer than 253 characters
766766
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
767-
required:
768-
- name
769767
type: object
770768
source:
771769
description: |-
@@ -1050,7 +1048,6 @@ spec:
10501048
has(self.catalog) : !has(self.catalog)'
10511049
required:
10521050
- namespace
1053-
- serviceAccount
10541051
- source
10551052
type: object
10561053
status:

manifests/standard.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,11 @@ spec:
688688
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
689689
serviceAccount:
690690
description: |-
691-
serviceAccount is a reference to a ServiceAccount used to perform all interactions
692-
with the cluster that are required to manage the extension.
691+
serviceAccount is an optional field that references a ServiceAccount used to
692+
perform all interactions with the cluster that are required to manage the extension.
693+
If not set, operator-controller will use its own ServiceAccount for extension management.
693694
The ServiceAccount must be configured with the necessary permissions to perform these interactions.
694695
The ServiceAccount must exist in the namespace referenced in the spec.
695-
serviceAccount is required.
696696
properties:
697697
name:
698698
description: |-
@@ -729,8 +729,6 @@ spec:
729729
(.), start and end with an alphanumeric character, and be
730730
no longer than 253 characters
731731
rule: self.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
732-
required:
733-
- name
734732
type: object
735733
source:
736734
description: |-
@@ -1015,7 +1013,6 @@ spec:
10151013
has(self.catalog) : !has(self.catalog)'
10161014
required:
10171015
- namespace
1018-
- serviceAccount
10191016
- source
10201017
type: object
10211018
status:

0 commit comments

Comments
 (0)