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

Opa policy bundle with optimizations and future.keywords #4111

Closed
beepdot opened this issue Dec 8, 2021 · 3 comments · Fixed by #4115
Closed

Opa policy bundle with optimizations and future.keywords #4111

beepdot opened this issue Dec 8, 2021 · 3 comments · Fixed by #4115
Assignees
Labels

Comments

@beepdot
Copy link

beepdot commented Dec 8, 2021

Short description

Opa version: 0.34.2
When I use import future.keywords.in in a opa policy and then bundle it with optimization as 1 or 2, opa doesn't start and complains with an error. Please see below to reproduce.

main.rego

package main

allow {
  data.policy.valid
}

policy.rego

package policy

import future.keywords.in

valid {
  input.message in ["abc", "def"]
}

Creating the bundle with optimization level 0 works

opa build --bundle . --optimize 0 --entrypoint "main/allow"
opa run -s -b bundle.tar.gz
curl "localhost:8181/v1/data/main/allow" --data '{"input": {"message": "abc"}}'
{"result":true}

But creating the bundle with optimization level 1 or 2 doesn't start opa

opa build --bundle . --optimize 1 --entrypoint "main/allow"
opa run -s -b bundle.tar.gz 
error: load error: bundle bundle.tar.gz: 1 error occurred: /optimized/policy.rego:5: rego_parse_error: unexpected ident token: expected \n or ; or }
	__local0__2 in ["abc", "def"]
	            ^

Could you please tell me if I am doing something wrong? How can I achive optimizations 1 or 2 using future.keywords as imports.

@beepdot beepdot added the bug label Dec 8, 2021
@anderseknert
Copy link
Member

anderseknert commented Dec 8, 2021

Hi @keshavprasadms!

And thanks for filing this. I don't think you're doing anything wrong. That does indeed look like a bug.

I see the same behavior on HEAD.

@beepdot
Copy link
Author

beepdot commented Dec 8, 2021

@anderseknert Any info on when this can get fixed? Will the fix be available only in future release or will there be a patch to 0.34.x?

@tsandall tsandall added this to Backlog in Open Policy Agent via automation Dec 8, 2021
@tsandall tsandall moved this from Backlog to Planned - v0.36 in Open Policy Agent Dec 8, 2021
@tsandall
Copy link
Member

tsandall commented Dec 8, 2021

@keshavprasadms @srenatus is working on this right now. The fix will be released in v0.36.0 at the end of the month. If you need this backported, we could potentially cherry-pick it into v0.35.

@tsandall tsandall moved this from Planned - v0.36 to In Progress in Open Policy Agent Dec 8, 2021
Open Policy Agent automation moved this from In Progress to Done Dec 9, 2021
srenatus added a commit that referenced this issue Dec 9, 2021
When a module is formatted that has calls to `internal.member_2` or
`internal.member_3`, which get pretty-printed as infix `in` operator
calls, the formatter now ensures that the corresponding future keyword
import is present.

Fixes #4111.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

4 participants