Skip to content
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

Building bundle with optimization breaks metadata annotation parsing #6529

Open
anderseknert opened this issue Jan 17, 2024 · 0 comments · May be fixed by #6593
Open

Building bundle with optimization breaks metadata annotation parsing #6529

anderseknert opened this issue Jan 17, 2024 · 0 comments · May be fixed by #6593
Assignees
Labels

Comments

@anderseknert
Copy link
Member

cwd

.
└── bundle
    └── p.rego

bundle/p.rego

package p

a := 1

# METADATA
# description: a
# entrypoint: true
b := 2

# METADATA
# description: b
# entrypoint: true
c := 3
opa build -O=1 --bundle bundle/
opa eval -b bundle.tar.gz data.p
{
  "errors": [
    {
      "message": "loading error: bundle bundle.tar.gz: 1 error occurred: /bundle/p.rego:9: rego_parse_error: yaml: line 4: could not find expected ':'\n\t# description: b\n\t^"
    }
  ]
}

Looking inside of the optimized bundle, the p.rego file does indeed look broken wrt metadata:

p.rego (inside bundle.tar.gz)

package p

a := 1

# METADATA
# description: a
# entrypoint: true
# METADATA
# description: b
# entrypoint: true

The b and c rules have been moved to different files under the optimized directory, but since the metadata annotations haven't moved with them, they'll no longer be scoped to those rules.

Interestingly, running opa eval -O=1 --bundle bundle/ — i.e. on the directory directly (without passing opa build) does not produce this error, so presumably it does not do the same optimization?

Reported to me by @nevumx

@ashutosh-narkar ashutosh-narkar added this to Backlog in Open Policy Agent via automation Jan 25, 2024
@ashutosh-narkar ashutosh-narkar moved this from Backlog to Planning - v0.62 in Open Policy Agent Jan 29, 2024
@ashutosh-narkar ashutosh-narkar moved this from Planning - v0.62 to In Progress in Open Policy Agent Jan 29, 2024
@ashutosh-narkar ashutosh-narkar self-assigned this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Open Policy Agent
  
In Progress
Development

Successfully merging a pull request may close this issue.

2 participants