|
| 1 | +# Instance Per Tenant |
| 2 | + |
| 3 | +For stronger isolation, run a separate Slicer daemon per tenant. Each gets its own UNIX socket, its own network range, and its own VM namespace. Tenant A cannot see, manage, or reach tenant B's VMs. |
| 4 | + |
| 5 | +``` |
| 6 | +┌───────────────────────────────────────────────────────┐ |
| 7 | +│ Your Application │ |
| 8 | +│ │ |
| 9 | +│ Tenant A request ──► /run/slicer/a3cf.sock │ |
| 10 | +│ Tenant B request ──► /run/slicer/e7d1.sock │ |
| 11 | +└───────────┬───────────────────────────┬───────────────┘ |
| 12 | + ▼ ▼ |
| 13 | +┌─────────────────────┐ ┌─────────────────────┐ |
| 14 | +│ Slicer (a3cf) │ │ Slicer (e7d1) │ |
| 15 | +│ 169.254.100.0/22 │ │ 169.254.104.0/22 │ |
| 16 | +│ │ │ │ |
| 17 | +│ ┌────────┐┌────────┐│ │ ┌────────┐┌────────┐│ |
| 18 | +│ │ a3cf-1 ││ a3cf-2 ││ │ │ e7d1-1 ││ e7d1-2 ││ |
| 19 | +│ └────────┘└────────┘│ │ └────────┘└────────┘│ |
| 20 | +└─────────────────────┘ └─────────────────────┘ |
| 21 | +``` |
| 22 | + |
| 23 | +## When to use this |
| 24 | + |
| 25 | +Use a separate instance per tenant when: |
| 26 | + |
| 27 | +* You need API-level isolation - one tenant's requests cannot access another's VMs |
| 28 | +* You need network isolation between tenants |
| 29 | +* You want independent failure domains - one tenant's daemon crashing does not affect others |
| 30 | +* Compliance or security requirements demand full separation |
| 31 | + |
| 32 | +## Configuration |
| 33 | + |
| 34 | +Generate a config per tenant with isolated networking, a UNIX socket, and a non-overlapping IP range. Use [isolated mode networking](/reference/networking/#isolated-mode-networking) so VMs from different tenants cannot communicate. |
| 35 | + |
| 36 | +Tenant A: |
| 37 | + |
| 38 | +```bash |
| 39 | +slicer new a3cf \ |
| 40 | + --net=isolated \ |
| 41 | + --isolated-range 169.254.100.0/22 \ |
| 42 | + --socket /run/slicer/a3cf.sock \ |
| 43 | + --count=0 \ |
| 44 | + --graceful-shutdown=false \ |
| 45 | + --drop 192.168.1.0/24 \ |
| 46 | + > tenant-a.yaml |
| 47 | +``` |
| 48 | + |
| 49 | +This produces: |
| 50 | + |
| 51 | +```yaml |
| 52 | +config: |
| 53 | + host_groups: |
| 54 | + - name: a3cf |
| 55 | + storage: image |
| 56 | + storage_size: 25G |
| 57 | + count: 0 |
| 58 | + vcpu: 2 |
| 59 | + ram_gb: 4 |
| 60 | + network: |
| 61 | + mode: "isolated" |
| 62 | + range: "169.254.100.0/22" |
| 63 | + drop: ["192.168.1.0/24"] |
| 64 | + allow: ["0.0.0.0/0"] |
| 65 | + image: "ghcr.io/openfaasltd/slicer-systemd:6.1.90-x86_64-latest" |
| 66 | + hypervisor: firecracker |
| 67 | + graceful_shutdown: false |
| 68 | + api: |
| 69 | + bind_address: "/run/slicer/a3cf.sock" |
| 70 | +``` |
| 71 | +
|
| 72 | +Tenant B: |
| 73 | +
|
| 74 | +```bash |
| 75 | +slicer new e7d1 \ |
| 76 | + --net=isolated \ |
| 77 | + --isolated-range 169.254.104.0/22 \ |
| 78 | + --socket /run/slicer/e7d1.sock \ |
| 79 | + --count=0 \ |
| 80 | + --graceful-shutdown=false \ |
| 81 | + --drop 192.168.1.0/24 \ |
| 82 | + > tenant-b.yaml |
| 83 | +``` |
| 84 | + |
| 85 | +```yaml |
| 86 | +config: |
| 87 | + host_groups: |
| 88 | + - name: e7d1 |
| 89 | + storage: image |
| 90 | + storage_size: 25G |
| 91 | + count: 0 |
| 92 | + vcpu: 2 |
| 93 | + ram_gb: 4 |
| 94 | + network: |
| 95 | + mode: "isolated" |
| 96 | + range: "169.254.104.0/22" |
| 97 | + drop: ["192.168.1.0/24"] |
| 98 | + allow: ["0.0.0.0/0"] |
| 99 | + image: "ghcr.io/openfaasltd/slicer-systemd:6.1.90-x86_64-latest" |
| 100 | + hypervisor: firecracker |
| 101 | + graceful_shutdown: false |
| 102 | + api: |
| 103 | + bind_address: "/run/slicer/e7d1.sock" |
| 104 | +``` |
| 105 | +
|
| 106 | +Each `/22` range provides 256 usable VM slots. Use non-overlapping ranges when running multiple daemons on the same host (e.g. `169.254.100.0/22`, `169.254.104.0/22`, `169.254.108.0/22`). |
| 107 | + |
| 108 | +In isolated mode, each VM gets its own network namespace. VMs cannot communicate with each other, with the host, or with the LAN. The `drop` list blocks specific CIDRs. Auth is disabled by default for UNIX sockets since access is controlled by filesystem permissions. |
| 109 | + |
| 110 | +## Start each daemon |
| 111 | + |
| 112 | +Start each daemon in its own terminal or tmux window: |
| 113 | + |
| 114 | +```bash |
| 115 | +sudo slicer up tenant-a.yaml |
| 116 | +``` |
| 117 | + |
| 118 | +```bash |
| 119 | +sudo slicer up tenant-b.yaml |
| 120 | +``` |
| 121 | + |
| 122 | +Each daemon manages its own VMs. Your application routes requests to the correct socket based on which tenant is making the request. |
| 123 | + |
| 124 | +For production, run each daemon as a systemd service - one unit per tenant. See [running in the background](/getting-started/daemon/) for setup. |
| 125 | + |
| 126 | +## API isolation |
| 127 | + |
| 128 | +Each daemon has its own VM namespace. Listing nodes on tenant A's socket returns only tenant A's VMs: |
| 129 | + |
| 130 | +```bash |
| 131 | +TOKEN=$(sudo cat /var/lib/slicer/auth/token) |
| 132 | +
|
| 133 | +# Tenant A: create a VM |
| 134 | +sudo curl -sf --unix-socket /run/slicer/a3cf.sock \ |
| 135 | + -H "Authorization: Bearer $TOKEN" \ |
| 136 | + -H "Content-Type: application/json" \ |
| 137 | + -X POST http://localhost/hostgroup/a3cf/nodes \ |
| 138 | + -d '{"tags":["user=alice","job=123"]}' |
| 139 | +
|
| 140 | +# Tenant B: create a VM |
| 141 | +sudo curl -sf --unix-socket /run/slicer/e7d1.sock \ |
| 142 | + -H "Authorization: Bearer $TOKEN" \ |
| 143 | + -H "Content-Type: application/json" \ |
| 144 | + -X POST http://localhost/hostgroup/e7d1/nodes \ |
| 145 | + -d '{"tags":["user=bob","job=456"]}' |
| 146 | +
|
| 147 | +# Tenant A sees only its own VMs |
| 148 | +sudo curl -sf --unix-socket /run/slicer/a3cf.sock \ |
| 149 | + -H "Authorization: Bearer $TOKEN" http://localhost/nodes |
| 150 | +``` |
| 151 | + |
| 152 | +```json |
| 153 | +[{"hostname":"a3cf-1","hostgroup":"a3cf","ip":"169.254.100.2", |
| 154 | + "tags":["user=alice","job=123"],"status":"Running"}] |
| 155 | +``` |
| 156 | + |
| 157 | +Tenant A cannot manage, exec into, or copy files to tenant B's VMs through its socket. |
| 158 | + |
| 159 | +## See also |
| 160 | + |
| 161 | +* [Single Slicer instance](/platform/single-instance/) - simpler deployment for trusted environments |
| 162 | +* [Networking](/reference/networking/) - CIDR configuration and bridge setup |
| 163 | +* [REST API reference](/reference/api/) - full endpoint documentation |
0 commit comments