-
Notifications
You must be signed in to change notification settings - Fork 71
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
Implement a capability restriction system. #89
Implement a capability restriction system. #89
Conversation
Signed-off-by: Ryan Apilado <[email protected]>
21a78ee
to
05a3bca
Compare
Signed-off-by: Ryan Apilado <[email protected]>
05a3bca
to
0b28799
Compare
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
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.
Apologies for the late review.
BUILD
Outdated
@@ -9,6 +9,7 @@ cc_library( | |||
hdrs = glob(["include/proxy-wasm/**/*.h"]), | |||
deps = [ | |||
"@proxy_wasm_cpp_sdk//:common_lib", | |||
"@com_google_absl//absl/container:flat_hash_set", |
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 don't recall the reason, but John removed all uses of absl from this repo. Is there any reason why we need absl::flat_hash_set
here instead of using std::unordered_map
?
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 need to create allowed_capabilities
on the Envoy side and pass it to the WasmBase
constructor, but the Envoy formatter complains when I use unordered_set
or unordered_map
. So I had to switch it to absl::flat_hash_set
in both Envoy and here.
But I see that there is some code in Envoy that uses unordered_set
anyways, like here. Should I do the same?
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.
Ah, OK. Let's leave it then.
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.
FYI, https://github.com/proxy-wasm/proxy-wasm-cpp-host/blob/master/src/v8/v8.cc#L28-L29 John did not remove absl from V8
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.
Any thoughts on absl::flat_hash_set
, @mathetake? Should we completely remove it? Removing it from V8 would be trivial.
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.
Re: #89 (comment)
Should I change it to a std::unordered_map
then? Again, it goes against Envoy style guidelines, and at the moment, there are no uses of std::unordered_map
in Envoy.
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.
OK then, let's follow Envoy's style guide and stick to absl everywhere in this repo too. What I wanted was consistency. After merging, could you please replace std::unordered_**
with abls ones?
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.
Ok, sounds good!
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.
The reason for no absl
is that proxy-wasm-cpp-host can be used (at least in theory) by other proxies, not only Envoy, and we didn't want to force absl
as a dependency for them when the same containers are available in std
.
You should be able to "fix" the formatter warnings by adding relevant files to a whitelist (there are many of those for various formatter exclusions). Envoy has no business enforcing argument types in 3rd-party libraries.
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.
Ok, makes sense. Changed to std::unordered_map
here and in Envoy PR.
@mathetake @kyessenov could you take a look as well? |
77aa7f6
to
3ef808d
Compare
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
eeb98b8
to
0e09b31
Compare
Signed-off-by: Ryan Apilado <[email protected]>
0e09b31
to
a180877
Compare
👍 to 2) because it’s more independent of ABI versions and developer friendly. |
But then should we discuss this in proxy-wasm/spec first? I think we would better have more comments from the folks including SDK developers |
I think (2) definitely needs to be done, eventually. There are dependencies between some of the capabilities which aren't obvious (e.g. But maybe also having (1) could also be useful, for cases where more granular restriction is needed? (do such cases exist, or could we cover all reasonable restriction policies with the groups defined in (2)? I don't know). For example, maybe a user only wants to allow a subset of the gRPC capabilities, not all of them. And there are capabilities like So maybe
Internally, the capability bundles ( |
Signed-off-by: Ryan Apilado <[email protected]>
8de28c7
to
254328b
Compare
Signed-off-by: Ryan Apilado <[email protected]>
Updated to make Also updated the Envoy PR to match. |
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.
@ryanapilado could you merge master
to resolve conflicts? Thanks!
Regarding the (1) vs (2), WASI uses rights
that pretty much map 1:1 with function names (although, there are a few rights that grant permission to call multiple functions), which is much closer to (1) than (2). Unfortunately, they don't limit parameters, so we need to diverge from them.
Also, (2) can be always built on top of (1), but not the vice-versa, so let's get this in, and we can worry about (2) later.
@mathetake could you review this?
auto context = exports::ContextOrEffectiveContext( \ | ||
static_cast<ContextBase *>((void)raw_context, current_context_)); \ | ||
context->wasmVm()->error("Attempted call to restricted capability: " #_fn); \ | ||
return WasmResult::InternalFailure; \ |
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: @PiotrSikora we should have a new Wasm result like Unauthorized
as WASI's acces Permission denied.
(hopefully in the next ABI ). https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#variants-1
Resolved conflicts, merged master. |
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
03c170a
to
f37f375
Compare
Signed-off-by: Ryan Apilado <[email protected]>
Adding a small change in anticipation of implementing (1), PTAL. It's not enough to have a vector of strings, we also need a parameter to control whether it behaves as an allowlist or denylist. So the capabilities now map to a struct |
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 sans the nit.
@ryanapilado could you fix the Envoy PR? I would like to merge this, but Envoy PR doesn't even build right now. Thanks.
Signed-off-by: Ryan Apilado <[email protected]>
…-wasm-cpp-host into capability-restriction
My bad, Envoy PR seems ok now. |
include/proxy-wasm/exports.h
Outdated
}; | ||
FOR_ALL_HOST_FUNCTIONS(_CREATE_EXPORT_STUB) | ||
FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_CREATE_EXPORT_STUB) | ||
FOR_ALL_WASI_FUNCTIONS(_CREATE_EXPORT_STUB) |
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.
For WASI, I think it would be better if we had a dedicated stub that returns __WASI_ENOTCAPABLE
(76
), since WASI modules should be aware of that error code, and they know nothing about Proxy-Wasm return values.
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Implement a mechanism to restrict which proxy-wasm ABI functions are made available to the module. Functions which are restricted are replaced with a stub.
Envoy-side implementation and tests.
Signed-off-by: Ryan Apilado [email protected]