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.
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?
There was a problem hiding this comment.
Done, in the nested form: with for the name, and the rest of the chain under its else. All eight combinations of rbac.enabled × serviceaccount.create × serviceaccount.name render the same as before.
| {{- 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?
There was a problem hiding this comment.
I kept it (option 1). The helper's comment now says where it comes from: it's the default rbac.serviceaccount.name had up to chart 9.4.1, kept so installs with rbac.enabled keep their account on upgrade. If you'd rather have option 2, a shared default in values.yaml, I'll switch.
There was a problem hiding this comment.
to avoid conflicts we should use {{ template "nextcloud.fullname" . }} like on every manifest.
There was a problem hiding this comment.
Done: no more literal. The account is now rbac.serviceaccount.name when set, otherwise {{ template "nextcloud.fullname" . }} when the chart creates it, otherwise default, so it no longer depends on rbac.enabled.
That changes upgrades for installs with rbac.enabled and no name: their account moves from nextcloud-serviceaccount to the release's full name, the RoleBinding follows, and the pods roll out once. Setting rbac.serviceaccount.name: nextcloud-serviceaccount keeps the old one; with create: false a name is now needed. The commit message and the description say so. Rebased onto 9.4.3, chart 9.5.0.
eb3b63a to
f1fbcc8
Compare
…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, as the chart's other objects are named, 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 without a name used nextcloud-serviceaccount, the previous default of rbac.serviceaccount.name. They now get the release's full name too: the chart creates that account and moves its RoleBinding to it, and the pods roll out once on upgrade. To keep the old account, set rbac.serviceaccount.name: nextcloud-serviceaccount; with create set to false that is required, as for any existing account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Martin Matyas <martin.matyas@tieto.com>
f1fbcc8 to
566d2a1
Compare
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; otherwise the release's full name when the chart creates the account, as its other objects are named; 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.enabledwithout a name usednextcloud-serviceaccount. They now get the release's full name as well (as asked in review, so two releases in one namespace don't collide): the chart creates that account, moves its RoleBinding to it, and the pods roll out once. To keep the old account, setrbac.serviceaccount.name: nextcloud-serviceaccount; withcreate: falsethat is required, as for any existing account.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 fc36d83 (7 Nov, Nextcloud 35.0.2). Verified on a fork:rbac.enabled×serviceaccount.create×serviceaccount.namerendered againstmain: a named account is used as given; otherwise the release's own account when the chart creates it, ordefaultwithcreate: false; the pods and therbac.enabledRoleBinding always name the same account.helm linton the defaults and all ninetest-valuessets.ct lintand all eight install cases pass (run 42389401742).rbac.enabledinstalls' account:helm upgradefrommainon kind, with the live Deployment pod template diffed before and after (run 42389401502): 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