Skip to content

Conversation

Skn0tt
Copy link
Contributor

@Skn0tt Skn0tt commented May 2, 2023

Summary

Addresses https://github.com/netlify/pod-compute/issues/491 and https://github.com/netlify/pod-ecosystem-frameworks/issues/471.

This PR propagates the featureFlags object that's passed into @netlify/build down towards plugins. The Netlify Team can use this to roll out changes to plugins more precisely.

There's discussions around changing where those values come from (BitBalloon vs Buildbot, see e.g. https://github.com/netlify/pod-compute/issues/491#issuecomment-1523024232), but with this PR i'd like to just address that they're usable from plugins, not where they're sourced from.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@Skn0tt Skn0tt self-assigned this May 2, 2023
@Skn0tt Skn0tt requested a review from lukasholzer May 2, 2023 12:34
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

event,
error,
envChanges,
featureFlags,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're providing the flags to every single plugin with this, no matter who wrote it and wether we trust it. I don't think these flags are super secret, so this should be fine - if not, is there some guard we could put in place? e.g. use the pluginPackageJson that's passed into the function, and check it against an allow-list?

Copy link
Member

Choose a reason for hiding this comment

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

How much work do you think it would be to build that allow-list functionality? Just thinking from a perspective of being conservative in what we expose to plugins before we've fully settled on how we expose feature flags in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The easiest approach would probably be to check pluginPackageJson.name and compare it to an allowlist. That's trivial to build, but won't stop people from accessing them if they're determined to do so (i'm sure there's ways of mangling with the package.json)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but if we're only trying to hide this while figuring out the details, then that's probably a good solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

These flags are passed down from buildbot (not filtered or anything). This means that we will also get secret values down the road here!

Instead, we might only pass them to the "core plugins"? Which is the next runtime etc.? instead of to all build plugins?

Furthermore, we should now change in buildbot the way how we gather feature flags and use the newly added tag filter to only pass feature flags for @netlify/build.

Currently all Netlify flags are passed down (backend, frontend, etc...)

CleanShot 2023-05-02 at 15 17 06

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead, we might only pass them to the "core plugins"?

Right, that's what I mean by "allow list". How would you recommend we check wether we can trust a plugin?

Copy link
Contributor

@lukasholzer lukasholzer May 2, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

or if the npm package starts with @netlify/ as then it's one of our trusted npm packages

Copy link
Contributor

Choose a reason for hiding this comment

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

but anyways I would suggest first limiting the list of plugins that are passed by buildbot via a tag in devcycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented the @netlify/-based filter in 12c45da.

but anyways I would suggest first limiting the list of plugins that are passed by buildbot via a tag in devcycle.

Could you elaborate on how this would help? You mentioned that we have "secret values" in the flags, could you give an example for a featureflag that we don't want to expose to trusted plugins?

event,
error,
envChanges,
featureFlags,
Copy link
Member

Choose a reason for hiding this comment

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

How much work do you think it would be to build that allow-list functionality? Just thinking from a perspective of being conservative in what we expose to plugins before we've fully settled on how we expose feature flags in general.

featureFlags: { test_flag: true },
})
.runWithBuild()
t.true(output.includes('test_flag'))
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually assert the shape of featureFlags (e.g. comma-separated array vs. object). Could we make the test a bit more specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 5909c3d

@@ -0,0 +1,3 @@
export const onBuild = function ({ featureFlags }) {
console.log(Object.keys(featureFlags))
Copy link
Contributor

Choose a reason for hiding this comment

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

you could leverage node builtin assertion to test it with:

import { deepEqual } from 'node:assert' export const onBuild = function ({ featureFlags }) { assert.deepEqual(featureFlags, { test_flag: true} ); console.log('passed'); };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep the assertions in the test file for readability, so I went with 5909c3d instead

@@ -0,0 +1,2 @@
name: test
inputs: []
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you don't need the inputs here or?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in d6429ab

Copy link
Contributor

@lukasholzer lukasholzer left a comment

Choose a reason for hiding this comment

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

LGTM! Nevertheless, I think we should create a follow-up issue to limit the set of feature flags passed down to netlify build via a tag.

@Skn0tt Skn0tt merged commit c4897b1 into main May 3, 2023
@Skn0tt Skn0tt deleted the plugins-feature-flags branch May 3, 2023 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment