Repository navigation
fix(nextcloud): run the pods as the chart's own service account by default - #896
martin-mat wants to merge 1 commit into
Conversation
| {{- if .Values.rbac.serviceaccount.create -}} | ||
| {{- default (include "nextcloud.fullname" .) .Values.rbac.serviceaccount.name -}} | ||
| {{- else -}} | ||
| {{- required "rbac.serviceaccount.name must name an existing service account when rbac.serviceaccount.create is false" .Values.rbac.serviceaccount.name -}} |
There was a problem hiding this comment.
there ia no fallback to namespace default service-account. you drop rbac.enabled
There was a problem hiding this comment.
Thanks, you're right on both counts, and the first version also failed the install with create: false and no name. Both are fixed in the rebased commit:
- With
rbac.serviceaccount.create: falseand no name, the pods run as the namespace'sdefaultaccount again, as before. - Installs with
rbac.enabledkeepnextcloud-serviceaccountwhether the chart creates it or an existing one is used. I had defaulted the name to the release's full name everywhere; that would have renamed the account of every install that setrbac.enabled, which is the only way to get a dedicated account today. Now the release's full name is the default only where there was no account before.
So rbac.enabled still controls the Role and RoleBinding for the PodSecurityPolicy, and installs that set it are unchanged: I rendered all eight combinations of rbac.enabled × create × name against main, and every rbac.enabled one is identical to main down to the full manifest. On kind, upgrading an rbac.enabled install (also with create: false on a pre-created account) from main leaves the pod template identical and rolls nothing; a default install gets <release>-nextcloud and rolls once. Details and run links in the description.
…fault The chart creates a service account only with rbac.enabled, which is off by default, so the Nextcloud pods run as the namespace's default service account. rbac.enabled binds the privileged PodSecurityPolicy, which Kubernetes removed in 1.25; the account itself has nothing to do with it. The service account is now created whenever rbac.serviceaccount.create is true (the default), whatever rbac.enabled says, and the Nextcloud Deployment and the cron CronJob always run as it. Its name defaults to the release's full name, so two releases in one namespace don't collide; a name set in rbac.serviceaccount.name is kept. With create set to false the pods run as the account named there, or as the namespace's default account when no name is given, as before. Installs that set rbac.enabled are unchanged: with no name set they keep nextcloud-serviceaccount, the previous default, whether the chart creates it or an existing one is used, so their account, and anything bound to its name outside the chart, stays as it is on upgrade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Martin Matyas <martin.matyas@tieto.com>
edbe17e to
eb3b63a
Compare
| account. | ||
| */}} | ||
| {{- define "nextcloud.serviceAccountName" -}} | ||
| {{- if .Values.rbac.serviceaccount.name -}} |
There was a problem hiding this comment.
| {{- if .Values.rbac.serviceaccount.name -}} | |
| {{- with .Values.rbac.serviceaccount.name -}} | |
| {{ . }} |
There was a problem hiding this comment.
Thanks. One thing before I change it: the rest of the helper is an else if chain, and in Go templates with can only be followed by else or else with, not else if, so the suggestion as written doesn't parse (parse error at (nextcloud/templates/_helpers.tpl:495): unexpected <if> in input, helm v4.3.1). Using with would mean nesting the rest of the chain under an else, one level deeper:
{{- with .Values.rbac.serviceaccount.name -}}
{{ . }}
{{- else -}}
{{- if .Values.rbac.enabled -}}
nextcloud-serviceaccount
{{- else if .Values.rbac.serviceaccount.create -}}
{{- include "nextcloud.fullname" . -}}
{{- else -}}
default
{{- end -}}
{{- end -}}
Both forms render identically for all eight combinations of rbac.enabled × create × name (run). I find the flat if chain easier to read; would you like to keep it, or should I switch to the nested with?
| {{- if .Values.rbac.serviceaccount.name -}} | ||
| {{- .Values.rbac.serviceaccount.name -}} | ||
| {{- else if .Values.rbac.enabled -}} | ||
| nextcloud-serviceaccount |
There was a problem hiding this comment.
where this value come from?
There was a problem hiding this comment.
It's the default rbac.serviceaccount.name had in values.yaml until this change (name: nextcloud-serviceaccount, line 1104 on main). This PR sets that default to "" so that a new install gets its own <release>-nextcloud account, but an install that set rbac.enabled: true and kept the default name has always run as nextcloud-serviceaccount; without the literal here, upgrading it would rename its service account and roll the pods. So it's there for those installs only.
Two ways to go from here:
- Keep it, with a line in the helper's comment saying where the name comes from.
- Keep
nextcloud-serviceaccountas the default invalues.yamland use it for every install: no name in the helper, but every release in a namespace shares one account name, so two releases there would collide.
Which do you prefer?
Description of the change
The chart's service account is now created whenever
rbac.serviceaccount.createis true (the default), independent ofrbac.enabled, and the Nextcloud Deployment and the cron CronJob always run as it:templates/serviceaccount.yaml: rendered onrbac.serviceaccount.createalone.templates/_helpers.tpl: anextcloud.serviceAccountNamehelper. The name isrbac.serviceaccount.namewhen set; otherwisenextcloud-serviceaccount, the previous default, whenrbac.enabledis set, so installs that enabled rbac keep their account; otherwise the release's full name; withcreate: falseand no name, the namespace'sdefaultaccount, as before.templates/deployment.yaml,templates/cronjob.yaml:serviceAccountNamealways set from the helper;templates/rbac.yaml: the RoleBinding subject from the same helper.values.yaml:rbac.serviceaccount.namedefaults to"", with comments; README rows corrected; chart 9.4.1 → 9.5.0.The PSP Role behind
rbac.enabledis unchanged.Benefits
The pods no longer run as the namespace's
defaultservice account, so:rbac.serviceaccount.annotationsworks withoutrbac.enabled, for cloud identity (IRSA, Workload Identity) to S3 primary storage;dedicated_service_accounttest are satisfied.Two releases in one namespace no longer collide on a fixed account name.
Possible drawbacks
rbac.enabledare unchanged: they keepnextcloud-serviceaccount, and the pod template is identical, so nothing rolls on upgrade.rbac.serviceaccount.nameset withoutrbac.enabledis now used, where the chart ignored it before; withcreate: falsethat account has to exist.Applicable issues
Additional information
Rebased onto
mainat cc9a089 (Nextcloud 35.0.2). Verified on a fork:rbac.enabled×serviceaccount.create×serviceaccount.namerendered againstmain: everyrbac.enabledcombination renders identically tomain(the full manifest differs only in thehelm.sh/chartlabel), the others get the release's own account, ordefault/the named account withcreate: false.helm linton the defaults and all ninetest-valuessets.ct lintand all eight install cases pass (run 39388756623).helm upgradefrommainon kind, with the live Deployment pod template diffed before and after (run 39388760172): defaults get<release>-nextcloudand roll once (the diff isserviceAccountNamealone);rbac.enabled, with and withoutcreate: falseon a pre-created account, keepnextcloud-serviceaccountwith an identical pod template and no rollout. Nextcloud answers on/status.phpin all three.dedicated_service_accountfails onmainand passes with this change; the essential tests are unchanged at 15 of 19.Checklist
Chart.yamlaccording to semver.🤖 Generated with Claude Code