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

wasm: capability restriction #13911

Merged
merged 43 commits into from
Feb 9, 2021

Conversation

ryanapilado
Copy link
Contributor

@ryanapilado ryanapilado commented Nov 5, 2020

Signed-off-by: Ryan Apilado [email protected]

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Commit Message: wasm: implement capability restriction
Additional Description: Defines the configuration for capability restriction and propagates the configuration to proxy-wasm-cpp-host.
Risk Level: Medium
Testing: Unit tests (wasm_test.cc), configuration tests (config_test), and integration tests (wasm_filter_test.cc). Test that capabilities can be restricted selectively and are unrestricted by default.
Docs Changes: Add documentation for the new messages created in wasm.proto.
Release notes: N/A

@antoniovicente
Copy link
Contributor

Thanks for the additional tests. What is missing before this PR is ready for review?

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #13911 was synchronize by ryanapilado.

see: more, trace.

@ryanapilado ryanapilado changed the title [WIP] add tests for proxy-wasm capability restriction [WIP] proxy-wasm abi restriction Nov 18, 2020
@ryanapilado ryanapilado changed the title [WIP] proxy-wasm abi restriction [WIP] proxy-wasm: abi restriction Nov 19, 2020
@ryanapilado ryanapilado force-pushed the capability-restriction-tests branch from 03d1ffb to f468a96 Compare November 19, 2020 02:26
@ryanapilado ryanapilado changed the title [WIP] proxy-wasm: abi restriction [WIP] wasm: abi restriction Nov 19, 2020
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
Signed-off-by: Ryan Apilado <[email protected]>
@@ -18,6 +18,12 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// [#protodoc-title: Wasm]
// [#extension: envoy.bootstrap.wasm]

// Configuration for restricting proxy-wasm capabilities available to modules.
message CapabilityRestrictionConfig {
// The list of proxy-wasm capabilities which will be exposed to the module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a reference to where the capabilities are defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a reference and updated the docs.

Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Signed-off-by: Ryan Apilado <[email protected]>
Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Thanks

@ryanapilado
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #13911 (comment) was created by @ryanapilado.

see: more, trace.

Base automatically changed from master to main January 15, 2021 23:01
// and so should be left empty.
//
// The capability names are given in the
// `proxy-wasm ABI <https://github.com/proxy-wasm/spec/tree/master/abi-versions/vNEXT>`_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/proxy-wasm/Proxy-Wasm/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -18,6 +18,26 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// [#protodoc-title: Wasm]
// [#extension: envoy.bootstrap.wasm]

// Configuration for restricting proxy-wasm capabilities available to modules.
message CapabilityRestrictionConfig {
// The proxy-wasm capabilities which will be allowed. Capabilities are mapped by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/proxy-wasm/Proxy-Wasm/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

map<string, SanitizationConfig> allowed_capabilities = 1;
}

// Configuration for sanitization of inputs to an allowed capability. NOTE: This is currently unimplemented.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move NOTE to a new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misunderstood this, fixed.

static bool createWasmInternal(const VmConfig& vm_config, const PluginSharedPtr& plugin,
const Stats::ScopeSharedPtr& scope,
static bool createWasmInternal(const VmConfig& vm_config,
const CapabilityRestrictionConfig& cr_config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/cr_config/capabilities_config, otherwie variable isn't self-describing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, changed to capabiility_restriction_config for consistency with type name and proto. Can change to capabilities_config if too long.

WASM_EXPORT(uint32_t, proxy_on_vm_start, (uint32_t context_id, uint32_t configuration_size)) {
(void)(context_id);
(void)(configuration_size);
std::string level_message = "after on_vm_start, before proxy_log";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/level_message/log_message/

Also, this message is written as part of proxy_log, not before proxy_log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

auto context = std::make_unique<TestContext>(wasm.get());
EXPECT_TRUE(wasm->initialize(code, false));

// on_vm_start will trigger proxy_log, but expect no call because both are restricted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should proxy_on_vm_start callback be even called considering that is not allowed? This is special case, since if we don't call proxy_on_vm_start then there is a high chance that plugin won't work correctly, but other callbacks should be skipped if they are not in the allowed capabilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the comment is incorrect, proxy_on_vm_start will never run in this case. Fixed. I also added a different callback to the wasm file (proxy_on_context_create) and adjusted the tests to test for it.

@ryanapilado
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #13911 (comment) was created by @ryanapilado.

see: more, trace.

@ryanapilado
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #13911 (comment) was created by @ryanapilado.

see: more, trace.

Signed-off-by: Ryan Apilado <[email protected]>
@PiotrSikora PiotrSikora requested a review from mathetake February 5, 2021 19:47
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lizan could you take a pass?

@repokitteh-read-only repokitteh-read-only bot removed the api label Feb 9, 2021
@lizan
Copy link
Member

lizan commented Feb 9, 2021

@envoyproxy/dependency-shepherds PTAL

@moderation
Copy link
Contributor

/lgtm deps

@repokitteh-read-only repokitteh-read-only bot removed the deps Approval required for changes to Envoy's external dependencies label Feb 9, 2021
@lizan lizan merged commit 47ad8ee into envoyproxy:main Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants