-
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
[POC] Use WebAssembly build of package-spec for package validation #128076
Conversation
@elastic/kibana-security I noticed that we have no other usages of WASM in Kibana today. Are there any known reasons we can't or shouldn't pursue this option? |
💔 Build FailedFailed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled in files
Total ESLint disabled count
HistoryTo update your PR or re-run it, just comment with: |
Thanks for asking! I'll let others on the team respond do your direct usage, which appears to be server-side. I don't know enough to have an opinion one way or another here. For client-side WASM, we would likely need a CSP that included either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Larry's earlier assessment. If we use WASM on the server-side and compile only the module we ship, then I don't have any significant security-related concerns. I just left few performance related questions and it'd be great if we can avoid polluting the global scope with Go
wasm helper.
size: number, | ||
buffer: Uint8Array | ||
): Promise<void> { | ||
const validator = await WebAssembly.instantiate(wasmBuffer, go.importObject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if it's called multiple times then it'd probably make sense to compile module just once and reuse it for instantiation (with new WebAssembly.Module
or WebAssembly.compile
).
// @ts-expect-error | ||
const go = new Go(); | ||
|
||
const wasmBuffer = fs.readFileSync(path.join(__dirname, 'validator.wasm')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Just curious, I see this module is about 12mb, I assume it's not optimized yet (with more aggressive build optimization flags, wasm-opt
and friends)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep we still need to explore making this smaller and distribute it via a proper npm module. This is currently being built with go-wasm, but I think it would make sense to look at tinygo.
// Provides global.Go runtime | ||
import './wasm_exec'; | ||
// @ts-expect-error | ||
const go = new Go(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I'm not familiar with wasm_exec.js
\tinygo, is it possible to use its importObject
without polluting the global scope with Go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without editing the wasm_exec.js
from Go (this is not from tinygo), I don't see a way. I think it would be a small edit though and I agree we shouldn't merge this in its current state (polluting the global scope).
Summary
Related to #115032
Uses a WebAssembly build from elastic/package-spec#285
This imports a WebAssembly (wasm) build of the package-spec validation code and applies it to all packages installed via upload. It will fail to install these packages if they do not pass the package-spec validation.
For instance, this fails on the
endpoint
package today with this error (due to elastic/package-spec#23):Maybe for now we make this a dev-only log warning to start?
Checklist
Delete any items that are not applicable to this PR.
Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:
For maintainers