Skip to content

Conversation

@Subhra264
Copy link
Contributor

@Subhra264 Subhra264 commented Nov 4, 2024

Fixes #4982

  • Adds migration for pipelines for ofga tuple database.
  • Fixes some rbac permission logic for pipelines.

Summary by CodeRabbit

  • New Features

    • Enhanced pipeline migration logic to ensure pipeline-related data is considered during migrations.
    • Improved permission checking mechanism in the list_pipelines function, allowing for dynamic model retrieval.
    • Expanded permissions management in the EditRole component to include pipeline entities.
    • Added a new method to fetch pipeline data in the EditRole component.
  • Bug Fixes

    • Refined request handling and authorization extraction processes for better accuracy in identifying object types and methods.
    • Enhanced error handling for deleting pipelines to provide more informative messages.
  • Documentation

    • Added comments to clarify logic in the from_request method for improved readability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The pull request introduces modifications primarily in the src/common/infra/ofga.rs, src/common/utils/auth.rs, src/handler/http/request/pipeline.rs, web/src/components/iam/roles/EditRole.vue, and src/service/pipeline/mod.rs files. Key changes include the addition of a boolean variable need_pipeline_migration to handle pipeline data migration, refinements to the from_request method for authorization checks, updates to the list_pipelines function for dynamic model retrieval, and enhancements in the EditRole component for managing pipeline-related permissions. These adjustments improve migration processes and enhance permissions management.

Changes

File Path Change Summary
src/common/infra/ofga.rs - Added need_pipeline_migration variable and logic in init function to check meta_version and existing_model_version.
- Integrated add_tuple_for_pipeline function for processing pipelines.
src/common/utils/auth.rs - Updated from_request method to refine object type determination and authorization checks, particularly for PUT requests.
- Updated method signatures for from_request.
src/handler/http/request/pipeline.rs - Added import for OFGA_MODELS and modified list_pipelines function to dynamically retrieve the model key for permission checks instead of using a hardcoded string.
web/src/components/iam/roles/EditRole.vue - Added import for pipelineService and defined getPipelines function.
- Updated getResourceEntities to include pipeline retrieval.
- Modified updateResourceEntities to integrate pipeline entities.
src/service/pipeline/mod.rs - Updated permission checks in list_pipelines and delete_pipeline functions to standardize permission formats and enhance error handling.

Assessment against linked issues

Objective Addressed Explanation
Ensure existing pipelines are displayed for SSO users (#4982)

Possibly related PRs

Suggested labels

🧹 Updates

Suggested reviewers

  • hengfeiyang
  • oasisk

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Nov 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
src/common/infra/ofga.rs (1)

198-208: Consider batching pipeline migrations for better performance.

The current implementation fetches all pipelines for each organization at once. For organizations with many pipelines, this could lead to memory pressure.

Consider implementing batch processing:

  1. Fetch pipelines in chunks
  2. Process each chunk before fetching the next
  3. Add progress logging

Would you like me to provide an example implementation with batching?

src/common/utils/auth.rs (1)

343-347: LGTM! Consider adding a clarifying comment.

The exclusion of streams and pipelines from the PUT method condition correctly fixes the RBAC permission logic. This change ensures proper authorization checks for pipeline operations.

Consider adding a comment to explain why streams and pipelines require different handling:

            } else if method.eq("PUT")
+               // Streams and pipelines have special handling for PUT operations
+               // as they require different permission checks
                && path_columns[1] != "streams"
                && path_columns[1] != "pipelines"
                || method.eq("DELETE")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4603b26 and ec75406.

📒 Files selected for processing (3)
  • src/common/infra/ofga.rs (4 hunks)
  • src/common/utils/auth.rs (1 hunks)
  • src/handler/http/request/pipeline.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/common/infra/ofga.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/common/utils/auth.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/handler/http/request/pipeline.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🔇 Additional comments (4)
src/handler/http/request/pipeline.rs (3)

21-21: LGTM: Import statement is correctly placed and used.


Line range hint 38-199: Consider implementing consistent RBAC across all pipeline endpoints.

While the RBAC improvements in list_pipelines are good, other endpoints (save_pipeline, delete_pipeline, update_pipeline, enable_pipeline) might benefit from similar permission model checks for consistency.

#!/bin/bash
# Check if other endpoints have RBAC checks
rg -A 5 "list_objects_for_user.*pipeline" 

83-85: Verify pipeline model registration in OFGA_MODELS.

The change from hardcoded "logs" to dynamic model lookup is an improvement. However, let's verify that "pipelines" is properly registered in OFGA_MODELS to avoid always falling back to the default.

src/common/infra/ofga.rs (1)

18-18: LGTM: Import changes are appropriate.

The new imports support the pipeline migration functionality.

Also applies to: 25-26

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
web/src/components/iam/roles/EditRole.vue (1)

1437-1447: Consider enhancing error handling and type safety.

The implementation follows the established pattern and correctly integrates with the pipeline service. However, consider these improvements:

  1. Add error handling to catch and properly handle API failures
  2. Add TypeScript type annotations for better code maintainability
-const getPipelines = async () => {
+const getPipelines = async (): Promise<void> => {
   try {
     const pipelines = await pipelineService.getPipelines(
       store.state.selectedOrganization.identifier
     );
 
     updateResourceEntities("pipeline", ["name"], [...pipelines.data.list]);
   } catch (error) {
+    console.error('Failed to fetch pipelines:', error);
+    throw error;
   }
-  return new Promise((resolve) => {
-    resolve(true);
-  });
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec75406 and 7f75bc9.

📒 Files selected for processing (1)
  • web/src/components/iam/roles/EditRole.vue (3 hunks)
🔇 Additional comments (1)
web/src/components/iam/roles/EditRole.vue (1)

329-329: LGTM: Pipeline service import added correctly.

The import statement is properly placed alongside other service imports and aligns with the PR's objective to implement pipeline RBAC fixes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7f75bc9 and 845472b.

📒 Files selected for processing (1)
  • src/common/infra/ofga.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/common/infra/ofga.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🔇 Additional comments (2)
src/common/infra/ofga.rs (2)

24-25: LGTM!

The import changes are clean and well-organized.


48-48: LGTM!

The pipeline migration flag follows the established pattern.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/common/infra/ofga.rs (1)

201-216: Consider transaction safety for pipeline migration

While the error handling is robust, the pipeline migration process might leave the system in an inconsistent state if it fails partway through. Consider:

  1. Collecting all tuples first
  2. Performing the update in a single transaction

Here's a suggested approach:

 if need_pipeline_migration {
+    let mut pipeline_tuples = Vec::new();
     match db::pipeline::list_by_org(org_name).await {
         Ok(pipelines) => {
             for pipeline in pipelines {
-                add_tuple_for_pipeline(org_name, &pipeline.name, &mut tuples);
+                add_tuple_for_pipeline(org_name, &pipeline.name, &mut pipeline_tuples);
             }
+            // Add all pipeline tuples at once
+            tuples.extend(pipeline_tuples);
         }
         Err(e) => {
             log::error!(
                 "Failed to migrate RBAC for org {} pipelines: {}",
                 org_name,
                 e
             );
         }
     }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 845472b and 729085e.

📒 Files selected for processing (1)
  • src/common/infra/ofga.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/common/infra/ofga.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
web/src/components/iam/roles/EditRole.vue (1)

1437-1447: Consider adding error handling for pipeline fetching.

The implementation follows the established pattern and correctly integrates with the existing resource entity management. However, consider adding error handling to match the robustness of a production system.

 const getPipelines = async () => {
-  const pipelines = await pipelineService.getPipelines(
-    store.state.selectedOrganization.identifier
-  );
+  try {
+    const pipelines = await pipelineService.getPipelines(
+      store.state.selectedOrganization.identifier
+    );
 
-  updateResourceEntities("pipeline", ["name"], [...pipelines.data.list]);
+    updateResourceEntities("pipeline", ["name"], [...pipelines.data.list]);
 
-  return new Promise((resolve) => {
-    resolve(true);
-  });
+    return Promise.resolve(true);
+  } catch (error) {
+    console.error('Failed to fetch pipelines:', error);
+    return Promise.reject(error);
+  }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 729085e and e4e190e.

📒 Files selected for processing (4)
  • src/common/infra/ofga.rs (4 hunks)
  • src/common/utils/auth.rs (1 hunks)
  • src/handler/http/request/pipeline.rs (1 hunks)
  • web/src/components/iam/roles/EditRole.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/common/infra/ofga.rs
  • src/common/utils/auth.rs
  • src/handler/http/request/pipeline.rs
🔇 Additional comments (1)
web/src/components/iam/roles/EditRole.vue (1)

329-329: LGTM: Pipeline service import added correctly.

The import follows the established pattern and is properly placed with other service imports.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
web/src/components/iam/roles/EditRole.vue (1)

1437-1447: Add error handling to getPipelines function.

While the implementation follows the established pattern and correctly integrates with the existing entity loading system, consider adding error handling for robustness.

Apply this diff to improve error handling:

 const getPipelines = async () => {
-  const pipelines = await pipelineService.getPipelines(
-    store.state.selectedOrganization.identifier
-  );
+  try {
+    const pipelines = await pipelineService.getPipelines(
+      store.state.selectedOrganization.identifier
+    );
 
-  updateResourceEntities("pipeline", ["name"], [...pipelines.data.list]);
+    updateResourceEntities("pipeline", ["name"], [...pipelines.data.list]);
 
-  return new Promise((resolve) => {
-    resolve(true);
-  });
+    return true;
+  } catch (error) {
+    console.error('Failed to fetch pipelines:', error);
+    throw error;
+  }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e9147b2 and 71bea66.

📒 Files selected for processing (5)
  • src/common/infra/ofga.rs (4 hunks)
  • src/common/utils/auth.rs (1 hunks)
  • src/handler/http/request/pipeline.rs (1 hunks)
  • src/service/pipeline/mod.rs (1 hunks)
  • web/src/components/iam/roles/EditRole.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/common/infra/ofga.rs
  • src/common/utils/auth.rs
  • src/handler/http/request/pipeline.rs
🧰 Additional context used
📓 Path-based instructions (1)
src/service/pipeline/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🔇 Additional comments (3)
src/service/pipeline/mod.rs (2)

176-176: LGTM! Verify permission format changes across the codebase.

The permission format changes from plural pipelines:* to singular pipeline:* look good and align with standardizing the RBAC permission logic.

Let's verify that this permission format change is consistent across the codebase:

Also applies to: 180-180

✅ Verification successful

Let me gather more information about the permission format usage across the codebase.


Let me check for any old permission format usage to ensure completeness.


Based on the gathered information, I can now provide a final response:

Permission format change is correctly implemented and consistent

The changes to use singular pipeline: format instead of plural pipelines: are correctly implemented in the permission checks. The search results confirm:

  1. The new format pipeline:{id} and pipeline:_all_{org_id} is used consistently in permission checks
  2. No instances of the old pipelines: format were found in permission-related code
  3. The only occurrences of "pipelines" are in variable names and type definitions, not in permission strings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old permission format
# and verify the new format is used consistently.

echo "Checking for old permission format 'pipelines:'"
rg -l 'pipelines:[^/]' || echo "No files contain old format"

echo -e "\nChecking usage of new permission format 'pipeline:'"
rg -l 'pipeline:[^/]'

Length of output: 302834


Script:

#!/bin/bash
# Check for permission format usage in Rust files
echo "Checking permission format in Rust files:"
rg -A 2 'pipeline:' src/service/pipeline/

Length of output: 3991


Script:

#!/bin/bash
# Check for old permission format 'pipelines:' in the codebase
echo "Checking for old permission format:"
rg -A 2 'pipelines:' src/

# Check for permission validation/checking logic
echo -e "\nChecking permission validation logic:"
rg -A 5 'fn.*permission' src/service/pipeline/

Length of output: 2214


Line range hint 173-186: Verify SSO user permissions for pipeline visibility.

Given issue #4982 about SSO users not seeing root-created pipelines, please verify that:

  1. SSO users receive the correct permissions in the permitted parameter
  2. The permission format change doesn't affect SSO user access

Let's check the permission handling for SSO users:

web/src/components/iam/roles/EditRole.vue (1)

329-329: LGTM: Pipeline service import added correctly.

The import statement follows the established pattern and is appropriately placed with other service imports.

@taimingl taimingl merged commit 287185a into main Nov 4, 2024
29 of 31 checks passed
@taimingl taimingl deleted the fix/rbac-pipeline branch November 4, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pipelines- Existing pipelines created via root user not displayed when user signs in with SSO

3 participants