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

Protect private segment functions when called from the same node #296

Open
petermasking opened this issue May 22, 2023 · 1 comment
Open
Assignees
Labels
feature New feature or request runtime Improvements or additions to the runtime package

Comments

@petermasking
Copy link
Member

Currently, we only protect the access to segmented functions when called remote. This means that private functions from another segment can be called when both segments are placed on the same node. To assure a consistent behavior we need to add an additional level of protection.

For the implementation we need to change local repository. Module files are currently requested by client id that is bound to one or more segments. We need to change this to requesting module files per segments.

Before

GET http://repository/modules/{clientId}/file.js

After

GET http://repository/modules/{segmentName}/file.js
@petermasking petermasking added feature New feature or request runtime Improvements or additions to the runtime package labels May 22, 2023
@basmasking basmasking self-assigned this Jun 27, 2023
@basmasking basmasking removed their assignment Mar 1, 2024
basmasking added a commit that referenced this issue Mar 19, 2024
petermasking added a commit that referenced this issue Apr 5, 2024
mandatory caller in imports.
petermasking added a commit that referenced this issue May 13, 2024
basmasking added a commit that referenced this issue May 13, 2024
petermasking added a commit that referenced this issue May 14, 2024
@petermasking
Copy link
Member Author

We've been working on this issue for a while now and tried to implement the suggested setup. This failed quite early because workers can request the same module multiple times from multiple segments. In the current setup, there wasn't a way to figure out the requesting segment. So we had to go back to the drawing board.

To overcome this problem we refactored the requesting strategy to track where the request was coming from. For this we added a caller parameter.

GET http://repository/modules/file.js?caller=otherfile.js

With this addition information, the repository can check if both files share a segment. If they do the real implementation gets provided, otherwise the remote implementation. This strategy works very well, but introduces a change that has set us to think.

The ESM system caches modules based on their origin. Meaning that in the current setup modules are cached per client (id). No matter the segment, the same module is provided for any request. In the new setup this has changed to caching per
module/caller pair. Effectively this leads more overhead in the memory used. But this isn't something we're worried about yet. We've got another fish to fry first.

Every uniquely loaded module has it's own isolated scope. In this scope state can be kept. Since building distributed systems require stateless components, this new setup forces to keep everything stateless. Great right? For most case, absolutely. But as always, there are exceptions. For example, you might want to share a database connection (pool) with all components running on a worker. The new setup doesn't allow this, so we have to go back to the drawing board again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request runtime Improvements or additions to the runtime package
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants