-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Add config value support in frontend to New Platform #41990
Comments
Pinging @elastic/kibana-platform |
cc @legrego @elastic/kibana-app-arch |
Given that the NP will not have as many full bootstrap events, I tend to agree with your assessment. |
Tying together a couple of different conversations here:
Given these two needs, and potentially others, I think Josh's proposal of whitelisting configuration values makes sense here. |
Problems to discuss:
export const config = {
exposeToBrowser: ['key1'],
schema: ...
} pros:
|
w/r/t Declaration format, I agree we shouldn't couple it to I started writing an alternative proposal, but then I realized that @joshdover essentially stated the same in the issue description above:
We could consider the One downside to this approach is that the metadata field won't make sense everywhere. Consider the following: schema.object({
cookieName: schema.string({ defaultValue: 'sid' }),
sessionTimeout: schema.oneOf([
schema.number(),
schema.literal(null, { metadata: { exposeToBrowser: true } })
], { defaultValue: null }),
}),
}); Here, we are saying that the |
Great points about not coupling In terms of the alternatives raised, I think I'm leaning towards @restrry's solution. My thinking here is that:
I don't think this problem is specific to the issue of accessing config on the client. This type of discrepancy can exist today. IMO, documentation about this is good enough. This is a temporary situation which should be able to be resolved in the coming months as more plugins are migrated to the New Platform.
I imagine that to do this rehydration process, we'll also need to serialize the schema itself (or import it into browser bundles?). This sounds non-trivial to me. We could pare down the work here by only supporting a handful of primitive types in the initial version and falling back to strings for the other types.
+1 on pushing runtime updates to a future change.
+1 |
also export const config = {
exposeToBrowser: ['key1'],
} should support shared config types for server & client sides via |
Started to look at this one. A few questions comes to mind:
export const ConfigSchema = schema.object(
{
ui: schema.object({ enabled: schema.boolean({ defaultValue: false }) }),
},
); should we allow something like export const config = {
exposeToBrowser: ['ui.enabled'],
schema: ConfigSchema,
} or do we simply only allow to expose root-level values?
|
We can start with the simplest option and expose only root keys. Config schema can be non-trivial and contain conditional types, maybe types, union types, etc. It can make it harder to access nested fields.
We can inject data in the HTML page. As we do in the legacy platform https://github.com/elastic/kibana/blob/master/src/legacy/ui/ui_render/ui_render_mixin.js#L235 Another problem: there could be client-side only plugins that want to leverage the config mechanism. We need to decide how they should declare schema and browser keys. |
Hum, that's seems like more than one problem actually:
Is
|
Another option to actually use the same mecanism between client-only plugins and other kind of plugin would be to actually expose the config from the plugin root folder We could even keep the old As an alternative, we could also allow client-only plugin to expose a WDYT @restrry ? |
It does not currently work client-side due to the version of Joi we're using. I believe once #48026 is merged, we could upgrade our Joi version to the latest one, which does support the browser environment.
In legacy, plugins could define a
A lot of legacy plugins use the injectedVars pattern today, so I do think there is a need. Another option would be to require plugins to make a HTTP request to the backend when they start, but I think that would lead to a lot of requests happening at once to the backend when the frontend app is first bootstrapped. This would also not work for client-side only plugins
This option seems attractive from a consistency standpoint, but results in a plugin being able to execute code on the server. Though, so does the original proposal in this issue. I think the only option that would not lead to client-side plugins being able to execute code on the server would be a static json file format, which is definitely outside the scope of what we need to solve now. Given that, I think we will need to punt on pure client-side only plugins until we have time to tackle that. The issue with exposing the same config object to client and server is that some config values are sensitive and should not be exposed to the client at all (eg. encryption keys, Elasticsearch credentials, etc.). We absolutely need the developer to explicitly whitelist which options are available to the client. |
We don't really need joi client-side, it's just that importing the config type (we only need the type here, and only for generating the client config type from the server's using something like restrry suggested) will result in probably importing joi as the config type is based on
As long as our validation library doesnt support static json for validation, this is not an option as the client-side only props will not be known by the server validation resulting on kibana not starting
Thats not was I was thinking of. Even with a shared config in
If a malevolent plugin wants to execute server-side code, it just have to add a server-side part to their plugin, and voila, so I'm not sure that's a bigger issue than overall plugin sandboxing which is widely out of the scope of the issue? But WDYT ? should we just forget about client-only plugins for now ? |
Got it, this makes sense to me.
In order to execute server-side code that accesses Core APIs, yes they'd need to create a server side plugin. But if there's a For context here, Cloud wants to be able to allow customers to install 3rd party plugins that cannot execute any code on their infrastructure at all. An alternative would be sandboxing, but that still carries some risks. I don't think we necessarily need to solve this case now, we should just think about how it would be done in the future and make sure we don't code ourselves into a corner. I think what you're proposing is a viable option, and we can address true client-side only plugins in the future, possibly with allowing schema to be defined in a json format, just with limited functionality. |
Ok, let's drop the client-only plugins config support from the issue then. |
Currently in the New Platform, we allow frontend plugins to read injected vars from legacy plugins, but there is no mechanism for adding injected vars from the server side.
Because the New Platform frontend is a single-page application, I believe we no longer have a strong case for adding the injected var mechanism and instead should allow plugins to whitelist configuration values that should be available in the frontend.
Reasons not to add injected vars to the new platform:
Reasons we may still want injected vars:
Implementation Proposal
I believe we could add a new
exposeToBrowser: boolean
field to theTypeOptions
interface passed to@kbn/config-schema
types.Core could then use this to expose any fields marked as
true
to the browser-side plugin.The text was updated successfully, but these errors were encountered: