Skip to content

Commit f8ed6f5

Browse files
authored
[Bugfix] Allow limited rbac scope (#940)
1 parent c338414 commit f8ed6f5

File tree

22 files changed

+50
-62
lines changed

22 files changed

+50
-62
lines changed

chart/kube-arangodb/templates/deployment-operator/role.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ metadata:
1414
release: {{ .Release.Name }}
1515
rules:
1616
- apiGroups: ["database.arangodb.com"]
17-
resources: ["arangodeployments", "arangodeployments/status","arangomembers", "arangomembers/status", "arangoclustersynchronizations", "arangoclustersynchronizations/status", "arangotasks", "arangotasks/status"]
17+
resources: ["arangodeployments", "arangodeployments/status","arangomembers", "arangomembers/status"]
1818
verbs: ["*"]
19+
{{- if .Values.rbac.extensions.acs }}
20+
- apiGroups: ["database.arangodb.com"]
21+
resources: ["arangoclustersynchronizations", "arangoclustersynchronizations/status"]
22+
verbs: ["*"]
23+
{{- end }}
24+
{{- if .Values.rbac.extensions.at }}
25+
- apiGroups: ["database.arangodb.com"]
26+
resources: ["arangotasks", "arangotasks/status"]
27+
verbs: ["*"]
28+
{{- end }}
1929
- apiGroups: [""]
2030
resources: ["pods", "services", "endpoints", "persistentvolumeclaims", "events", "secrets", "serviceaccounts"]
2131
verbs: ["*"]
@@ -28,9 +38,11 @@ rules:
2838
- apiGroups: ["backup.arangodb.com"]
2939
resources: ["arangobackuppolicies", "arangobackups"]
3040
verbs: ["get", "list", "watch"]
41+
{{- if .Values.rbac.extensions.monitoring }}
3142
- apiGroups: ["monitoring.coreos.com"]
3243
resources: ["servicemonitors"]
3344
verbs: ["get", "create", "delete", "update", "list", "watch", "patch"]
34-
45+
46+
{{- end }}
3547
{{- end }}
3648
{{- end }}

chart/kube-arangodb/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ operator:
5454
tolerations: []
5555

5656
rbac:
57-
enabled: true
57+
enabled: true
58+
extensions:
59+
monitoring: true
60+
acs: true
61+
at: true

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/arangodb/go-driver v1.2.1
2929
github.com/arangodb/go-driver/v2 v2.0.0-20211021031401-d92dcd5a4c83
3030
github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21
31+
github.com/arangodb/rebalancer v0.1.1
3132
github.com/cenkalti/backoff v2.2.1+incompatible
3233
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
3334
github.com/ghodss/yaml v1.0.0
@@ -108,3 +109,5 @@ require (
108109
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
109110
sigs.k8s.io/yaml v1.2.0 // indirect
110111
)
112+
113+
require github.com/arangodb/rebalancer v0.1.1

pkg/deployment/context_impl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func (d *Deployment) getAuth() (driver.Authentication, error) {
262262
return nil, nil
263263
}
264264

265+
if !d.GetCachedStatus().Initialised() {
266+
return nil, errors.Newf("Cache is not yet started")
267+
}
268+
265269
var secret string
266270
var found bool
267271

pkg/deployment/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import (
6464
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
6565
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
6666
"github.com/arangodb/kube-arangodb/pkg/util/trigger"
67+
apierrors "k8s.io/apimachinery/pkg/api/errors"
6768
)
6869

6970
// Config holds configuration settings for a Deployment
@@ -604,6 +605,9 @@ func (d *Deployment) lookForServiceMonitorCRD() {
604605
var err error
605606
if d.GetScope().IsNamespaced() {
606607
_, err = d.currentState.ServiceMonitor().V1()
608+
if apierrors.IsForbidden(err) {
609+
return
610+
}
607611
} else {
608612
_, err = d.deps.Client.KubernetesExtensions().ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), "servicemonitors.monitoring.coreos.com", meta.GetOptions{})
609613
}

pkg/deployment/resources/annotations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/rs/zerolog/log"
3838
core "k8s.io/api/core/v1"
3939
policy "k8s.io/api/policy/v1beta1"
40+
apierrors "k8s.io/apimachinery/pkg/api/errors"
4041
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
4142
)
4243

@@ -239,6 +240,9 @@ func ensurePvcsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Insp
239240
func ensureServiceMonitorsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Inspector, kind, name, namespace string, spec api.DeploymentSpec) error {
240241
i, err := cachedStatus.ServiceMonitor().V1()
241242
if err != nil {
243+
if apierrors.IsForbidden(err) {
244+
return nil
245+
}
242246
return err
243247
}
244248
if err := i.Iterate(func(serviceMonitor *monitoring.ServiceMonitor) error {

pkg/deployment/resources/inspector/acs.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ func (p *arangoClusterSynchronizationsInspector) LastRefresh() time.Time {
163163
return p.last
164164
}
165165

166-
func (p *arangoClusterSynchronizationsInspector) IsStatic() bool {
167-
return p.state.IsStatic()
168-
}
169-
170166
func (p *arangoClusterSynchronizationsInspector) Refresh(ctx context.Context) error {
171167
p.Throttle(p.state.throttles).Invalidate()
172168
return p.state.refresh(ctx, arangoClusterSynchronizationsInspectorLoaderObj)

pkg/deployment/resources/inspector/am.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ func (p *arangoMembersInspector) LastRefresh() time.Time {
167167
return p.last
168168
}
169169

170-
func (p *arangoMembersInspector) IsStatic() bool {
171-
return p.state.IsStatic()
172-
}
173-
174170
func (p *arangoMembersInspector) Refresh(ctx context.Context) error {
175171
p.Throttle(p.state.throttles).Invalidate()
176172
return p.state.refresh(ctx, arangoMembersInspectorLoaderObj)

pkg/deployment/resources/inspector/at.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ func (p *arangoTasksInspector) LastRefresh() time.Time {
163163
return p.last
164164
}
165165

166-
func (p *arangoTasksInspector) IsStatic() bool {
167-
return p.state.IsStatic()
168-
}
169-
170166
func (p *arangoTasksInspector) Refresh(ctx context.Context) error {
171167
p.Throttle(p.state.throttles).Invalidate()
172168
return p.state.refresh(ctx, arangoTasksInspectorLoaderObj)

pkg/deployment/resources/inspector/inspector.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ type inspectorState struct {
139139

140140
versionInfo driver.Version
141141

142-
static bool
142+
initialised bool
143+
}
144+
145+
func (i *inspectorState) Initialised() bool {
146+
if i == nil {
147+
return false
148+
}
149+
150+
return i.initialised
143151
}
144152

145153
func (i *inspectorState) Client() kclient.Client {
@@ -210,15 +218,7 @@ func (i *inspectorState) Pod() pod.Definition {
210218
return i.pods
211219
}
212220

213-
func (i *inspectorState) IsStatic() bool {
214-
return i.static
215-
}
216-
217221
func (i *inspectorState) refresh(ctx context.Context, loaders ...inspectorLoader) error {
218-
if i.IsStatic() {
219-
return nil
220-
}
221-
222222
return i.refreshInThreads(ctx, 15, loaders...)
223223
}
224224

@@ -295,6 +295,7 @@ func (i *inspectorState) refreshInThreads(ctx context.Context, threads int, load
295295
i.throttles = n.throttles
296296

297297
i.last = time.Now()
298+
i.initialised = true
298299

299300
return nil
300301
}
@@ -364,7 +365,6 @@ func (i *inspectorState) copyCore() *inspectorState {
364365
arangoClusterSynchronizations: i.arangoClusterSynchronizations,
365366
throttles: i.throttles.Copy(),
366367
versionInfo: i.versionInfo,
367-
static: i.static,
368368
logger: i.logger,
369369
}
370370
}

0 commit comments

Comments
 (0)