Skip to content

Add Lavamoat to build system#9939

Merged
kumavis merged 12 commits intodevelopfrom
lavamoat-buildsystem
Feb 22, 2021
Merged

Add Lavamoat to build system#9939
kumavis merged 12 commits intodevelopfrom
lavamoat-buildsystem

Conversation

@EtDu
Copy link
Copy Markdown
Contributor

@EtDu EtDu commented Nov 24, 2020

This PR aims to add LavaMoat in the MetaMask build system.

  • Introduces patch-package to work around SES compatibility issues in deep dependencies
  • Add explicit imports for babel plugins and presets
  • Browserify: use explicit require statements to import plugins & transforms
  • Browserify: use explicit imports for transforms in dependencies (required for static analysis)
  • Remove redundant gulp-sass assignment to compiler

Regular config modifications:

  • Fix deep endowments bug: remove .match from process.version
  • Remove .call from hasOwnProperty & stream.Stream
    Lavamoat fails to dedupe configuration when merging override configuration (E.G. x.y & x.y.z)

Override config additions:

  • Endow babel presets & plugins manually (dynamic require)
  • Endow to @babel/core for reading babel config
  • Endow Browerify transform loose-envify
  • Endow post-css iterations to stylelint (lazy-import)
  • incomplete parsing: vinyl, colorette, node-sass

@EtDu EtDu requested review from a team and kumavis as code owners November 24, 2020 07:08
@EtDu EtDu requested a review from darkwing November 24, 2020 07:08
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@EtDu EtDu force-pushed the lavamoat-buildsystem branch from e9d9340 to d6aacf5 Compare November 24, 2020 07:13
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [d6aacf5]
Page Load Metrics (463 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint3096542110
domContentLoaded3025864619344
load3035874639345
domInteractive3025864619344

@EtDu EtDu force-pushed the lavamoat-buildsystem branch from d6aacf5 to 60da67e Compare December 1, 2020 02:01
@EtDu EtDu added the DO-NOT-MERGE Pull requests that should not be merged label Dec 1, 2020
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [111772b]
Page Load Metrics (539 ± 49 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33112562311
domContentLoaded34166253710148
load34266353910149
domInteractive34166153610148

@EtDu EtDu force-pushed the lavamoat-buildsystem branch from 111772b to 9cdd7ff Compare December 4, 2020 04:32
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [8dbc38a]
Page Load Metrics (463 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint3910068189
domContentLoaded32865646111354
load33065846311354
domInteractive32865546011354

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [45b3e50]
Page Load Metrics (414 ± 48 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31347696632
domContentLoaded26260441210048
load26460741410148
domInteractive26260441110048

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [96b8ee4]
Page Load Metrics (595 ± 46 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint337651126
domContentLoaded3468255939646
load3488265959646
domInteractive3468245939646

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [dcc16e5]
Page Load Metrics (516 ± 14 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31624794
domContentLoaded3985415132914
load3995435163014
domInteractive3975415132914

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Dec 17, 2020

wow nice, this is ready

@kumavis kumavis removed the DO-NOT-MERGE Pull requests that should not be merged label Dec 17, 2020
@kumavis
Copy link
Copy Markdown
Member

kumavis commented Dec 17, 2020

this pr is ready but i recommend waiting til after the holiday

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Jan 23, 2021

Now that v9 is out, I think we're ready to start trying to land this. Could you rebase this on develop?

@kumavis kumavis force-pushed the lavamoat-buildsystem branch from dcc16e5 to fd144d0 Compare January 28, 2021 02:08
@kumavis kumavis dismissed a stale review via 56f8429 February 6, 2021 12:33
@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 8, 2021

🦇 🦇 🦇 🦇 🦇 🦇 🦇 🦇 🦇 🦇

build completed. task timeline:
█ clean NaNs
█ styles:prod NaNs
█ manifest:prod NaNs
█ scripts:core:prod:disable-console NaNs
█ scripts:core:prod:initSentry NaNs
█ scripts:core:prod:phishing-detect NaNs
█ scripts:core:prod:contentscript NaNs
█ scripts:deps:ui NaNs
█ scripts:deps:background NaNs
█ static:prod NaNs
█ scripts:core:prod:background NaNs
█ scripts:core:prod:ui NaNs
█ zip NaNs
█ prod NaNs

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [cf71e92]
Page Load Metrics (607 ± 24 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint49806194
domContentLoaded5337686055024
load5347736075124
domInteractive5337686045024

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 8, 2021

  • de-conflict
  • fix task timers
  • fix lavamoat-viz
  • attempt to minimalize PR diffs
  • QA dev mode

@kumavis kumavis force-pushed the lavamoat-buildsystem branch from cf71e92 to 92afbc1 Compare February 8, 2021 09:50
@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 8, 2021

just did a manual squash + rebase

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [92afbc1]
Page Load Metrics (531 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint447956105
domContentLoaded3776185307033
load3796195317033
domInteractive3776185297033

@kumavis kumavis force-pushed the lavamoat-buildsystem branch from 11a0576 to 92afbc1 Compare February 8, 2021 10:16
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [92afbc1]
Page Load Metrics (1280 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint102148124147
domContentLoaded1085146712769445
load1088146812809345
domInteractive1084146712769445

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [115911a]
Page Load Metrics (656 ± 49 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint478863115
domContentLoaded55998865510349
load56198965610349
domInteractive55998765510349

Comment thread .prettierignore Outdated
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [5f5e489]
Page Load Metrics (666 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint508766105
domContentLoaded4338426649345
load4348446669345
domInteractive4328426649345

Comment thread patches/graceful-fs+4.2.3.patch Outdated
Comment thread patches/graceful-fs+4.2.3.patch Outdated
Comment thread patches/readable-stream+2.3.6.patch Outdated
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

I tried testing this by deleting the readable-stream patch, updating the graceful-fs patch, and updating the policy file by running yarn lavamoat --autopolicy ./development/build/index.js prod. There are lots of new console warnings now during the build 🤔

Lots of new Buffer constructor deprecation warnings:

[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

and many from LavaMoat about attempts to write read-access globals.

The Buffer warnings appeared to be from packages that we were using before, so I'm unsure why they didn't show up before 🤔.

I'm guessing the approach taken with the LavaMoat warnings is to assume the write attempts weren't all that important? I'm unsure how to investigate further, as the warning doesn't indicate where the write attempt occurred.

Comment thread patches/stylelint+13.6.1.patch
Comment thread patches/plugin-error+1.0.1.patch
Comment thread patches/gulp-livereload++chalk+2.4.2.patch Outdated
@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 18, 2021

should review console warnings

@EtDu EtDu force-pushed the lavamoat-buildsystem branch from 5f5e489 to 8fc7b20 Compare February 18, 2021 04:59
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [d526d3f]
Page Load Metrics (559 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint43775484
domContentLoaded532584558168
load534585559168
domInteractive532583558168

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Feb 18, 2021

I looked into the that "ignoring write attempt" warning, and changed it to throw an error locally to help me debug it. It turns out that the first warning I hit in any process is caused by dart. I encounter that in every process, even those that don't touch dart at all (or so I thought).

e.g.

$ yarn lavamoat ./development/build/index.js build scripts:core:dev:disable-console
yarn run v1.22.10
$ /home/gudahtt/projects/metamask-extension/node_modules/.bin/lavamoat ./development/build/index.js build scripts:core:dev:disable-console
(Error#1)

  Error#1: LavaMoat: ignoring write attempt to read-access global "process"
     at Object.set (LavaMoat/core/kernel:258:17)
    at Object.eval (/home/gudahtt/projects/metamask-extension/node_modules/sass/sass.dart.js:26:16)
    at internalRequire (LavaMoat/core/kernel:353:25)
    at requireRelative (LavaMoat/core/kernel:394:27)
    at requireRelativeWithContext (LavaMoat/core/kernel:366:16)
    at Object.eval (/home/gudahtt/projects/metamask-extension/development/build/sass-compiler.js:2:14)
    at internalRequire (LavaMoat/core/kernel:353:25)
    at requireRelative (LavaMoat/core/kernel:394:27)
    at requireRelativeWithContext (LavaMoat/core/kernel:366:16)
    at Object.eval (/home/gudahtt/projects/metamask-extension/development/build/styles.js:16:17)

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Feb 18, 2021

I was able to remove warnings from all build steps apart from styles by making sass and sass-compiler a dynamic require step. Good to know that all of those warnings were just dart.

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Feb 18, 2021

I'm seeing a bunch of changes after running yarn lavamoat:auto 🤔
I pushed them here so you could see them: db25ff6

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 19, 2021

@Gudahtt the auto policy charges are likely because you made the require dynamic? we dont know to walk it then

@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Feb 19, 2021

Sorry I meant from a clean working tree, after discarding the dynamic import change.

I figured it was due to some platform difference (mac vs Linux)

@kumavis
Copy link
Copy Markdown
Member

kumavis commented Feb 19, 2021

@Gudahtt ah yeah may be optional deps diff due to platform. @EtDu is running mac and gets fsevents

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

I was able to confirm that the policy differences were due to platform; the changes were all related to fsevents.

These cross-platform issues do present challenges to keeping the auto policy up-to-date. We'll have to postpone adding a check in CI to ensure it has been updated, as it'll always fail for contributors using macOS (and possibly Windows). But we can make do for the time being by checking prior to each release to ensure the policy file is up-to-date. I can create a CI check in a separate PR to run on release branches only, to ensure we don't accidentally forget this step.

Similarly, we can address the various console warnings in a separate PR.

LGTM!

@kumavis kumavis merged commit f196c9f into develop Feb 22, 2021
@kumavis kumavis deleted the lavamoat-buildsystem branch February 22, 2021 14:43
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 22, 2021
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.

4 participants