Skip to content

Lavamoat build system integration for WebApp#12242

Merged
kumavis merged 10 commits intodevelopfrom
lavamoat-webapp-bg4
Oct 5, 2021
Merged

Lavamoat build system integration for WebApp#12242
kumavis merged 10 commits intodevelopfrom
lavamoat-webapp-bg4

Conversation

@kumavis
Copy link
Copy Markdown
Member

@kumavis kumavis commented Sep 29, 2021

🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋
the next step in incrementally locking down metamask:
providing the build process with a switch for adding lavamoat to each page
currently does not apply lavamoat to any page
🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋 🦊 🌋

summary of code changes

  • in app/*.html include a if-block to optionally apply lavamoat by loading the commonjs or lavamoat runtime. commonjs still needs an external lockdown script
  • in build/scripts.js change packer to lavapack, append policy loader, and render html with the useLavamoat switch
  • in lavamoat/browserify, add combined background and ui policies (ui policy is not enforced yet)
  • in lavamoat/node update policies to include running lavamoat and other added deps
  • in package.json add new scripts for generating lavamoat policies and add deps
  • in test/e2e/tests/contract-interactions.spec.js add delays to fix race condition
  • in yarn.locklavamoat dep additions

summary of work flow changes

  • after modifying dependencies or patches used in the background or ui, run yarn lavamoat:auto to update the policies. these policies are not applied yet, but makes PRs consistent with the future requirement where we will soon apply these policies when lavamoat is enabled.

things to be aware of

  • there is a change to workflow, see above
  • this pr was designed to be minimal and easy to revert
  • this version of LavaMoat was prepared to not require eval and requires no change to the manifest.
  • while this applies no protection to background or ui, it does changes the runtime of the ui and background (update to lavapack). All non-lavamoat pages now runs in a ses-shim like structure where a with statement is wrapping the globalThis. This is done to have a matching module initialization structure to the lavamoat protected components.
  • the application of this structure may have performance impacts, especially on low resource devices. This is already noticed in CI as additional timeouts were necessary. However, in QA on my machines performance has felt normal. Take this with a grain of salt.
  • this change is in preparation to applying lavamoat protections and bringing significant supplychain security enhancements to metamask
  • I am committed to polishing the developer experience in response to feedback

TODO:

@metamaskbot

This comment has been minimized.

@metamaskbot

This comment has been minimized.

@kumavis kumavis marked this pull request as ready for review September 30, 2021 07:22
@kumavis kumavis requested a review from a team as a code owner September 30, 2021 07:22
@kumavis kumavis force-pushed the lavamoat-webapp-bg4 branch from bbbb538 to f80c385 Compare September 30, 2021 18:31
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [f80c385]
Page Load Metrics (406 ± 49 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint825473658641
domContentLoaded28575938710149
load30777340610249
domInteractive28575938710149

@kumavis kumavis changed the title Lavamoat for WebApp background Lavamoat build system integration for WebApp Sep 30, 2021
@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Sep 30, 2021

TODO: review lockdown-run.js

browserPlatforms,
);
renderHtmlFile('home', groupSet, commonSet, browserPlatforms);
useLavamoat: false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to pass in useLavamoat as a CLI flag

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.

im not sure the usecase, can add later. would need to specify it for every entry/webpage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean so the Lavamoat build can be tested without modifying this file. You'd have to go through and swap every useLavamoat: false, to useLavamoat: true, right?

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.

makes sense

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Sep 30, 2021

Lavamoat policy validation is here: https://github.com/MetaMask/metamask-extension/blob/develop/.circleci/config.yml#L171
Which calls this script: https://github.com/MetaMask/metamask-extension/blob/develop/.circleci/scripts/validate-lavamoat-policy.sh

So because the lavamoat:auto script now automatically updates both, I think this PR works with that CI step already.

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Sep 30, 2021

request for QA on firefox esp wrt to popup init perf

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Sep 30, 2021

add debugging information if policy fails https://github.com/MetaMask/metamask-extension/blob/develop/.circleci/scripts/validate-lavamoat-policy.sh#L9

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [e464859]
Page Load Metrics (376 ± 44 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint2805823669043
domContentLoaded2705823569144
load2875823769244
domInteractive2705823569144

@brad-decker
Copy link
Copy Markdown
Contributor

Other than the popup init time issue I am 👍🏻 on this

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Oct 4, 2021

@brad-decker did you see a difference in pop perf time with lavamoat disabled as it is now?

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Oct 4, 2021

removing e2e test delays that are likely only required for actually turning lavamoat on

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Oct 4, 2021

ive gotten a few QA reports that firefox popup startup perf looks fine

brad-decker
brad-decker previously approved these changes Oct 4, 2021
Copy link
Copy Markdown
Contributor

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

With QA and my own testing not finding popup delays I'm good with this 💯

@kumavis
Copy link
Copy Markdown
Member Author

kumavis commented Oct 4, 2021

removing delays failed 😿

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [0612a3f]
Page Load Metrics (371 ± 41 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint706083358943
domContentLoaded2726113498641
load2896163718541
domInteractive2726113498641

Copy link
Copy Markdown
Contributor

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

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

lgtm after testing!

@kumavis kumavis merged commit cb174ff into develop Oct 5, 2021
@kumavis kumavis deleted the lavamoat-webapp-bg4 branch October 5, 2021 22:06
@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2021
@tmashuang tmashuang restored the lavamoat-webapp-bg4 branch October 6, 2021 16:36
@tmashuang tmashuang deleted the lavamoat-webapp-bg4 branch October 6, 2021 16:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants