package main // Exhibit 9. The zoo is one wasm instance per request inside rc-host: its files are its own data // folder and nothing else (every path is resolved beneath it, no symlink followed), its database is // its own (SQLite cannot ATTACH another file), and its outbound calls go through a fence that refuses // the server's loopback, private networks, the cloud metadata service and the box's own non-web ports, // after DNS and on every redirect. This tries the doors right now, as the zoo itself; the controls // (its own file, its own address) must open, or the refusals prove nothing. Root tries the same doors // as every wasm app, every hour, from inside the host's own sandbox. import "core:fmt" import "core:strings" import "ratcloud:rc" Door :: struct { door: string `json:"door"`, result: string `json:"result"`, why: string `json:"why"`, } doors :: proc() -> []Door { out := make([dynamic]Door) e := env().env file :: proc(out: ^[dynamic]Door, door, path: string) { _, c := rc.read_file(path) append(out, Door{fmt.tprintf("read %s (%s)", door, path), "refused" if c < 0 else "opened", fmt.tprintf("error %d", c) if c < 0 else "read"}) } file(&out, "account's database", fmt.tprintf("../../account/%s/account.db", e)) file(&out, "account's database", fmt.tprintf("/srv/data/account/%s/account.db", e)) file(&out, "account's signing key", fmt.tprintf("/srv/data/account/%s/assert-key.pem", e)) file(&out, "the platform's secrets", "/etc/ratcloud/secrets") file(&out, "account's repository", "/opt/account.git/config") p, l := rc.sptr(fmt.tprintf("../../account/%s/account.db", e)) h := rc.db_open(p, l) append(&out, Door{"open account's database by name", "refused" if h < 0 else "opened", fmt.tprintf("error %d", h) if h < 0 else "opened"}) _, ae := rc.exec(db(), fmt.tprintf("ATTACH DATABASE '/srv/data/account/%s/account.db' AS x", e)) append(&out, Door{"ATTACH account's database", "refused" if ae != "" else "opened", ae}) _, s1 := rc.secret("account") append(&out, Door{"read the zoo's own sign-in secret", "opened" if s1 else "refused", "it stays in the host"}) for u in ([]string{"http://127.0.0.1/", "http://[::1]/", "http://10.0.0.1/", "http://169.254.169.254/latest/meta-data/", fmt.tprintf("http://%s:22/", env().host)}) { res := rc.fetch({url = u, timeout_ms = 5000}) refused := strings.has_prefix(res.err, "refused") append(&out, Door{fmt.tprintf("connect to %s", u), "refused" if refused else "opened", res.err if res.err != "" else fmt.tprintf("status %d", res.status)}) } return out[:] } // The control: the same tries on doors that should open. If these fail, so would everything. controls :: proc() -> map[string]bool { c := make(map[string]bool) w := rc.write_file("doors-control.txt", transmute([]u8)string("mine")) back, re := rc.read_file("doors-control.txt") c["own data"] = w == 0 && re == 0 && string(back) == "mine" c["own address"] = rc.fetch({url = self_url("/lights.json"), timeout_ms = 10_000}).status == 200 return c } e09 :: proc() -> Exhibit { return { n = 9, wing = "Isolation", title = "Try the doors", promise = "An app cannot open another app's files, and it cannot reach the server's own internal network.", block = "Every request is a fresh wasm instance in rc-host: its own data folder is the only place it can read or write, its database the only one it can open, and its outbound calls pass a fence that refuses the box's loopback, private networks and the metadata service.", src = {"e09_doors.odin", #load("e09_doors.odin", string)}, script = {"web/e09.js", #load("web/e09.js", string)}, show = proc(me: ^rc.User) -> string { root := strings.builder_make() for c in jarr(fact("platform.json"), "check", "checks") { line := jstr(c, "line") if !strings.has_prefix(line, "(exhibit 9)") && !strings.has_prefix(line, "An app cannot read") do continue rc.render_to(&root, `
Root tries them too, as every app, every hour: