Skip to content

Added Rule: Disallow import rego.v1#1778

Merged
charlieegan3 merged 4 commits intoopen-policy-agent:mainfrom
SeanLedford:s_ledford/rule-disallow-import-rego-v1
Dec 2, 2025
Merged

Added Rule: Disallow import rego.v1#1778
charlieegan3 merged 4 commits intoopen-policy-agent:mainfrom
SeanLedford:s_ledford/rule-disallow-import-rego-v1

Conversation

@SeanLedford
Copy link
Contributor

Added an import rule to address the following issue!

Added necessary coverage as well. Would like to review e2e test changes before merging 😄

@SeanLedford SeanLedford force-pushed the s_ledford/rule-disallow-import-rego-v1 branch from 774b0c1 to d7b4d58 Compare November 18, 2025 23:31
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

A solid start 👏 There doesn't seem to be any documentation included for this rule, but that should be a pretty quick fix given how it's pretty obvious what it does. Left a few comments, but this is an excellent start.

@@ -0,0 +1,31 @@
# METADATA
# description: Use `import rego.v1`
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be "Use of disallowed import rego.v1"

confusing-alias:
level: error
disallow-rego-v1:
level: error
Copy link
Member

Choose a reason for hiding this comment

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

All good, but even if this pertains to imports, this rule should be in the custom category, where all optional rules are placed.

notices contains result.notice(rego.metadata.chain()) if {
capabilities.is_opa_v1
input.regal.file.rego_version != "v0"
}
Copy link
Member

Choose a reason for hiding this comment

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

I believe the notices can be removed for this rule, as enabling it manually assumes someone is running with a version of OPA at 1.0 or above.

}

report contains violation if {
capabilities.is_opa_v1
Copy link
Member

Choose a reason for hiding this comment

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

So this can go too.

e2e/cli_test.go Outdated
"file-length",
"rule-named-if",
"use-rego-v1",
"disallow-rego-v1",
Copy link
Member

Choose a reason for hiding this comment

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

The changes in this file are likely not needed once it's moved to the custom category.

@anderseknert
Copy link
Member

Oh, I forgot! Once this rule is in the custom category — let's also enable it in our own linter configuration: https://github.com/open-policy-agent/regal/blob/main/.regal/config.yaml

No better way to test our rules than to use them ourselves :)

@SeanLedford SeanLedford force-pushed the s_ledford/rule-disallow-import-rego-v1 branch 3 times, most recently from 555367b to bbac31f Compare November 20, 2025 15:48
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks a lot @SeanLedford 👏 Nothing blocking, but some comments to consider. Great work, and impressive how quickly you got here considering that not only is this a new code base for you, but one that involves a new language. Awesome!

Let me know when you have had a chance to read and consider my last comments.

(And btw, sorry for the delay in reviewing this. Had some non-work issues to deal on Friday :/ )

rules:
custom:
disallow-rego-v1:
level: error
Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍


foo if not bar
`)
with capabilities.is_opa_v1 as true
Copy link
Member

Choose a reason for hiding this comment

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

We no longer check the capabilities in the rule, so this can be removed. But no big deal 🙂


This rule is intended to be enabled for projects that have been configured to target versions of OPA from 1.0
onwards, but Regal does not explicitly check which version of OPA is being targeted for this rule. If working
with older versions of OPA and Rego, ensure that this rule is disabled.
Copy link
Member

Choose a reason for hiding this comment

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

ensure that this rule is disabled

Since this is the default, perhaps we can just say "you probably don't want to enable this rule".

(Unrelated to that, but what's up with the 1-space indentation on the 2 lines above? 😄)


## Related Resources

- GitHub: [Source Code](https://github.com/open-policy-agent/regal/blob/main/bundle/regal/rules/custom/disallow-rego-v1/disallow_rego_v1.rego)
Copy link
Member

Choose a reason for hiding this comment

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

Excellent!


policy := `package p

import rego.v1
Copy link
Member

Choose a reason for hiding this comment

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

Nice :)


foo if not bar
`)
with capabilities.is_opa_v1 as true
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@anderseknert anderseknert linked an issue Nov 27, 2025 that may be closed by this pull request
Signed-off-by: Sean Ledford <s_ledford@apple.com>
Signed-off-by: Sean Ledford <s_ledford@apple.com>
Signed-off-by: Sean Ledford <s_ledford@apple.com>
@SeanLedford SeanLedford force-pushed the s_ledford/rule-disallow-import-rego-v1 branch 2 times, most recently from 287448e to 24030da Compare December 1, 2025 18:05
@@ -0,0 +1,23 @@
# disallow-rego-v1

**Summary**: Disallow `import rego v1`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Summary**: Disallow `import rego v1`
**Summary**: Use of disallowed `import rego v1`

I think the rules are generally named about what the use has done wrong, so it reads well when they see it in their editors, etc.

Signed-off-by: Sean Ledford <s_ledford@apple.com>
@SeanLedford SeanLedford force-pushed the s_ledford/rule-disallow-import-rego-v1 branch from 24030da to bef5faf Compare December 1, 2025 21:07
@charlieegan3 charlieegan3 merged commit 1b083ff into open-policy-agent:main Dec 2, 2025
8 checks passed
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.

Rule: Disallow import rego.v1

3 participants