open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.49k stars 1.32k forks source link

AST: missing location in some rule head refs #6860

Closed anderseknert closed 1 week ago

anderseknert commented 1 month ago

This was reported in Regal, but my brief investigation suggests that the issue originates in OPA. Regal expects each part of a ref to include a location. However, a policy like this:

package p

import rego.v1

a.b if true

a.b := true

Transforms to an AST where the first a.b has no ref locations, and the second a.b does.

rule.head.ref "a.b if true"

[
  {
    "type": "var",
    "value": "a"
  },
  {
    "type": "string",
    "value": "b"
  }
]

rule.head.ref "a.b := true"

[
  {
    "location": {
      "col": 1,
      "file": "p.rego",
      "row": 7,
      "text": "b3V0cHV0"
    },
    "type": "var",
    "value": "output"
  },
  {
    "location": {
      "col": 8,
      "file": "p.rego",
      "row": 7,
      "text": "InVzZXJLYXJtYSI="
    },
    "type": "string",
    "value": "userKarma"
  }
]

I believe this inconsistency is a bug.

kd-labs commented 1 month ago

can I pick this up ?? ...it would be my first to contribute to opa codebase

charlieegan3 commented 1 month ago

Certainly @kd-labs! Let us know how if you run into any issues.

Reviewing https://github.com/open-policy-agent/opa/pull/5576/files might be a good place to start.

stale[bot] commented 3 weeks ago

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.