Skip to content

fix(transcoding): restrict transcoding operations to admin users #4096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented May 21, 2025

This pull request introduces role-based access control (RBAC) for the transcodingRepository by restricting certain operations to admin users only. It also adds comprehensive unit tests to validate the new behavior. The key changes include the addition of an isAdmin function, integration of permission checks across repository methods, and new test cases for admin and regular user scenarios.

Role-Based Access Control (RBAC) Implementation:

Unit Tests for Permission Enforcement:

  • Added persistence/transcoding_repository_test.go to validate RBAC functionality:
    • Tests for admin users to ensure they can create, update, and delete transcodings.
    • Tests for regular users to confirm they are denied permissions for the same operations.

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan requested a review from Copilot May 21, 2025 21:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request implements role‐based access control for transcoding operations by restricting modifications to admin users and adding unit tests to confirm correct behavior.

  • Added an isAdmin function in the base repository to centralize admin checking.
  • Integrated permission checks into Put, Save, Update, and Delete methods.
  • Added unit tests to verify that only admin users can perform transcoding operations.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
persistence/transcoding_repository.go Added RBAC checks in Put, Save, Update, and Delete methods
persistence/sql_base_repository.go Added isAdmin helper to check user privileges
persistence/transcoding_repository_test.go Added tests ensuring admin-only modifications are enforced
Comments suppressed due to low confidence (1)

persistence/transcoding_repository.go:44

  • [nitpick] The admin check logic is duplicated across multiple methods. Consider refactoring this repeated logic into a helper function to improve maintainability.
if (!isAdmin(r.ctx)) {

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 21d7617 in 1 minute and 54 seconds. Click for details.
  • Reviewed 162 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. persistence/sql_base_repository.go:68
  • Draft comment:
    The isAdmin function relies on loggedUser returning a default user when none exists. Consider explicitly handling a nil/empty user to clarify that no user is non-admin.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The current implementation is actually clean and follows Go idioms - it uses the zero value pattern where an empty User struct represents a non-admin user. Making the nil case explicit would add complexity without adding clarity. The current code is more elegant and safer since there's no nil to check. I could be wrong about whether this is truly intentional behavior. Maybe there are edge cases where we want different handling of missing users vs non-admin users. The code shows a clear pattern - loggedUser() deliberately returns an empty User{} rather than nil, and isAdmin() builds on this design choice. This is good Go code following zero-value patterns. The comment should be deleted. The current code is well-designed and explicit nil handling would make it more complex without benefit.
2. persistence/transcoding_repository.go:43
  • Draft comment:
    RBAC checks are duplicated across Put, Save, Update, and Delete. Consider centralizing the admin validation to reduce repetition.
  • Reason this comment was not posted:
    Comment was on unchanged code.
3. persistence/transcoding_repository_test.go:75
  • Draft comment:
    Test for regular user update uses Put for updating. Consider adding explicit tests for the dedicated Update method to fully verify RBAC enforcement.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment seems to be making assumptions about code we can't see. There's no indication of a separate Update method in the interface or implementation. The existing tests already verify RBAC for modifications using Put(). Without evidence of an Update method, this suggestion isn't actionable. I could be wrong about the Update method - it might exist in files we can't see. The interface could have both Put and Update methods. Even if an Update method exists elsewhere, we can't verify that from the context we have. We should only keep comments that are clearly correct based on the evidence available. Delete the comment since it makes assumptions about code structure we can't verify, and the existing tests already verify RBAC enforcement for modifications.

Workflow ID: wflow_T2c2SVOxUsws1HzT

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@deluan deluan merged commit e543855 into master May 22, 2025
35 checks passed
@deluan deluan deleted the transcoding-authz branch May 22, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant