Skip to content

[rbac] Fix permissions for high-privilege users - #1622

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/access-rights
Nov 12, 2025
Merged

[rbac] Fix permissions for high-privilege users#1622
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/access-rights

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Nov 12, 2025

Copy link
Copy Markdown
Member

What this PR does

This patch grants "admin" permissions to super-admins, "use" permissions to admins and super-admins, "view" permissions to "use"-privileged users, admins, and super-admins. Previously lower-privileged roles were not assigned to higher-privileged users, so a viewer could excercise their basic read-only permissions which were not available to high-privilege users. This patch corrects the template function used to generate subjects in rolebindings, fixing the issue.

Release note

[rbac] Fix issue of privileged users not having low-privilege read-only
permissions.

Summary by CodeRabbit

  • Bug Fixes
    • Updated access level handling in role-based authorization to ensure proper permission evaluation across tenant environments.

## What this PR does

This patch grants "admin" permissions to super-admins, "use" permissions
to admins and super-admins, "view" permissions to "use"-privileged
users, admins, and super-admins. Previously lower-privileged roles were
not assigned to higher-privileged users, so a viewer could excercise
their basic read-only permissions which were not available to
high-privilege users. This patch corrects the template function used to
generate subjects in rolebindings, fixing the issue.

### Release note

```release-note
[rbac] Fix issue of privileged users not having low-privilege read-only
permissions.
```

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
@dosubot dosubot Bot added the size/XS This PR changes 0-9 lines, ignoring generated files label Nov 12, 2025
@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 addresses a critical flaw in the Role-Based Access Control (RBAC) configuration where users with higher administrative privileges were inadvertently lacking fundamental lower-level permissions. By updating the RBAC template function, the changes ensure that permissions are correctly inherited across different access levels, thereby allowing privileged users to perform all actions expected of their role, including those typically associated with less privileged roles.

Highlights

  • Permission Assignment: Super-admins are now granted 'admin' permissions, while admins and super-admins receive 'use' permissions. Additionally, 'view' permissions are extended to 'use'-privileged users, admins, and super-admins.
  • Role Hierarchy Correction: The pull request resolves an issue where higher-privileged users were not automatically assigned lower-privileged roles, preventing them from exercising basic read-only permissions.
  • Template Function Update: The template function used for generating subjects in rolebindings has been corrected from cozy-lib.rbac.subjectsForTenant to cozy-lib.rbac.subjectsForTenantAndAccessLevel to properly reflect the intended permission hierarchy.
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.

@lllamnyp Timofei Larkin (lllamnyp) added kind/bug Categorizes issue or PR as related to a bug backport Should change be backported on previous release and removed size/XS This PR changes 0-9 lines, ignoring generated files labels Nov 12, 2025
@coderabbitai

coderabbitai Bot commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A template function call for RBAC subject generation is updated across multiple role bindings in the tenant template. The function cozy-lib.rbac.subjectsForTenant is replaced with cozy-lib.rbac.subjectsForTenantAndAccessLevel, affecting view, use, admin, and super-admin role bindings in a single YAML file.

Changes

Cohort / File(s) Change Summary
RBAC template function update
packages/apps/tenant/templates/tenant.yaml
Updated subject generation function from subjectsForTenant to subjectsForTenantAndAccessLevel across multiple RoleBinding resources (view, use, admin, super-admin bindings)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the semantic difference between subjectsForTenant and subjectsForTenantAndAccessLevel functions in cozy-lib
  • Confirm that all RoleBinding blocks were consistently updated (no partial migrations)
  • Ensure the AccessLevel parameter inclusion is appropriate for all binding types (view, use, admin, super-admin)

Suggested reviewers

  • kvaps

Poem

🐰 A function hops from old to new,
AccessLevels added to the RBAC view,
Four bindings bound with fresh delight,
Subjects generated just right! ✨

Pre-merge checks and finishing touches

✅ 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] Fix permissions for high-privilege users' directly relates to the main change: fixing RBAC rolebindings to grant lower-privilege permissions to higher-privilege users by using a new template function.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/access-rights

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a861814 and 7ddd9cf.

📒 Files selected for processing (1)
  • packages/apps/tenant/templates/tenant.yaml (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
packages/apps/tenant/templates/tenant.yaml (1)

125-125: Verify the new template function implements privilege hierarchy correctly.

The change to cozy-lib.rbac.subjectsForTenantAndAccessLevel is semantically aligned with the PR objective. However, without access to the function's implementation, I cannot confirm it correctly distributes subjects across privilege levels (i.e., that view RoleBinding includes all users at view, use, admin, and super-admin levels).

Please verify that the implementation of cozy-lib.rbac.subjectsForTenantAndAccessLevel in the cozy-lib library correctly implements the hierarchical privilege logic described in the PR objectives. You can check this by:

  1. Locating the function definition in the cozy-lib Helm library
  2. Confirming it generates subjects for all applicable privilege levels based on the input access level (e.g., "view" should return subjects for view, use, admin, and super-admin)
  3. Validating this against the PR objectives

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 aims to fix RBAC permissions by ensuring higher-privileged users also receive lower-privilege permissions. This is done by switching to the cozy-lib.rbac.subjectsForTenantAndAccessLevel Helm template helper. While the intent is correct, this change introduces a critical issue. The cozy-lib.rbac.subjectsForTenantAndAccessLevel function incorrectly generates ServiceAccount subjects from parent tenants, which reside in different namespaces. Kubernetes RoleBindings are namespace-scoped and cannot reference subjects in other namespaces, which will cause the deployment to fail. I have added a detailed comment on the first occurrence of this issue, which applies to all changes in this pull request. This must be fixed before merging.

namespace: {{ include "tenant.name" . }}
subjects:
{{ include "cozy-lib.rbac.subjectsForTenant" (list "view" (include "tenant.name" .)) | nindent 2 }}
{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "view" (include "tenant.name" .)) | nindent 2 }}

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.

critical

The cozy-lib.rbac.subjectsForTenantAndAccessLevel template function introduces a critical issue by generating invalid subjects for this RoleBinding. A Kubernetes RoleBinding is a namespace-scoped resource and can only grant permissions to subjects (like ServiceAccounts) within its own namespace.

The subjectsForTenantAndAccessLevel template iterates through the current tenant and all its parent tenants, and for each, it creates a ServiceAccount subject. For any parent tenant, the ServiceAccount will be in a different namespace than this RoleBinding, making the generated resource invalid and causing the deployment to fail.

To fix this, the cozy-lib.rbac.subjectsForTenantAndAccessLevel template in packages/library/cozy-lib/templates/_rbac.tpl must be changed to not generate ServiceAccount subjects for parent tenants. It should only generate a ServiceAccount subject for the current tenant, if at all.

The problematic logic in cozy-lib.rbac.subjectsForTenantAndAccessLevel is the call to include "cozy-lib.rbac.serviceAccountSubject" inside the loop over all tenants ($tenants). This call should be moved outside the loop or removed if ServiceAccount subjects are handled elsewhere.

This issue applies to all four changes in this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is incorrect. Roles can reference serviceaccounts in other namespaces. To quote the k8s documentation:

You can use RBAC to allow service accounts in one namespace to perform actions on resources in a different namespace in the cluster.

@dosubot dosubot Bot added the size/XS This PR changes 0-9 lines, ignoring generated files label Nov 12, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Nov 12, 2025
@kvaps
Andrei Kvapil (kvaps) merged commit 9d6af84 into main Nov 12, 2025
22 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the fix/access-rights branch November 12, 2025 14:46
@github-actions

Copy link
Copy Markdown

Successfully created backport PR for release-0.37:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Should change be backported on previous release kind/bug Categorizes issue or PR as related to a bug lgtm This PR has been approved by a maintainer size/XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants