Skip to content

Regal showcase #30

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Regal showcase #30

wants to merge 2 commits into from

Conversation

nimratcoderabbit
Copy link

@nimratcoderabbit nimratcoderabbit commented Jul 15, 2025

image

Summary by CodeRabbit

  • New Features

    • Introduced configuration files for review and linting settings, targeting YAML and Rego files.
    • Added a new Rego policy module with various rules and logic for access control and token checking.
  • Chores

    • Implemented formatting and linting standards for policy files, including rules for variable usage and naming conventions.

Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

Three new files are introduced: a CodeRabbit configuration file specifying path filters for reviews, a Rego policy module with multiple rules including default deny and token checks, and a Regal configuration file defining formatting and linting rules for Rego code. No changes were made to exported or public entities outside the new Rego module.

Changes

File(s) Change Summary
.coderabbit.yml Added configuration specifying path filters for review: **/*.yml, **/*.yaml, **/*.rego.
regal_config.yaml Added formatting (max line length 100, indentation 2) and enabled linting with rules disallowing unused vars, shadowing, and enforcing uppercase variables.
broken.rego Added new Rego policy module authz with default deny, constants, variables (some unused or conflicting), and multiple rules including deny, allow, result, foo, and token_check.

Poem

In the warren, configs bloom anew,
With Rego rules both old and askew.
Linting is strict, the lines are neat,
Path filters guide our rabbit feet.
🐇 With every hop, we check and test—
In YAML and code, we do our best!

Impact Analysis

Introduction of new authorization policy logic in Rego

📢 Medium 🔄 Impacts behavior

A new Rego policy module named authz is introduced, defining default-deny authorization logic and several rules that may affect access control decisions. The policy includes rules for allowing or denying access based on user input and token checks, which could impact how authorization is enforced for users or systems relying on this policy.

Test authorization scenarios for both allowed and denied users, including edge cases such as admin and non-admin users. Validate that the policy behaves as expected and does not inadvertently grant or deny access due to logic errors.

🔍 Related Files
  • broken.rego

Enforcement of stricter linting and formatting for policy and configuration files

ℹ️ Low 🔄 Impacts behavior

New configuration files enforce formatting and linting standards for .rego, .yml, and .yaml files, including line length, indentation, and rules against unused variables and variable shadowing. This may cause stricter validation and error reporting during development or CI, requiring users to adhere to these standards.

Verify that files with violations are correctly flagged and that compliant files pass without errors. Test integration with CI pipelines to ensure that linting failures are reported as expected.

🔍 Related Files
  • .coderabbit.yml
  • regal_config.yaml

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and e8b1cf4.

📒 Files selected for processing (3)
  • .coderabbit.yml (1 hunks)
  • broken.rego (1 hunks)
  • regal_config.yaml (1 hunks)
🧰 Additional context used
🪛 Regal (0.35.1)
broken.rego

[error] 24-24: Constant condition

(bugs)


[error] 23-23: Non-boolean return value unassigned

(bugs)


[error] 1-1: Directory structure should mirror package

(idiomatic)


[error] 1-1: Use import rego.v1

(imports)


[error] 15-15: Non-loop expression

(performance)


[error] 16-16: Non-loop expression

(performance)

🔇 Additional comments (2)
.coderabbit.yml (1)

1-3: Configuration looks good!

The path filters are correctly configured to include YAML and Rego files for review. The configuration follows the schema requirements.

regal_config.yaml (1)

1-16: Well-configured Regal linting rules!

The configuration appropriately sets up formatting standards and enables key linting rules that will help catch common Rego policy issues. The error severity level ensures CI will fail on violations.


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

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.

@nimratcoderabbit
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 15, 2025

✅ Actions performed

Full review triggered.

Copy link

@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: 9

🧹 Nitpick comments (1)
broken.rego (1)

1-41: File appears to be intentionally broken - clarify intent.

Given the filename "broken.rego" and numerous policy issues, this might be a test file to verify Regal linting. If this is intended as a real policy file, it needs significant fixes.

Would you like me to generate a corrected version of this policy or create test cases for your Regal configuration?

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and e8b1cf4.

📒 Files selected for processing (3)
  • .coderabbit.yml (1 hunks)
  • broken.rego (1 hunks)
  • regal_config.yaml (1 hunks)
🧰 Additional context used
🪛 Regal (0.35.1)
broken.rego

[error] 24-24: Constant condition

(bugs)


[error] 23-23: Non-boolean return value unassigned

(bugs)


[error] 1-1: Directory structure should mirror package

(idiomatic)


[error] 1-1: Use import rego.v1

(imports)


[error] 15-15: Non-loop expression

(performance)


[error] 16-16: Non-loop expression

(performance)

🔇 Additional comments (2)
.coderabbit.yml (1)

1-2: Verify the restrictive path filters.

The configuration limits reviews to only YAML and Rego files. This might exclude important file types from review depending on your project's needs.

Consider whether you want to include additional file patterns or remove the restriction entirely to review all file types.

regal_config.yaml (1)

1-16: LGTM!

The Regal configuration is well-structured with appropriate formatting settings and linting rules that will help maintain code quality in Rego files.


default allow = false

ALLOW := true
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused constant ALLOW.

This constant is defined but never referenced in the policy.

🤖 Prompt for AI Agents
In broken.rego at line 5, the constant ALLOW is defined but never used in the
policy. Remove the line defining ALLOW to clean up unused code and avoid
confusion.

Comment on lines +32 to +35
foo {
bar := [1, 2, 3]
bar = bar
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove or fix meaningless foo rule.

The rule assigns a value and then checks if it equals itself, which is always true and serves no purpose.

Either remove this rule or implement meaningful logic.

🤖 Prompt for AI Agents
In broken.rego around lines 32 to 35, the foo rule assigns a list to bar and
then compares bar to itself, which is always true and redundant. Remove this
rule entirely if it is not needed, or replace it with meaningful logic that
performs a useful check or computation relevant to your policy.

Comment on lines +10 to +11
unused1 := "test"
unused2 := input.fake.value
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused variables.

Variables unused1 and unused2 are declared but never used, violating the no-unused-vars rule.

🤖 Prompt for AI Agents
In broken.rego around lines 10 to 11, remove the declarations of the unused
variables `unused1` and `unused2` since they are not used anywhere in the code
and violate the no-unused-vars rule.

@@ -0,0 +1,41 @@
package authz
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add import rego.v1 for modern Rego compatibility.

Modern Rego policies should include the v1 import for better compatibility and to enable v1 features.

Add this after the package declaration:

 package authz
+
+import rego.v1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
package authz
package authz
import rego.v1
🧰 Tools
🪛 Regal (0.35.1)

[error] 1-1: Directory structure should mirror package

(idiomatic)


[error] 1-1: Use import rego.v1

(imports)

🤖 Prompt for AI Agents
In broken.rego at line 1, the policy is missing the import statement for
rego.v1, which is required for modern Rego compatibility and to enable v1
features. Add the line 'import rego.v1' immediately after the package
declaration to fix this.

Comment on lines +7 to +8
x := 1
x := 2
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix duplicate assignment to variable x.

Variable x is assigned two different values, which will cause a compilation error in Rego.

Remove one of the assignments or use different variable names:

-x := 1
-x := 2
+x1 := 1
+x2 := 2
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
x := 1
x := 2
x1 := 1
x2 := 2
🤖 Prompt for AI Agents
In broken.rego at lines 7 to 8, the variable x is assigned twice, which causes a
compilation error. Fix this by removing one of the assignments or renaming one
of the variables to avoid duplicate assignment.

Comment on lines +27 to +30
result := {
"status": 200,
"message": msg
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix undefined variable msg in result object.

The msg variable is not defined in this scope.

Either define msg or remove this object if it's not needed:

 result := {
   "status": 200,
-  "message": msg
+  "message": "OK"
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
result := {
"status": 200,
"message": msg
}
result := {
"status": 200,
"message": "OK"
}
🤖 Prompt for AI Agents
In broken.rego around lines 27 to 30, the variable `msg` used in the result
object is undefined in this scope. To fix this, either define the `msg` variable
with an appropriate value before using it in the result object or remove the
`message` field from the result object if it is not necessary.

Comment on lines +37 to +40
token_check {
x := split("abc.def.ghi", ".")
x[1] == "def"
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using input data instead of hardcoded string.

The token check uses a hardcoded string which isn't practical for real token validation.

Consider using input data:

 token_check {
-  x := split("abc.def.ghi", ".")
+  x := split(input.token, ".")
   x[1] == "def"
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
token_check {
x := split("abc.def.ghi", ".")
x[1] == "def"
}
token_check {
x := split(input.token, ".")
x[1] == "def"
}
🤖 Prompt for AI Agents
In broken.rego around lines 37 to 40, the token_check rule uses a hardcoded
string "abc.def.ghi" for splitting and checking, which is not practical for real
token validation. Replace the hardcoded string with a dynamic value from the
input data, such as input.token, to make the rule validate tokens based on
actual input rather than a fixed string.

Comment on lines +20 to +25
allow {
x == "user"
x := "user"
count(x)
true
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix logical errors in allow rule.

The rule has several issues:

  1. Checks x == "user" before assigning it
  2. count(x) on a string returns its length but the result is unused
  3. Constant true condition is redundant

Consider this corrected logic:

 allow {
-  x == "user"
-  x := "user"
-  count(x)
-  true
+  input.user == "user"
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
allow {
x == "user"
x := "user"
count(x)
true
}
allow {
input.user == "user"
}
🧰 Tools
🪛 Regal (0.35.1)

[error] 24-24: Constant condition

(bugs)


[error] 23-23: Non-boolean return value unassigned

(bugs)

🤖 Prompt for AI Agents
In broken.rego around lines 20 to 25, the allow rule has logical errors: it
compares x to "user" before assigning x, uses count(x) on a string without using
the result, and includes a redundant true condition. Fix this by first assigning
x to "user", removing the count(x) call since its result is unused, and
eliminating the constant true condition to simplify the rule logic.

Comment on lines +13 to +18
deny[msg] {
some x
input.user == "admin"
input.user == "admin"
msg := "Access granted"
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix contradictory logic in deny rule.

The deny rule returns "Access granted" which is semantically incorrect. Also, it has redundant conditions and an unused variable declaration.

Apply this fix:

 deny[msg] {
-  some x
-  input.user == "admin"
   input.user == "admin"
-  msg := "Access granted"
+  msg := "Access denied: admin access restricted"
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
deny[msg] {
some x
input.user == "admin"
input.user == "admin"
msg := "Access granted"
}
deny[msg] {
input.user == "admin"
msg := "Access denied: admin access restricted"
}
🧰 Tools
🪛 Regal (0.35.1)

[error] 15-15: Non-loop expression

(performance)


[error] 16-16: Non-loop expression

(performance)

🤖 Prompt for AI Agents
In broken.rego around lines 13 to 18, the deny rule incorrectly returns "Access
granted" and contains redundant conditions checking input.user == "admin" twice,
as well as an unused variable x. Remove the duplicate condition and the unused
variable, and change the message to reflect denial of access appropriately, such
as "Access denied".

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