Skip to content

[rbac] Use hierarchical naming scheme - #2019

Merged
Timofei Larkin (lllamnyp) merged 1 commit into
mainfrom
chore/refactor-rbac
Feb 11, 2026
Merged

Timofei Larkin (lllamnyp) merged 1 commit into
mainfrom
chore/refactor-rbac

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Feb 10, 2026 •

Copy link
Copy Markdown
Member

What this PR does

This patch improves the naming conventions used in Cozystack's RBAC resources. It follows the k8s system convention of using colons as separators in RBAC resource names (e.g. system:nodes:) and renames some default tenant clusterroles to a scheme like cozy:tenant:admin.

Release note

[rbac] Use a more structured naming convention for Cozystack's RBAC
resources.

Summary by CodeRabbit

  • Chores
    • Standardized Kubernetes role and binding names to a colon-delimited "cozy:tenant:*" format.
    • Applied naming updates across tenant RBAC, cluster-wide roles, and dashboard role resources.
    • Preserved existing permissions, namespaces, and behavior while improving naming consistency across system configurations.

@dosubot dosubot Bot added size/M This PR changes 30-99 lines, ignoring generated files kind/feature Categorizes issue or PR as related to a new feature labels Feb 10, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Timofei Larkin (@lllamnyp), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request standardizes the naming scheme for Cozystack's RBAC resources, aligning them with Kubernetes' hierarchical naming conventions. By replacing hyphens with colons in resource names like cozy:tenant:admin, the changes enhance readability, maintainability, and consistency across the RBAC configuration, making it easier to understand the relationships and scope of different roles.

Highlights

  • RBAC Naming Convention: Adopted a hierarchical naming scheme for Cozystack's RBAC resources, utilizing colons as separators (e.g., cozy:tenant:admin) to align with Kubernetes system conventions.
  • ClusterRole and Role Renaming: Renamed several default tenant ClusterRoles and Roles across tenant.yaml, clusterroles.yaml, and dashboard-role.yaml to reflect the new cozy:tenant: prefix and hierarchical structure.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/apps/tenant/templates/tenant.yaml
    • Updated roleRef.name for cozy-tenant to cozy:tenant.
    • Updated roleRef.name for cozy-tenant-view to cozy:tenant:view.
    • Updated roleRef.name for cozy-tenant-use to cozy:tenant:use.
    • Updated roleRef.name for cozy-tenant-admin to cozy:tenant:admin.
    • Updated roleRef.name for cozy-tenant-super-admin to cozy:tenant:super-admin.
    • Updated roleRef.name for cozy-tenant-dashboard to cozy:tenant:dashboard.
  • packages/system/cozystack-basics/templates/clusterroles.yaml
    • Updated metadata.name for cozy-tenant to cozy:tenant.
    • Updated metadata.name for cozy-tenant-base to cozy:tenant:base.
    • Updated metadata.name for cozy-tenant-view to cozy:tenant:view.
    • Updated metadata.name for cozy-tenant-view-base to cozy:tenant:view:base.
    • Updated metadata.name for cozy-tenant-use to cozy:tenant:use.
    • Updated metadata.name for cozy-tenant-use-base to cozy:tenant:use:base.
    • Updated metadata.name for cozy-tenant-admin to cozy:tenant:admin.
    • Updated metadata.name for cozy-tenant-admin-base to cozy:tenant:admin:base.
    • Updated metadata.name for cozy-tenant-super-admin to cozy:tenant:super-admin.
    • Updated metadata.name for cozy-tenant-super-admin-base to cozy:tenant:super-admin:base.
  • packages/system/cozystack-basics/templates/dashboard-role.yaml
    • Updated metadata.name for cozy-tenant-dashboard to cozy:tenant:dashboard.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai

coderabbitai Bot commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Renamed Kubernetes RBAC resource names from hyphenated cozy-tenant* to colon-delimited cozy:tenant* across ClusterRole, Role, and RoleBinding manifests; no permission rules, namespaces, or control flow were changed.

Changes

Cohort / File(s) Summary
ClusterRole definitions
packages/system/cozystack-basics/templates/clusterroles.yaml
Renamed ClusterRole metadata.name values from cozy-tenant* to cozy:tenant* (e.g., cozy-tenant-view → cozy:tenant:view). Rules and aggregation unchanged.
Role definition (dashboard)
packages/system/cozystack-basics/templates/dashboard-role.yaml
Renamed Role metadata.name from cozy-tenant-dashboard → cozy:tenant:dashboard; rules and namespace unchanged.
RoleBinding updates
packages/apps/tenant/templates/tenant.yaml
Updated RoleBinding metadata.name and roleRef.name to reference cozy:tenant* variants (top-level, view, use, admin, super-admin, and dashboard). Namespace for dashboard remains cozy-public.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on YAML with a twitch and a cheer,
swapping dashes for colons — neat and clear.
Names now line up in a punctual row,
RBAC sings softly, ready to go. 🐇✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[rbac] Use hierarchical naming scheme' directly and clearly describes the main change in the pull request, which consistently renames RBAC resources across multiple files to use colon-delimited hierarchical naming.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/refactor-rbac

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the naming of RBAC resources to use a hierarchical, colon-separated scheme, aligning with Kubernetes conventions. The changes are applied consistently across all relevant ClusterRole, Role, and RoleBinding definitions. All references between role bindings and their corresponding roles have been updated correctly. The aggregation logic for cluster roles remains intact and correct. This is a good improvement for clarity and maintainability of RBAC resources.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/apps/tenant/templates/tenant.yaml`:
- Around line 32-35: The RoleBinding roleRef values in tenant.yaml are being
changed (e.g., roleRef.name values 'cozy:tenant', 'cozy:tenant:view',
'cozy:tenant:use', 'cozy:tenant:admin', 'cozy:tenant:super-admin', and the Role
'cozy:tenant:dashboard') but roleRef is immutable on existing RoleBindings;
implement a migration so Helm upgrade doesn't fail: add a pre-upgrade hook (or a
separate migration Job) that deletes the existing RoleBindings with those
metadata names before Helm recreates them, or run `kubectl auth reconcile -f
<tenant.yaml>` as part of the upgrade; target the RoleBinding resources that
contain roleRef in tenant.yaml (and the Role resource 'cozy:tenant:dashboard')
so the new roleRef values can be applied without attempting an in-place patch.
🧹 Nitpick comments (1)
packages/system/cozystack-basics/templates/clusterroles.yaml (1)

52-60: Aggregation labels still use hyphens — intentional but worth a note.

The ClusterRole names now use colons (cozy:tenant:view) but the aggregation labels remain hyphenated (rbac.cozystack.io/aggregate-to-tenant-view). This is functionally fine since labels and names are independent, but the inconsistency may cause confusion for future maintainers. Consider adding a brief comment or documenting this convention choice.

Comment on lines 32 to 35
roleRef:
kind: ClusterRole
name: cozy-tenant
name: cozy:tenant
apiGroup: rbac.authorization.k8s.io

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the full RoleBinding definitions in tenant.yaml
fd -t f tenant.yaml packages/apps/tenant/templates/ -x cat -n {}

Repository: cozystack/cozystack

Length of output: 4172


🏁 Script executed:

# Check for any migration hooks or pre-upgrade strategies
find packages/apps/tenant -type f -name "*.yaml" -o -name "*.yml" | xargs grep -l "hook\|pre-upgrade\|migration" 2>/dev/null || echo "No migration hooks found"

Repository: cozystack/cozystack

Length of output: 110


🌐 Web query:

Kubernetes RoleBinding roleRef immutability constraints and upgrade behavior

💡 Result:

Immutability constraint (what you can’t change)

  • In both RoleBinding and ClusterRoleBinding, the field .roleRef is immutable. If you try to update it (change kind, name, or apiGroup), the API server rejects the update with a validation error like “cannot change roleRef”. (kubernetes.io)
  • Kubernetes documents two reasons: (1) allow delegating “update binding subjects” without allowing changing the granted role; (2) switching to a different role is considered a fundamentally different binding, so it must be delete+recreate. (kubernetes.io)

Upgrade / reconciliation behavior (kubectl / Helm / controllers)

  • kubectl apply / patch / SSA: can update mutable parts (e.g., subjects, metadata), but will fail if the manifest changes roleRef. (kubernetes.io)
  • To “change roleRef” you must replace the object: delete the existing binding and create a new one. (kubernetes.io)
  • kubectl auth reconcile -f … is purpose-built for RBAC objects and will delete+recreate bindings when needed to account for an immutable roleRef change; it can also semantically reconcile subjects (optionally removing extras with --remove-extra-subjects). (kubernetes.io)
  • Helm upgrades: if a chart revision changes roleRef, the upgrade typically fails because Helm attempts to patch the existing object; you generally need recreate semantics (for example, deleting that binding first, or using a forced replace approach) because Kubernetes won’t allow an in-place change. (kubernetes.io)

Practical rule of thumb

  • Role/ClusterRole changes (rules inside the Role/ClusterRole): safe to upgrade in-place.
  • Binding subject changes (who gets the role): safe to upgrade in-place.
  • Binding roleRef changes (what role is granted): must be delete+recreate (or use kubectl auth reconcile, which handles this). (kubernetes.io)

Citations:


🏁 Script executed:

cat -n packages/apps/tenant/templates/cleanup-job.yaml

Repository: cozystack/cozystack

Length of output: 3268


Critical: roleRef is immutable on existing RoleBindings — Helm upgrade will fail.

Kubernetes does not allow modifying roleRef on an existing RoleBinding. Changing roleRef.name from cozy-tenant to cozy:tenant (and similar changes for all six RoleBindings) while keeping the same RoleBinding metadata.name will cause Helm to attempt a patch/update, which the API server will reject with an error like:

roleRef cannot be changed

This applies to all six RoleBindings in tenant.yaml:

  • Line 34: cozy:tenant
  • Line 47: cozy:tenant:view
  • Line 60: cozy:tenant:use
  • Line 73: cozy:tenant:admin
  • Line 86: cozy:tenant:super-admin
  • Line 113: cozy:tenant:dashboard (Role, not ClusterRole)

You need a strategy to handle this migration, such as:

  1. A pre-upgrade hook that deletes the existing RoleBindings before Helm attempts to recreate them.
  2. Using kubectl auth reconcile -f … which is purpose-built to handle immutable roleRef changes.
  3. A migration job that deletes the old bindings to allow recreation with new roleRef values.
🤖 Prompt for AI Agents
In `@packages/apps/tenant/templates/tenant.yaml` around lines 32 - 35, The
RoleBinding roleRef values in tenant.yaml are being changed (e.g., roleRef.name
values 'cozy:tenant', 'cozy:tenant:view', 'cozy:tenant:use',
'cozy:tenant:admin', 'cozy:tenant:super-admin', and the Role
'cozy:tenant:dashboard') but roleRef is immutable on existing RoleBindings;
implement a migration so Helm upgrade doesn't fail: add a pre-upgrade hook (or a
separate migration Job) that deletes the existing RoleBindings with those
metadata names before Helm recreates them, or run `kubectl auth reconcile -f
<tenant.yaml>` as part of the upgrade; target the RoleBinding resources that
contain roleRef in tenant.yaml (and the Role resource 'cozy:tenant:dashboard')
so the new roleRef values can be applied without attempting an in-place patch.

## What this PR does

This patch improves the naming conventions used in Cozystack's RBAC
resources. It follows the k8s system convention of using colons as
separators in RBAC resource names (e.g. system:nodes:<nodename>) and
renames some default tenant clusterroles to a scheme like
cozy:tenant:admin.

### Release note

```release-note
[rbac] Use a more structured naming convention for Cozystack's RBAC
resources.
```

Signed-off-by: Timofei Larkin <[email protected]>

@kvaps Andrei Kvapil (kvaps) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Feb 11, 2026
@lllamnyp
Timofei Larkin (lllamnyp) merged commit c54e55e into main Feb 11, 2026
8 checks passed
@lllamnyp
Timofei Larkin (lllamnyp) deleted the chore/refactor-rbac branch February 11, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature lgtm This PR has been approved by a maintainer size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants