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

Fix the mismatch between specifier and resource identifier in attenuators policy AND allow skiping powerless packages #1838

Merged
merged 6 commits into from
Dec 12, 2023

Conversation

naugtur
Copy link
Member

@naugtur naugtur commented Oct 26, 2023

Update:

The problem identified when fixing attenuators policy turns out to not exist when we allow skipping setting empty values for policy resources for packages we want to endow no powers to.
I decided to solve that right away.

The current state of the PR is a work in progress, but it's only missing some test coverage for error hints and some hint improvements.


The issue is a mismatch between a specifier and a resource id AKA cannonical name in:
https://github.com/endojs/endo/blob/master/packages/compartment-mapper/src/policy.js#L158
the right policy value for @a/b/custom-export is @a/b and I need to add a proper conversion there.

@naugtur naugtur force-pushed the naugtur-fix-attenuator-nested-export branch from 8ad2406 to 2cd6a72 Compare November 2, 2023 11:44
@naugtur naugtur self-assigned this Nov 2, 2023
@naugtur naugtur requested a review from kriskowal November 2, 2023 13:33
@naugtur naugtur marked this pull request as ready for review November 2, 2023 13:34
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

It’s not clear to me at a glance how the change effects the fix described but we can talk that thru at next sync.

if (module.compartment !== undefined) {
if (
module.compartment !== undefined &&
compartmentRenames[module.compartment] !== undefined
Copy link
Member

Choose a reason for hiding this comment

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

We need to evaluate more rigorously throughout compartment-mapper how to handle cases like module.compartment being toString or __proto__. The undefined check is fine for a constant name, but we should use an own property check here.

@naugtur
Copy link
Member Author

naugtur commented Nov 2, 2023

It’s not clear to me at a glance how the change effects the fix described but we can talk that thru at next sync.

The fix for attenuators is to allow importing all into the attenuators compartment instead of trying to resolve a specifier into a policy resource identifier, which is a lot of work and implemented far away :)

The fix in archive is pretty much independent, but the switch to packages: 'any' in attenuators compartment policy caused a pre-existing bug to surface.
The line I removed and replaced with a comment in archive.js was never reached in testing. Otherwise it would fail, because soon after the compartment map translation is performed, validation rejects a compartment map which has an undefined compartment for a module.
My fixtures for policy testing happen to trigger that error now, while previously the list of modules for the attenuators compartment was trimmed by the policy to not include the one that doesn't get retained in an archive.

I'm looking forward to discussing my assumptions and decisions. Don't mind keeping this open till Wed, but I'm not sure if I'm gonna be able to attend while at NodeConfEU. We'll see.

@kriskowal
Copy link
Member

@naugtur Good enough for me!

boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 3, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 8, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 9, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 15, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 15, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 15, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 22, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 22, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 22, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 23, 2023
@naugtur naugtur changed the title Fix the mismatch between specifier and resource identifier in attenuators policy Fix the mismatch between specifier and resource identifier in attenuators policy AND allow skiping powerless packages Nov 23, 2023
packages[specifier] = true;
return packages;
}, {}),
packages: 'any',
Copy link
Member Author

Choose a reason for hiding this comment

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

this removed section had the bug where we mistook specifier for a resource id. and it was all unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

I trust that https://www.npmjs.com/package/any is not an issue with this property’s range of expressible values?

Copy link
Member Author

Choose a reason for hiding this comment

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

packages is normally a key/value map. there's only one string value allowed and that's the "any". There's no room for a mistake here

@naugtur naugtur force-pushed the naugtur-fix-attenuator-nested-export branch from 5c1bc06 to bd08203 Compare November 27, 2023 12:04
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 27, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Nov 27, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 6, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 8, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 8, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 8, 2023
@naugtur naugtur force-pushed the naugtur-fix-attenuator-nested-export branch from 7fbb651 to db2545b Compare December 12, 2023 08:11
packages[specifier] = true;
return packages;
}, {}),
packages: 'any',
Copy link
Member

Choose a reason for hiding this comment

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

I trust that https://www.npmjs.com/package/any is not an issue with this property’s range of expressible values?

/**
* Throws if importing of the specifier is not allowed by the policy
*
* @param {string} specifier
* @param {object} compartmentDescriptor
* @param {import('./types.js').CompartmentDescriptor} compartmentDescriptor
* @param {object} [info]
Copy link
Member

Choose a reason for hiding this comment

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

Can this info type be made more specific?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll unwrap errorHint

'policy - nested export in attenuator',
test,
fixture,
combineAssertions(
Copy link
Member

Choose a reason for hiding this comment

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

I missed when we got an assertions combinator. Neat.

Copy link
Member Author

Choose a reason for hiding this comment

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

Counting the expected number of assertions remains annoying tho.

@kriskowal kriskowal merged commit 98b1712 into master Dec 12, 2023
14 checks passed
@kriskowal kriskowal deleted the naugtur-fix-attenuator-nested-export branch December 12, 2023 19:41
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 12, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 15, 2023
boneskull added a commit to LavaMoat/LavaMoat that referenced this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants