You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package overlap.p
bar = __local1__2 {
__local1__2 = input.y
}
which will produce the following error when evaluated with opa eval -d bundle.tar.gz -fpretty 'data':
1 error occurred: /optimized/overlap.rego:1: rego_type_error: package overlap.p conflicts with rule p[__local0__3] defined at /optimized/overlap.rego:9
Suggested fix
Allow packages to be declared within the dynamic extent of a rule's ref. The document defined at the package path by the module might pose a conflict at eval-time, but cannot be determined to do so at compile-time.
Example 1: package extends partial object rule (valid)
a.rego:
package overlap
p[x] :=1 { x := input.list[_] }
b.rego:
package overlap.p
q :=2
Example 2: package redeclares value of single-value rule (invalid)
a.rego:
package overlap
p :=1
b.rego:
package overlap.p
q :=2
Example 3: package redeclares value of multi-value rule (invalid)
a.rego:
package overlap
p[x] { x := input.list[_] }
b.rego:
package overlap.p
q :=2
The text was updated successfully, but these errors were encountered:
johanfylling
changed the title
Opa rejects packages inside the dynamic extent of a rule's ref
Packages inside the dynamic extent of a rule's ref are rejected at compile-time
Nov 6, 2023
The general case
The following modules
Module A:
Module B:
will generate the compile-time error:
However, module
A
andB
can be expressed as a single module:which is valid rego, and will not be rejected by the compiler.
Side note: the error reports the bad package to be at
a.rego:1
, but it's actually atb.rego:1
The optimized build case
The above scenario can unintentionally be triggered through optimized compilation, e.g. when building an optimized bundle.
If building the policy:
with
opa build --optimize 1 .
a bundle with the following content will be produced:
optimized/overlap.rego
:optimized/overlap/p.rego
:which will produce the following error when evaluated with
opa eval -d bundle.tar.gz -fpretty 'data'
:Suggested fix
Allow packages to be declared within the dynamic extent of a rule's ref. The document defined at the package path by the module might pose a conflict at eval-time, but cannot be determined to do so at compile-time.
Example 1: package extends partial object rule (valid)
a.rego
:b.rego
:Example 2: package redeclares value of single-value rule (invalid)
a.rego
:b.rego
:Example 3: package redeclares value of multi-value rule (invalid)
a.rego
:b.rego
:The text was updated successfully, but these errors were encountered: