Skip to content

Add restricted controller messenger - #378

Merged
Gudahtt merged 13 commits into
developfrom
restricted-controller-messenger
Apr 14, 2021
Merged

Gudahtt merged 13 commits into
developfrom
restricted-controller-messenger

Conversation

@Gudahtt

@Gudahtt Gudahtt commented Mar 8, 2021

Copy link
Copy Markdown
Member

A method has been added to the controller messenger that returns a restricted instance of the controller messenger. This instance is restricted to registering actions and events within a particular namespace, typically being the name of the controller. Access to event subscriptions and calling actions is also restricted based on the given allowlist for each.

This is meant to address feedback left on the Controller Messaging System proposal.

@Gudahtt

Gudahtt commented Mar 8, 2021 •

Copy link
Copy Markdown
Member Author

This depends upon #377

@Gudahtt
Gudahtt force-pushed the controller-messaging branch from 159d49e to 756e986 Compare March 8, 2021 14:38
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from 30751bd to d5cb725 Compare March 8, 2021 14:38
@Gudahtt Gudahtt changed the title Add restricted controller Add restricted controller messenger Mar 8, 2021
@Gudahtt

Gudahtt commented Mar 8, 2021

Copy link
Copy Markdown
Member Author

My objective with this restricted messaging system was to prevent accidental use of methods beyond the intended access. I'm not protecting against access to private methods/properties, or anything sneaky like that. We have lint rules and types to protect against us doing that. This approach isn't adequate for dealing with untrusted code. I don't think we'll be using the controller messaging system for untrusted code though - at least not directly.

The snaps API will likely use the messaging system, but it will use other means to prevent unintended access (e.g. an RPC layer, SES, the permission system, etc.).

@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from d5cb725 to 4433aa7 Compare March 8, 2021 16:12
@Gudahtt
Gudahtt force-pushed the controller-messaging branch from 756e986 to 5202621 Compare March 8, 2021 18:20
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch 3 times, most recently from 993d382 to 53cc024 Compare March 8, 2021 21:26
Comment thread src/ControllerMessenger.ts Outdated
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch 3 times, most recently from 4a885cc to 626fd07 Compare March 9, 2021 05:31
Comment thread src/BaseControllerV2.test.ts Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the most complete example so far. It demonstrates calling an action and subscribing to an event in another controller.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I love it. 😍

@Gudahtt
Gudahtt force-pushed the controller-messaging branch from c4fb8f4 to c267a31 Compare March 11, 2021 04:14
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from e8cb578 to e7bb905 Compare March 11, 2021 04:14
@Gudahtt
Gudahtt force-pushed the controller-messaging branch from c267a31 to 1671284 Compare March 11, 2021 16:52
Base automatically changed from controller-messaging to develop March 11, 2021 17:32
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from e7bb905 to a97dfe4 Compare March 11, 2021 17:32
@Gudahtt
Gudahtt marked this pull request as ready for review March 11, 2021 17:40
@Gudahtt
Gudahtt requested a review from a team as a code owner March 11, 2021 17:40
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from a97dfe4 to be56e2b Compare March 12, 2021 17:31
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch 5 times, most recently from 99cd49d to 2e7b0b6 Compare March 19, 2021 20:11
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from 94d73b9 to e660361 Compare March 23, 2021 18:11
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from d387679 to 47e0cab Compare April 7, 2021 16:20
@rekmarks rekmarks self-assigned this Apr 12, 2021

@rekmarks rekmarks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bunch of nits, but overall I think this rules.

Comment thread src/ControllerMessenger.ts Outdated
Comment thread src/ControllerMessenger.ts Outdated
Comment thread src/ControllerMessenger.test.ts Outdated
Comment thread src/BaseControllerV2.test.ts Outdated
Comment thread src/BaseControllerV2.test.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I love it. 😍

Gudahtt added 11 commits April 13, 2021 19:36
A method has been added to the controller messenger that returns a
_restricted_ instance of the controller messenger. This instance is
restricted to registering actions and events within a particular
namespace, typically being the name of the controller. Access to event
subscriptions and calling actions is also restricted based on the given
allowlist for each.

This is meant to address feedback left on the Controller Messaging
System proposal[1].

[1]: https://www.notion.so/Controller-Messaging-System-617efb02b9e54bd0a0b0e44c6f776d85
The parameters for `getRestricted` were moved into an object, to
improve readability.
The "controllerName" option has been renamed to "name", so as to not
assume that the name is of a controller.
All methods now have corresponding JSDoc comments.
Previously the Base Controller would not accept any action types, and
it would only accept the single action it used. Now it accepts any
types, so long as the required type is present.
There is now a unit test that demonstrates inter-controller
communication using the controller messaging system. This is a Base
Controller test because it's also testing the Base Controller's
messenger integration at the same time.
This requirement was added recently in #422
Comments have been added alongside each `istanbul ignore if` statement
explaining why it was required.
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from 47e0cab to d25bb8e Compare April 13, 2021 23:09
Gudahtt added 2 commits April 13, 2021 20:43
The new tests cover restricted messenger instances with access to both
internal and external events and actions.
@Gudahtt
Gudahtt force-pushed the restricted-controller-messenger branch from d25bb8e to d028d1b Compare April 13, 2021 23:13
@Gudahtt

Gudahtt commented Apr 13, 2021

Copy link
Copy Markdown
Member Author

This has been rebased, and all comments have been addressed.

@rekmarks rekmarks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's gooo!

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.

3 participants