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

Policy ID for bundle modules adds extra path prefix #2117

Closed
patrick-east opened this issue Feb 18, 2020 · 0 comments · Fixed by #2274
Closed

Policy ID for bundle modules adds extra path prefix #2117

patrick-east opened this issue Feb 18, 2020 · 0 comments · Fixed by #2274
Assignees
Labels

Comments

@patrick-east
Copy link
Contributor

patrick-east commented Feb 18, 2020

If I have a bundle directory like:

policy/example
policy/example/http
policy/example/http/authz.rego
policy/example/http/authz
policy/example/policy.rego

When loaded like:

opa run -s -b ./policy

The policies show up with id's that are prefixed with policy twice (and a leading / which causes other problems... #2116 )

Ex:

{12:11} ~/p/g/s/g/o/opa:issue/2099 ✓ ❯ curl -s -X GET 'http://localhost:8181/v1/policies' | jq
{
  "result": [
    {
      "id": "/policy/policy/example/http/authz.rego",
<snip>

Additional Info

I believe some of this is for prefixing bundle paths to make them unique between bundles (normally its using the actual bundle file name like authz.tar.gz or whatever) but it defaults to using the directory when loaded this way. What we might want to do is remove the leading slash, if possible, and try to avoid just repeating the directory base name (its kind of confusing to look at the id as-is).

patrick-east added a commit to patrick-east/opa that referenced this issue Apr 7, 2020
Previously if we provided a "root" to the bundle directory loader that
was a relative path, it would matter whether or not it was prefixed
with "./". The logic to trim that path from the paths found walking
the root was not taking into account the prefix so the resulting ones
that had "./" would leave behind the root path.

Later on the bundle loader would generate a "full" path to set on the
module file for its location which is the root+path.. which resulted
in duplicate "root"s on those id's.

To fix this we just normalize the relative paths in the directory
loader so that we can not worry about what type of relative path it
is.

Fixes: open-policy-agent#2117
Signed-off-by: Patrick East <east.patrick@gmail.com>
@patrick-east patrick-east self-assigned this Apr 7, 2020
patrick-east added a commit that referenced this issue Apr 8, 2020
Previously if we provided a "root" to the bundle directory loader that
was a relative path, it would matter whether or not it was prefixed
with "./". The logic to trim that path from the paths found walking
the root was not taking into account the prefix so the resulting ones
that had "./" would leave behind the root path.

Later on the bundle loader would generate a "full" path to set on the
module file for its location which is the root+path.. which resulted
in duplicate "root"s on those id's.

To fix this we just normalize the relative paths in the directory
loader so that we can not worry about what type of relative path it
is.

Fixes: #2117
Signed-off-by: Patrick East <east.patrick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant