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

feat: add support for readonly dir mounting #68

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions extism.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"net/http"
"os"
"strings"
"time"

"github.com/tetratelabs/wazero"
Expand Down Expand Up @@ -382,8 +383,12 @@ func NewPlugin(
fs := wazero.NewFSConfig()

for host, guest := range manifest.AllowedPaths {
// TODO: wazero supports read-only mounting, do we want to support that too?
fs = fs.WithDirMount(host, guest)
if strings.HasPrefix(host, "ro:") {
trimmed := strings.TrimPrefix(host, "ro:")
fs = fs.WithReadOnlyDirMount(trimmed, guest)
} else {
fs = fs.WithDirMount(host, guest)
}
}

moduleConfig := config.ModuleConfig
Expand Down
26 changes: 26 additions & 0 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,32 @@ func TestFS(t *testing.T) {
}
}

func TestReadOnlyMount(t *testing.T) {
manifest := manifest("read_write.wasm")
manifest.AllowedPaths = map[string]string{
"ro:testdata": "/mnt",
}

if plugin, ok := plugin(t, manifest); ok {
defer plugin.Close()
plugin.Config["path"] = "/mnt/test.txt"

exit, output, err := plugin.Call("try_read", []byte{})

if assertCall(t, err, exit) {
actual := string(output)
expected := "hello world!"

assert.Equal(t, expected, actual)
}

_, _, err = plugin.Call("try_write", []byte("hello hello!"))

assert.NotNil(t, err, "Write must fail")
assert.Contains(t, err.Error(), "Failed to write file")
}
}

func TestCountVowels(t *testing.T) {
manifest := manifest("count_vowels.wasm")

Expand Down
Binary file added wasm/read_write.wasm
Binary file not shown.
Loading