Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Bind the Role to the Cluster's service account, honoring spec.serviceAccountName

未关闭 适合新手
#1,117 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, kubernetes

调研方向

从 BuildRoleBinding 及其单元测试开始,然后检查 EnsureRoleBinding,以了解 Subjects 是如何协调的。验证默认的 Cluster-name subject 和 spec.serviceAccountName subject,同时保留现有的 RoleRef;两种情况下测试都应通过。

由索引模型根据 Issue 内容生成。

描述

Problem

BuildRoleBinding always binds the <cluster>-barman-cloud Role to a ServiceAccount named after the Cluster (cluster.Name). When a Cluster sets spec.serviceAccountName, the instance pods run as that account instead, so the RoleBinding points at an account nobody uses. The sidecar then can't read the ObjectStore or its Secrets:

objectstores.barmancloud.cnpg.io "<name>" is forbidden: User "system:serviceaccount:<ns>:<shared-sa>" cannot get resource "objectstores" ...

As a result, WAL archiving and backups fail, and a replica restoring from the archive can't start.

A shared service account is how you use cloud workload identity (Azure Workload Identity, EKS IRSA/Pod Identity, GKE Workload Identity) with a service account whose name stays stable. The federated credential or IAM binding is tied to the service account's name, so a per-Cluster account means creating a new cloud-side credential every time a Cluster is renamed, recreated for a major upgrade, or recovered under a new name. The CNPG operator's own RoleBinding already follows spec.serviceAccountName. Only the plugin's doesn't.

The current workaround is a hand-written RoleBinding for each Cluster that grants the plugin's Role to the shared account.

Fix

Use cluster.GetServiceAccountName() (from the CNPG API) for the RoleBinding subject. It returns spec.serviceAccountName when set and falls back to cluster.Name otherwise, so Clusters that don't set the field keep exactly the same RoleBinding they have today.

Existing Clusters that already set spec.serviceAccountName also pick up the fix on the next reconcile. EnsureRoleBinding treats Subjects as additive, so it adds the correct account alongside the old per-Cluster one without removing anything.

Tests

Added BuildRoleBinding unit tests covering:

  • the default, where the subject is the Cluster name
  • spec.serviceAccountName set, where the subject is that account and the RoleRef is unchanged

Related: #649 (Azure Workload Identity setup questions)

主要语言
Go
星标
196
派生
76
平均合并
1 天 10 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cloudnative-pg/plugin-barman-cloud 的其他 Issue

查看 cloudnative-pg/plugin-barman-cloud 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。