wren-engine icon indicating copy to clipboard operation
wren-engine copied to clipboard

feat(core): add validation rule for the condition syntax check of row-level access controls

Open goldmedal opened this issue 7 months ago • 1 comments

Description

Wait #1161 Add the rule to check if the condition of RLAC is valid.

URL

POST /v3/connector/{data_source}/validate/rlac_condition_syntax_is_valid

Sample Payload

{
    "manifest_str": "...",
    "modelName": "orders",
    "requiredProperties": [
        {
            "name": "@SESSION_LEVEL",
            "required": true
        },
        {
            "name": "@SESSION_ROLE",
            "required": true
        },
        {
            "name": "@SESSION_REGION",
            "required": true
        }
    ],
    "condition": "level = @SESSION_LEVEL AND role = @SESSION_ROLE OR region = @SESSION_REGION"
}

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
  - Added validation for row-level access control (RLAC) condition syntax, ensuring all session properties referenced in conditions are properly declared.
  - Introduced new Python and Rust APIs to support RLAC rule validation and model access.
  - Expanded validation endpoints and test coverage for RLAC scenarios.

- **Bug Fixes**
  - Improved error messages for validation failures related to missing session properties in RLAC conditions.

- **Tests**
  - Added comprehensive tests for RLAC rule validation, covering both valid and invalid scenarios.

- **Documentation**
  - Enhanced Python bindings documentation by exposing new classes and functions for RLAC validation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

goldmedal avatar May 02 '25 06:05 goldmedal

Walkthrough

This update introduces row-level access control (RLAC) condition syntax validation to the system. It adds new Rust and Python bindings for RLAC-related types and validation logic, exposes these to Python, and integrates a new validation rule in the server. Associated tests are added at both the Rust and Python levels.

Changes

File(s) Change Summary
ibis-server/app/model/__init__.py, ibis-server/app/model/validator.py Broadened the type annotation for validation parameters and added a new RLAC condition syntax validation rule and method. Updated the validation rules list and method signatures accordingly.
ibis-server/tests/routers/v3/connector/postgres/test_validate.py Added async test for the new RLAC condition syntax validation endpoint, covering both valid and invalid scenarios.
wren-core-base/src/mdl/py_method.rs Added Python bindings for SessionProperty and RowLevelAccessControl structs, and a method to retrieve models by name from the manifest.
wren-core-py/src/lib.rs, wren-core-py/src/manifest.rs, wren-core-py/src/validation.rs Introduced a new validation module and exposed RLAC validation and manifest conversion functions and types to Python. Made to_manifest a Python-callable function.
wren-core-py/tests/test_modeling_core.py Added tests for RLAC rule validation, checking for correct handling of session property requirements.
wren-core/core/src/logical_plan/analyze/access_control.rs Added the validate_rlac_rule function to check RLAC conditions for undeclared session properties, and comprehensive tests for this logic.
wren-core/core/src/logical_plan/analyze/mod.rs Made the access_control module public to allow external access.
wren-core-py/src/errors.rs, wren-core-py/src/extractor.rs Minor refactoring: simplified error message formatting and replaced filtering logic with a helper method. No changes to public interfaces.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API Server
    participant RLAC Validator (Python)
    participant Manifest (Rust)
    participant RLAC Validator (Rust)

    Client->>API Server: POST /validate/rlac_condition_syntax_is_valid (parameters, manifest)
    API Server->>RLAC Validator (Python): validate_rlac_condition_syntax_is_valid(parameters, manifest)
    RLAC Validator (Python)->>Manifest (Rust): to_manifest(manifest_str)
    Manifest (Rust)-->>RLAC Validator (Python): Manifest object
    RLAC Validator (Python)->>Manifest (Rust): get_model(model_name)
    Manifest (Rust)-->>RLAC Validator (Python): Model object
    RLAC Validator (Python)->>RLAC Validator (Rust): validate_rlac_rule(RLAC, Model)
    RLAC Validator (Rust)-->>RLAC Validator (Python): Validation result (Ok/Error)
    RLAC Validator (Python)-->>API Server: Success or ValidationError
    API Server-->>Client: HTTP 204 (success) or 422 (error)

Suggested reviewers

  • douenergy

Poem

In fields of code where carrots grow,
A rabbit hops with RLAC in tow.
Now session props must match their name,
Or errors gently stake their claim.
With tests and bindings, all in sync—
This patch is fresher than you think!
🥕✨

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

coderabbitai[bot] avatar May 02 '25 06:05 coderabbitai[bot]

Thanks @goldmedal

douenergy avatar May 12 '25 09:05 douenergy