-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
topdown+wasm: Verifying host based on allow_net allowlist in built-in functions #4152
topdown+wasm: Verifying host based on allow_net allowlist in built-in functions #4152
Conversation
This implementation only applies to the |
5f22d52
to
161cdbe
Compare
… functions Adding host allow-listing based on the allow_net capability in the http.send()- and net.lookup_ip_addr() built-in functions when running the eval command. Fixes: open-policy-agent#3665 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
161cdbe
to
de8875c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nitpicks, questions; but this looks good!
ast/compile.go
Outdated
@@ -86,6 +86,9 @@ type Compiler struct { | |||
// with the key being the generated name and value being the original. | |||
RewrittenVars map[Var]Var | |||
|
|||
// Capabilities is the user-supplied capabilities or features allowed for OPA. | |||
Capabilities *Capabilities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing this technically means it could be messed with. However, WithCapabilities()
already allows that, so I guess we're OK. Alternatively, we could do
func (c *Compiler) Capabilities() *Capabilities {
return c.capabilities
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is precedence for direct access for other fields, but if a function is preferred, I can add one. The only drawback would be that it might look haphazard to a user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about this, too, it's the only part of this PR that worries me. Once we expose this as a field, we can never go back or change or structures or something.
Having a getter function would leave us done wiggle room. I'd prefer we go with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright! Will fix.
rego/rego_wasmtarget_test.go
Outdated
|
||
serverUrl, err := url.Parse(ts.URL) | ||
if err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
panic(err) | |
t.Fatal(err) |
topdown/http_test.go
Outdated
|
||
resultObj, err := ast.InterfaceToValue(expectedResult) | ||
if err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Let's either do t.Fatal(err)
here, or use resultObj := ast.MustInterfaceToValue(expectedResult)
above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, will fix.
"allow_net match + additional host": {addr, "example.com"}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Do we somehow need the cancel here? We night just do ctx := context.Background()
; but I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I thing you're right. This is a copy/paste I didn't clean up properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, all other test cases use cancel. I'll keep this as-is, just to be in line with the rest of them. However, this might be unnecessary in all cases.
@@ -305,7 +335,7 @@ func createHTTPRequest(bctx BuiltinContext, obj ast.Object) (*http.Request, *htt | |||
var strVal string | |||
|
|||
if s, ok := obj.Get(val).Value.(ast.String); ok { | |||
strVal = string(s) | |||
strVal = strings.Trim(string(s), "\"") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK given the existing code, but something here doesn't seem correct to me. Why are there extra "
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I don't get this either; but I didn't want to change existing functionality.
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like something worth documenting. (Even more so if it'll become available beyond opa eval
)
Changes look good to me, thanks!
Good point! Will find a suitable place to add to the docs. |
Adding documentation. Signed-off-by: Johan Fylling <johan.dev@fylling.se>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Adding host allow-listing based on the allow_net capability in the http.send()- and
net.lookup_ip_addr() built-in functions when running the eval command.
Fixes: #3665
Signed-off-by: Johan Fylling johan.dev@fylling.se