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 fails to load bundle when optimizations are enabled #4018

Closed
torsrex opened this issue Nov 16, 2021 · 2 comments · Fixed by #4019
Closed

OPA fails to load bundle when optimizations are enabled #4018

torsrex opened this issue Nov 16, 2021 · 2 comments · Fixed by #4019
Labels

Comments

@torsrex
Copy link

torsrex commented Nov 16, 2021

OPA fails to load bundle when optimizations are enabled.

Expected Behavior

First running opa build -O=1 . -e rules/main/allowed and then opa run -s -b bundle.tar.gz should successfully start the server.

Actual Behavior

The exceptions shown in the image below are thrown:
image

Here is the corresponding un-optimized rego code:

bearer_token(auth_header) = t {
	startswith(auth_header, "Bearer ")
	parts := split(auth_header, " ")
	count(parts) == 2
	t := parts[1]
}

And the optimized rego code:

bearer_token(__local15__6) = __local17__6 {
	startswith(
		__local15__6,
		"Bearer ",
	)
	split(
		__local15__6, __local57__6,
		" ",
	)
	__local16__6 = __local57__6
	count(__local16__6, __local58__6)
	__local58__6 = 2
	__local17__6 = __local16__6[1]
}

Creating the same bundle without optimizations by using opa build . -e rules/main/allowed allows the server to be started normally:

image

Steps to Reproduce the Problem

  • OPA version:
Version: 0.34.2
Build Commit: 9f11f21
Build Timestamp: 2021-11-10T18:33:08Z
Build Hostname: Mac-1636569091949.local
Go Version: go1.17.3
WebAssembly: available
@srenatus
Copy link
Contributor

Interesting, thanks for bringing this up. I wonder what's going on there.

	split(
		__local15__6, __local57__6,
		" ",
	)

should be

	split(
		__local15__6, 	" ",
		__local57__6,
	)

This could be an issue in the formatter, too, perhaps an unintended side-effect of #3864 🤔

@srenatus srenatus added the bug label Nov 16, 2021
@srenatus
Copy link
Contributor

srenatus commented Nov 16, 2021

Yep definitely related to that formatter change. The formatter is used when a bundle is created to put "pretty" code into the bundle. Here, there are new variables used, and the algorithm that's determining how the arguments are supposed to be laid out breaks when it sees one "real" argument (" ") and a bunch of synthetic ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants