101 points · by nilslice · 3y ago · 91 comments
Naturally one needs to sell WebAssembly as being the first of a kind.
"User-defined functions (UDFs) have been a fixture in database systems for a considerable period of time, allowing users to extend the database’s built-in functionality to complement good ol’ SQL."
Granted, I'm biased, but I think we did a decent job elaborating from there on the novelties WebAssembly brings to this age-old field.
> developers are in most cases forced to use unfamiliar programming languages, typically unique to the database itself.
What parent correctly points out is that this simply isn’t true. Your examples of novelty are all things that were possible decades ago in most mainstream DBMSes. The SQLite one in particular is bizarre: it’s inherently an embedded db with bindings in every language.
Supporting user defined functions as compiled objects loaded into the database is as old as the hills. The sandboxing part is silly since no one in their right mind is going to expose their database to untrusted users in the first place.
I've seen projects do exactly this, with PostgreSQL row-level security.
https://www.graphile.org/postgraphile/
EDIT: Though to be clear, it does seem a terrible idea to me too....even when you prevent unauthorized access, there is always the issue of resource usage.
That's circular logic. You would not do it when it's unsafe. But when it is, it could open up entirely new use cases. Most obviously, infrastructure-as-a-service offerings.
My only worry in all this (and wasm) in general is how well you can debug this later - be it interactive, or postmortem dump. I'm having my reservations, but would have to experiment and see.
So far the best integration I've seen between different languages/runtimes have been C++ / .NET (C#) and C++/CLI (e.g. their managed C++) - I can debug, step in, post-mortem debug without an issue.
I can't even do this properly with GoLang, and had mixed success with Python (+.pyd files).
Debugging (interactive, and post-mortem) is often overlooked, and thought about later.
But I'm all excited about wasm now :)
Isn’t that a step backwards? De linking them means you can scale the two appropriately independently.
I guess if you’re using could and can “steal” a bit of compute that way it makes sense.
It's definitely situational, and this can be true! But, generally its this kind of scaling optimization on everything that has us drowning in microservices today. If we can afford to "steal" some compute from the DB server, and minimize the amount of infra spun up for things that are basically scripts, I consider that a win.
Today there are lots of practical ways to autoscale databases and colocating data and compute is generally good for performance and simplicity (your mileage may vary for simplicity).
If Network I/O between your compute and data dominates every other dimension, you might want to to collocate compute and data.
Being able to fit the architecture to the performance of the workload is a good thing.
It could be for some use cases, but there are significant efficiency advantages to processing the data where it lies instead of shipping a copy to separate compute services.
Ideally you want scalable storage with compute (assuming really large datasets), so you can move the computation, which usually is small, close to the data.
In any case, it's not one size fits all, and each problem space matters.
Backend in Elixir, with Extism embedded and example plug-ins in Rust and Javascript!
We blogged [2] about this feature, and you can read the relevant PRs [3] containing the changes necessary for its implementation.
[1] https://seafowl.io/docs/guides/custom-udf-wasm
[2] https://www.splitgraph.com/blog/seafowl-wasm-udfs
[3] https://github.com/search?q=repo%3Asplitgraph%2Fseafowl+wasm...
How this all works varies a lot between databases, so what works in one may not be optimal in another.
There is a valid concern with using extra CPU/RAM on a (hard to scale) database rather than (easy to scale) application servers.
But it all depends on what you are doing, your tenant model, etc.
(Obviously, as WASM JIT compilers get more elaborate and it incorporates things like GC'd references, some of the advantages of this design wrt simplicity will disappear, but I anticipate that these kinds of features will mostly not be used in settings like databases).
It does get recompiled to bytecode that runs directly on the processor, so in theory there could be vulnerabilities that come up from that, but I think it’s a pretty well-understood surface area at this point.
Edit: read the first half of my sentence again.
I think that's because the word "binary" has connotations that aren't strictly technically justified. There's no difference between running WASM and running JS (which is usually obfuscated anyway). Both are JITted into machine code, and it's important the JIT is implemented securely. (JIT compilers have been sources of exploits.) The only difference is complexity of the source language, where simpler languages are easier to secure. And WASM is orders of magnitude simpler than JS.
You can already do things like http://www.jsfuck.com/ and even more complex ones, but they would likely have bad performace.
With wasm you could do malware-level obfuscation with less drawbacks.
It is possible that there are a lot of tool to examine JS code for "suspicious code" and that those tools might not work well on WASM.
In practice the WASM interpreter in the browser is a functionality that can be (almost) completely polyfilled.
Personally I would be way more worries about hardware exploits via WebGL.
But it is probably already possible with JSFuck and webworkers.
Flash, Silverlight, Java Applets, and loads more stuff existed while people were still OK serving stuff up without SSL, trying to figure out cookies and generally not putting a lot of thought into cross site scripting attacks. That was a security nightmare and all the obvious things happened. WASM does not seem like a repeat of that. Rather it builds on all the learning we've had since then.
Unfortunately, the design of WASM and common compilers targeting it means that your security is at risk as a user, even though your PC is safe. Applications compiled to WASM have a wide variety of fun security vulnerabilities that have been gone on native targets for decades, which means that if (for example) Gmail moved to WASM, it would now be possible for malicious parties to attack your Gmail tab even though they can't attack your PC. Some examples:
* Address space layout randomization is gone - if an attacker gets a write-anwyhere primitive, it will work 100% of the time
* Function pointers are densely packed - any possible value within the correct range (0 - function count) is a valid function pointer, as long as the signature matches. Even worse than not having ASLR.
* Page protections are gone - all data is mutable, even things that shouldn't be like string constants compiled into the binary
* Zero page accesses don't trap - while compilers go out of their way to try and make reading/writing from null pointers fail in WASM, the actual runtime happily allows you to do it. This makes attacks easier to execute because while stray nulls would kill a native application on dereference, in WASM they will just yield a 0 and execution will often continue.
* Most stuff is static linked - for native applications, it is common (albeit less common now in our modern era of Electron Hell) to pull in services from the OS and its packages, whether it's zlib or https or whatnot. The WASM runtime model generally offers a very limited set of capabilities in comparison, and there's no equivalent way to dynamically link against vendored packages that get security updates automatically. So every application ships its own ICU (for time zone and localization data), ships its own zlib (for compression/decompression), ships its own crypto (because the browser crypto APIs are extremely limited and async-only), etc...
Ultimately WebAssembly runtimes are very secure, but you have to protect everything else from the code you're running, because the code itself can easily be attacked by uncontrolled input.
Other than a few extremely niche situations (maybe browser-based gaming?) does anyone ever really think to themselves "wow I should really use WebAssembly here?" Even the post itself doesn't talk about any real solutions, just about what might be possible:
> database platforms could gain these additions with little to no incremental work required
Ultimate cope. It's the classic solution looking for a problem.
(Edit: mass downvoted by the WASMOOOORS)
Regarding use cases, I think there are plenty, mainly in places where you need to protect yourself against th code you're running, so pretty similar to docker, but lighter and faster boot time. Admittedly, also less feature complete and a different target: less business-y code and more system-y code.
So anything like cloud functions, database functions as described in this article, indeed web browser based games. I think Fastly is providing cloud functions at the edge that are wasm based.
With these uses cases, theoretically, an ecosystem might develop making more use cases transferable from docker to wasm, particularly use cases of isolated pieces of logic that need to be executed unitarity.
> mainly in places where you need to protect yourself against the code you're running
You can do this with LUA or like a million other languages (heck, even vanilla JS). The idea that WASM is the only sandboxed thing in the universe is just weird.
I don't know anyone who has ever said that.
Those people seem to get excited at the idea that you could build web apps with a “real compiler”.
But personally I just don’t buy that JavaScript is the reason web development is hard. I think it’s just the natural outcome of the fact that the capabilities of browsers are both varied and ever changing, and therefore the expectations of clients are always changing, and therefore the tooling to be able to (relatively) quickly meet those requirements is always changing.
But we’ll see. Maybe there will be some beautiful, stable web dev framework built on WASM that comes out!
WASM will eat SPAs and a chunk of the gaming market, it's just a matter of how long it takes.
Ah yes, the classic "we're still early"—might I introduce you to cryptocurrency? Apologies for the snakiness, but if it hasn't happened in the last 10 years, do you really think it will happen in the next 10?
I've no idea why you think that situation is a close analog to WASM.
It's like implementing Photoshop in Python. Why would you do that?