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

Plugins cannot read other plugin configs #88

Merged
merged 3 commits into from
Dec 29, 2023
Merged

Conversation

staltz
Copy link
Member

@staltz staltz commented Dec 26, 2023

An improvement to secret-stack's security and overall avoidance of spaghetti dependencies.

This PR is a breaking change that allows each plugin to read config.global and config[pluginName] but nothing else.

E.g. with the config below:

{
  global: { seed, appKey },
  foo: { age: 18 },
  bar: { timeout: 3000 },
  qux: { path: "~/.config/app" }
}

A plugin named foo will get in its init function only config.global and config.foo:

{
  name: 'foo',
  manifest: {
    greet: 'sync',
  }
  init: function init(api, config) {
    // config is { global, foo }
    // ...
  }
}

global is now a reserved word (a plugin named "global" would emit an error log and be skipped.

@staltz staltz requested a review from mixmix December 26, 2023 13:52
Copy link
Member

@mixmix mixmix left a comment

Choose a reason for hiding this comment

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

I think this works. I would like to float an alternative implementation which breaks fewer other modules but achieves same result:

  • don't add "global" namespace
  • each plugin "lays claim" to part of the config
  • the subConfig it gets is "the namespaced part + the remaining config no other plugins layed claim to"

It's... messier (beacause a future plugin can call itself "connections" and swallow the global config called connections (so that would require reserved plugin name "connections")
But.. config.host and config.keys etc would always be there ... don't have to go to each module and add global.

It is more incremental, but might cause problems. What do you think?

CHANGELOG.md Show resolved Hide resolved
@@ -24,7 +24,7 @@ var databasePlugin = require('./some-database')
var bluetoothPlugin = require('./bluetooth')
var config = require('./some-config')

var App = SecretStack({ appKey: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' })
var App = SecretStack({ global: { appKey: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' } })
Copy link
Member

Choose a reason for hiding this comment

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

I have never used appKey. I would be in favoure of deprecating (wasn't it replaced with caps?)

I also don't think "global" is needed here? It feels more implicit to me that these are global?

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 have never used appKey. I would be in favoure of deprecating (wasn't it replaced with caps?)

Out of scope?

also don't think "global" is needed here? It feels more implicit to me that these are global?

It's necessary in case you want to specify at this point some plugin-specific config, then you need a way of saying that the other configs are global, not plugin-specific. It can also be generally less confusing, if both SecretStack({ ... }) and .create(null, { ... }) object shapes follow the same schema.

lib/api.js Show resolved Hide resolved
lib/api.js Outdated Show resolved Hide resolved
lib/api.js Outdated Show resolved Hide resolved
lib/api.js Show resolved Hide resolved
lib/api.js Outdated Show resolved Hide resolved
lib/api.js Outdated Show resolved Hide resolved
@staltz
Copy link
Member Author

staltz commented Dec 26, 2023

How is this "laying claim" actually going to work? I'm afraid of having a complex system to solve a problem that's not very important. I think it's reasonable to incur this kind of breaking change cost, and change ways of working with secret stack.

I think the dumbest implementation is often a good bet, i.e. my PR is a pretty dumb approach. It's simple, also easy to know how downstream implementations need to comply.

@staltz
Copy link
Member Author

staltz commented Dec 26, 2023

Also, I must say, not merging this PR is a realistic approach for me. It's not a necessary step for my other tasks.

lib/api.js Show resolved Hide resolved
lib/plugins/shs.js Show resolved Hide resolved
@staltz staltz merged commit acae5f9 into main Dec 29, 2023
5 checks passed
@staltz staltz deleted the staltz/plugin-config-sandbox branch December 29, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants