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

Absolute paths do not work with rego.Load on Windows #4521

Open
lcarva opened this issue Mar 30, 2022 · 9 comments
Open

Absolute paths do not work with rego.Load on Windows #4521

lcarva opened this issue Mar 30, 2022 · 9 comments

Comments

@lcarva
Copy link
Contributor

lcarva commented Mar 30, 2022

Short description

When using rego.Load with an absolute path on Windows, the following error is returned when Rego.PrepareForEval is called:

1 error occurred during loading: CreateFile \Users\RUNNER~1\AppData\Local\Temp\TestRegoPolicyLoadAbsolutePath3698015745\001\policy.rego: The system cannot find the path specified.

The issue does not occur if a relative path is used. The issue does not work on Linux or OSX.

Steps To Reproduce

policy := `
	package signature

	allow {
		input.predicateType == "https://slsa.dev/provenance/v0.2"
	}
`
// This alternative line works:
// policyFile := "policy.rego"
policyFile := filepath.Join(t.TempDir(), "policy.rego")
if err := os.WriteFile(policyFile, []byte(policy), 0644); err != nil {
	t.Fatal(err)
}
r := rego.New(rego.Query("data.signature.allow"), rego.Load([]string{policyFile}, nil))

ctx := context.Background()

// This fails on Windows Server 2022.
_, err := r.PrepareForEval(ctx)
if err != nil {
	t.Fatal(err)
}

Expected behavior

PrepareForEval should not return an error.

Additional context

I created a small git repo to reproduce this issue. The test TestRegoPolicyLoadAbsolutePath fails, while the test TestRegoPolicyLoadRelativePath passes. The GitHub actions were useful in running the tests across different Operating Systems. I'm not sure how long the results will last, but here's a link to them.

@stale
Copy link

stale bot commented Apr 29, 2022

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

@stale stale bot added the inactive label Apr 29, 2022
@anderseknert
Copy link
Member

Hey @lcarva! Sorry for not acknowledging this before, but that definitely seems like a bug. If anyone with a Windows machine would consider taking a look at this, that would be much appreciated!

@lcarva
Copy link
Contributor Author

lcarva commented Apr 29, 2022

@anderseknert, no worries! FWIW, it's possible to reproduce the issue with just GitHub actions as mentioned in the description. It's definitely not as easy to debug as a local system, but a potential way forward.

@stale stale bot removed the inactive label Apr 29, 2022
@stale
Copy link

stale bot commented May 29, 2022

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

@stale stale bot added the inactive label May 29, 2022
@lcarva
Copy link
Contributor Author

lcarva commented May 31, 2022

Still failing on opa v0.40.0 with the same error.

@stale stale bot removed the inactive label May 31, 2022
@anderseknert
Copy link
Member

Yes, no changes here, @lcarva. The stalebot warning does not mean it's being closed/removed, just that there's not been any activity for some time.

@stale
Copy link

stale bot commented Jul 2, 2022

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

@stale stale bot added the inactive label Jul 2, 2022
@simar7
Copy link

simar7 commented Jul 11, 2023

Still seems to be the case on v0.54.0.

@stale stale bot removed the inactive label Jul 11, 2023
simar7 added a commit to aquasecurity/trivy that referenced this issue Jul 11, 2023
Need this as OPA is currently broken on Windows

open-policy-agent/opa#4521

Signed-off-by: Simar <simar@linux.com>
github-merge-queue bot pushed a commit to aquasecurity/trivy that referenced this issue Jul 17, 2023
* feat(misconf): Support custom data for cloud policies

Signed-off-by: Simar <simar@linux.com>

* use policyfs

Signed-off-by: Simar <simar@linux.com>

* refactor to reduce cyclomatic complexity

Signed-off-by: Simar <simar@linux.com>

* bump defsec

* update docs

Signed-off-by: Simar <simar@linux.com>

* update test assertion

Signed-off-by: Simar <simar@linux.com>

* update test

Need this as OPA is currently broken on Windows

open-policy-agent/opa#4521

Signed-off-by: Simar <simar@linux.com>

* fix data path

* fix(mapfs): convert volume names into dirs

* revert creating temp dirs

---------

Signed-off-by: Simar <simar@linux.com>
Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
@stale
Copy link

stale bot commented Aug 10, 2023

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.

@stale stale bot added the inactive label Aug 10, 2023
AnaisUrlichs pushed a commit to AnaisUrlichs/trivy that referenced this issue Aug 10, 2023
…ecurity#4745)

* feat(misconf): Support custom data for cloud policies

Signed-off-by: Simar <simar@linux.com>

* use policyfs

Signed-off-by: Simar <simar@linux.com>

* refactor to reduce cyclomatic complexity

Signed-off-by: Simar <simar@linux.com>

* bump defsec

* update docs

Signed-off-by: Simar <simar@linux.com>

* update test assertion

Signed-off-by: Simar <simar@linux.com>

* update test

Need this as OPA is currently broken on Windows

open-policy-agent/opa#4521

Signed-off-by: Simar <simar@linux.com>

* fix data path

* fix(mapfs): convert volume names into dirs

* revert creating temp dirs

---------

Signed-off-by: Simar <simar@linux.com>
Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants