• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mod_wasm is an extension module for the Apache HTTP Server (httpd) that enables the usage of WebAssembly (Wasm). This module allows the execution of certain tasks in the backend in a very efficient and secure way.

mod_wasm

Test passing License: Apache-2.0

mod_wasm is an Apache Server (httpd) extension module able to run and serve WebAssembly binaries as endpoints.

The first version (v0.1.0) was unveiled at the ApacheCon North America on Oct 3rd, 2022 (see the slides). In addition, a full-detailed article was published at VMware's Wasm Labs page.

βœ… Features

mod_wasm can be useful in the different scenarios:

  • Run existing applications from a variety of languages without modification.
  • Execute untrusted third-party code in a secure environment without using containers.
  • The Wasm capabilities model allows to enable/disable capabilites per HTTP request.

▢️ Quick Demo

  1. Run the container:
docker run -p 8080:8080 ghcr.io/vmware-labs/httpd-mod-wasm:latest
  1. Open browser at:
Demo Wasm Module URL
Drupal PHP 8.2.0 http://localhost:8080/drupal
Drupal (from setup) PHP 8.2.0 http://localhost:8080/drupal-10-zero
WordPress PHP 7.3.33 http://localhost:8080/wordpress
HTTP Request Viewer Python 3.11 http://localhost:8080/http-request-viewer

πŸ“” Contents

πŸ”­ Overview

The mod_wasm project is composed by two different libraries:

  • mod_wasm.so (written in C) acts as the extension module for the Apache Server (httpd).
  • libwasm_runtime.so (written in Rust) offers a very high-level C-API to manage WebAssembly modules via Wasmtime.

alt Architecture

Apache Configuration

To enable mod_wasm in Apache, simply define your <Location> with the wasm-handler and the file path to the Wasm binary in httpd.conf:

LoadModule wasm_module modules/mod_wasm.so

<Location /hello-wasm>
  SetHandler wasm-handler
  WasmModule /var/www/modules/hello_wasm.wasm
</Location>

mod_wasm supports multiple <Location> definitions, each of them with its own configuration. In addition, multiple configurations can share the same .wasm file. mod_wasm will automatically cache Wasm modules and use only one instance on memory.

New Directives

To setup and manage WebAssembly binaries and their WASI contexts, mod_wasm offers new directives to the httpd.conf configuration file:

Directive Description
WasmModule <path> Specifies the Wasm module file path.
WasmDir <dir> Pre-open a host directory for the Wasm context.
WasmMapDir <map> <dir> Pre-open a host directory for the Wasm context and mount into a mapping directory.
WasmArg <arg> Set an argument to be passed to the Wasm module context.
WasmEnv <env> <value> Set an environment variable to be passed to the Wasm module context.
WasmEnableCGI {On|Off} Enable/Disable CGI emulation mode. Default is Off.
WasmMapCGIFileNames {On|Off} Enable/Disable mapping SCRIPT_FILENAME based on WasmMapDirs when WasmEnableCGI is enabled. Default is Off.

Workflow

mod_wasm plays a role in two different stages of the Apache Server workflow:

  1. On the boot up sequence, the different WasmXXX directives are read from httpd.conf:
    • When a WasmModule directive is found, the Wasm runtime tries to load the given Wasm binary from disk into memory. This is an expensive operation so that is why it is executed only once during the Apache boot up sequence. In addition, a cache is used to store the different Wasm modules, so a specific Wasm module can be shared among different configurations with only one instance loaded into memory.
    • The remaining WasmXXX directives define different configuration aspects. A new configuration instance is created for each <Location> and it will be later used during execution as a template.
  2. On each incoming HTTP request, mod_wasm builds a new WASI context for the already-loaded Wasm binary. Next, the Wasm module is instantiated and the entry point is executed. The stdout from the Wasm module is redirected to the HTTP response, and the stderr is appended to Apache Server's trace (usually at <httpd_dir>/dist/logs/error_log).

mod_wasm also offers the ability to build a specific execution context per HTTP request. When setting up WasmEnableCGI On, mod_wasm will pass the HTTP headers as environtment variables to the Wasm module (they will be prefixed as HTTP_). Also, URL parameters are passed in the environment variable QUERY_STRING. And finally, the HTTP request body is passed as the stdin to the module.

alt Workflow

πŸ•ΉοΈ Examples

This repo cointains several pre-built WebAssembly examples to play with.

Feel free to explore, modify and crash them!

πŸ—οΈ Building mod_wasm

As introduced in the overview, there are two main libraries in the mod_wasm project, being libwasm_runtime.so a dependency for mod_wasm.so. So, you might want to build libwasm_runtime.so first:

  1. To build libwasm_runtime.so, the Wasm management and runtime library, go to wasm_runtime for detailed instructions.
  2. For mod_wasm.so, the Apache Server module extension, go to mod_wasm.

πŸ“¦ Building the container image

This repository contains all you need to build a local container image. Go to image for detailed instructions.

⚠️ Troubleshooting

Cannot load modules/mod_wasm.so into server

This is a common error related to LD_LIBRARY_PATH:

$ httpd
httpd: Syntax error on line XXX of <...>/httpd/dist/conf/httpd.conf:
Cannot load modules/mod_wasm.so into server: libwasm_runtime.so: cannot open shared object file: No such file or directory

Apache is loading modules/mod_wasm.so but during the process it cannot find libwasm_runtime.so. Either run Apache with LD_LIBRARY_PATH pointing to the directory where libwasm_runtime.so is located, or copy libwasm_runtime.so to a directory such as /usr/lib.

πŸ› Debugging

To get detailed debugging information about the Wasm execution, run the Apache Server with the following environment variables:

  • WASMTIME_BACKTRACE_DETAILS=1
  • RUST_BACKTRACE=full

Also, it is recommended to run Apache in debug mode (-X option), this means only one process, only one worker, and without detaching from the terminal.

WASMTIME_BACKTRACE_DETAILS=1 RUST_BACKTRACE=full ./httpd -X

More Repositories

1

wasm-workers-server

πŸš€ Develop and run serverless applications on WebAssembly
Rust
503
star
2

webassembly-language-runtimes

Wasm Language Runtimes provides popular language runtimes (Ruby, Python, …) precompiled to WebAssembly that are tested for compatibility and kept up to date when new versions of upstream languages are released
Shell
315
star
3

attack-surface-framework

Tool to discover external and internal network attack surface
CSS
183
star
4

node-replicated-kernel

Experimental kernel with built-in replication.
Rust
153
star
5

reconciler-runtime

⚠️ Maintenance suspended. Please, migrate to the active fork reconciler.io/runtime. See https://github.com/reconcilerio/runtime/releases/tag/v0.20.0 for instructions. This repository will be archived eventually.
Go
81
star
6

distribution-tooling-for-helm

Helm Distribution plugin is is a set of utilities and Helm Plugin for making offline work with Helm Charts easier. It is meant to be used for creating reproducible and relocatable packages for Helm Charts that can be moved around registries without hassles. This is particularly useful for distributing Helm Charts into airgapped environments.
Go
62
star
7

yaml-jsonpath

JSONPath implementation for the gopkg.in/yaml.v3 node API
Go
47
star
8

wasm-languages

How to use WebAssembly in various languages
HTML
45
star
9

verified-betrfs

A verified high-performance file system
Dafny
32
star
10

hci-benchmark-appliance

HCIBench stands for "Hyper-converged Infrastructure Benchmark". It's an automation wrapper around the popular and proven open source benchmark tools: Vdbench and Fio that make it easier to automate testing across a HCI cluster. It's the recommended tool for VMware vSAN customer to run performance testing.
Python
29
star
11

vmware-customer-connect-cli

Golang based CLI to interact with customerconnect.vmware.com
Go
19
star
12

date-and-time-pattern-detection

Date/time Pattern Detection is multi-module project consisting of library, rest-api and models. The project aims to help Engineers who need to parse date/time input without pattern, need validation library for localized date/time or help/suggestions on what are the standard Unicode practices for Localization.
Java
17
star
13

research-and-development-artificial-intelligence-lab

Welcome to VMware's AI Lab (VAIL). Here we publish helpful snippets for the NLP community πŸ˜„
Python
14
star
14

vmware-image-builder-action

GitHub action code for VMware Image Builder (VIB).
TypeScript
14
star
15

marketplace-cli

A CLI for interacting with the VMware Marketplace
Go
11
star
16

container-tracer

The project brings the power of the Linux kernel tracing to Kubernetes. It leverages existing kernel tracing frameworks such as ftrace, perf, ebpf to trace workloads running on a Kubernetes cluster. Designed as a native Kubernetes application, its main goal is to be simple and efficient in doing one thing - collecting system traces per container.
Go
11
star
17

advanced-same-machine-interprocess-communication-protocol-suite

Toroni is a protocol suite for advanced interprocess communication specialized to work the same machine (i.e. no networking involved) offering characteristics that are unmatched by existing OS IPC features, off-the shelve components like ZeroMQ, Aeron and many others. Currently Toroni involves The Reliable Message Protocol which is:- brokerless, meaning no dedicated server process is needed to run the protocol- many-to-many- totally ordered, meaning all readers see messages from all writers in the same order- reliable, meaning a reader can detect if it has missed a message- termination safe, meaning crash of any communicating process is not harmful to the restAdditionaly Toroni offers The Topic Protocol (TP) which is is publish/subscribe protocol running on top of RMP.More info about RMP and TP can be found at https://radio.eng.vmware.com/2022/events/3090Toroni will not be limited to RMP and TP and can be placeholder for new advanced IPC same machine protocols.
Java
10
star
18

feed-manager-for-misp

MISP Feed Manager is a set of python libraries and utilities to ease generation and consumption of feeds of threat intelligence indicators published in MISP format (https://github.com/MISP/misp-rfc). MISP Threat Sharing is an open source threat intelligence platform (https://en.wikipedia.org/wiki/Malware_Information_Sharing_Platform).
Python
9
star
19

multi-tenant-persistence-for-saas

Multi-tenant Persistence for SaaS acts as data abstraction layer for underlying data store (Postgres) and provide multi-tenancy capabilities along with ability to integrate with different IAM authorizers.
Go
8
star
20

build-inspector

Build Inspector is a tool designed to process plain-text CI/CD build and deploy logs, and extract useful information from them, such as dependency provenance information, along with potentially risky behavioral information.
Python
8
star
21

client-library-for-chaos-mesh

Chaos-Mesh Python Client
Python
5
star
22

blueprint-for-horizon-with-vmc-on-aws

This script include all necessary groups, services and Distributed firewall rules for a Horizon Environment in VMC on AWS.
HCL
4
star
23

bert-pretraining

The project is a python module that facilitates BERT pretraining. The current existing open source solution for training this specific model is convoluted. We have simplified the procedure. The project's goal is to open the code to the wider Machine Learning community to help ML practitioners train their own BERT models using their data. The code was created to train the latest iteration of VMware's BERT model (vBERT) to help Machine Learning and Natural Language Processing Researchers within VMware.
Python
4
star
24

vmware-customer-connect-sdk

Golang based SDK to interact with customerconnect.vmware.com. It is used in a CLI that enables product downloads from customerconnect: https://github.com/vmware-labs/vmware-customer-connect-cli
Go
3
star
25

vms-for-slurm

vm-provisioning-plugin-for-slurm (also called Multiverse) is Dynamic VM orchestration for virtualized HPC frameworks. In other words it a VM per job model which spawns individual VMs on demand for evey incoming job in a HPC Cluster.
C
2
star
26

galaxy-parser-for-misp

MISP Galaxy Parser is a set of python libraries and utilities to ease reading and processing of MISP Galaxies. MISP Galaxies are knowledge bases of malware labels, threat actors codified in MISP format. MISP Threat Sharing is an open source threat intelligence platform (https://en.wikipedia.org/wiki/Malware_Information_Sharing_Platform).
Python
2
star
27

patterns-lab

Run an immutable vmware lab using PhotonOS.
2
star
28

inclusive-language-ext-for-sonarqube

Language and terminology undergo change on a continuous basis due to social and linguistic forces. VMware Inclusive Terminology (ITS) Extension for SonarQube is used to scan source code and other project files for presence of terms which are considered as offensive, and provides recommended alternatives.This extension scans source code for Inclusive Terminology issues during build phase in build pipelines. Issues are reported to Sonar server and will be shown in Project Issues dashboard. After scan, SonarQube provides convenient tools to analyze, fix and report these issues.
Java
2
star
29

in-memory-property-aware-temporal-graph

Temporalgraph aims to provide an in-memory graph database that stores nodes and relationships between nodes in a versioned/time-aware manner.
Java
1
star
30

ui-guided-tours

UI Guided Tours representing step-by-step walkthroughs for VMware products
1
star
31

compliance-dashboard-for-kubernetes

A K8s compliance checker aggregator, with a dashboard and analyzer of K8s resources, as well as 3rd party scanners integration.
Go
1
star
32

efficient-supervised-anomaly-detection

RADE is a resource-efficient decision tree ensemble method (DTEM) based anomaly detection approach that augments standard DTEM classifiers resulting in competitive anomaly detection capabilities and significant savings in resource usage.
Python
1
star
33

api-data-collector

API Data Collector is a Chrome DevTools Extension which captures HTTP Requests and Response data, especially API data. API data can be stored, retrieved, and modified to be functional as a mock server for local application development and production debugging.
JavaScript
1
star
34

telemetry-peak-analyzer

The telemetry peak analyzer handles time series and detect relevant peaks or anomalies in threat telemetry data.
Python
1
star
35

sudo-for-microsoft-windows

Sudo for Windows aims to bring the familiar functionality of the linux Sudo command to Windows environments. It allows for full audit logging of all requests for elevation, along with the ability to tightly control which commands are allowed to be run by which users and groups.
C#
1
star
36

syscall-failure-analyzer

The project is an automatic system-call failure root-cause analyzer for Linux. Today, each error code might be caused by reasons. The tool allows developers and users to trace and analyze syscall call failures to pinpoint the exact reason of the failure.
Python
1
star