Authentication and tenants
Require a login, use tenant namespaces and set logical quotas.
Skeg 0.8 · Development documentation
A user logs in with a password. The user’s tenant determines which keys and vector indexes the connection can access. Users of one tenant share its namespace. Different tenants can use the same key or index name for their own records.
flowchart TD
accTitle: A login selects a tenant namespace
accDescr: Ana authenticates into acme and Ben authenticates into beta. Each connection reads the same key spelling in its own tenant.
A["Ana logs in"] --> B["Tenant acme"]
C["Ben logs in"] --> D["Tenant beta"]
B --> E["Title present in acme"]
D --> F["Title absent in beta"]
In this exercise, Ana and Ben both read tenant_demo:title. Ana sees the
value she wrote in acme. Ben reads in beta, where the key is absent.
Prepare the accounts
Follow Prepare the exercise in the
quickstart to install the CLI and create a fresh auth.kdb with users
root in ops and ana in acme. Then add Ben before starting Skeg.
From the same exercise directory, generate a private password file and
create the account:
(umask 077; openssl rand -hex 16 > ben.pw) &&
skeg-cli auth user create --store auth.kdb --user ben --tenant beta --password-file ben.pw
Keep the account store and password files private. Provision and edit accounts with the server stopped. Skeg loads the account store at startup.
Start a server that requires a login
Start the RESP listener in the exercise directory:
skeg --protocol resp3 --data-dir ./data --addr 127.0.0.1:6387 \
--tenant-auth ./auth.kdb --tenant-strict --admin-tenant ops
--tenant-auth loads the accounts. --tenant-strict requires a login
before running commands. --admin-tenant ops grants administrative
commands to connections authenticated in the named tenant.
Authenticate on each new connection, including each connection opened by a pool:
HELLO 3 AUTH <user> <password>
Use HELLO 2 AUTH <user> <password> for a RESP2 connection. Configure the
client to send authentication with HELLO. Before login, strict mode
returns NOAUTH even for commands such as PING and
SKEG.CAPABILITIES.
Use TLS through a proxy when credentials cross a network. See deployment for an example. Use the RESP listener for tenant authentication.
Verify isolation
In a second terminal, change to the exercise directory. Use Python 3.10 or later and install the client:
python3 -m venv .venv &&
. .venv/bin/activate &&
python -m pip install skeg==0.3.0
Download tenant_namespaces.py into that
directory and run python tenant_namespaces.py. It uses the two password
files and checks the identities returned by SKEG.WHOAMI. It writes a key
as Ana, verifies that the key is absent for Ben and deletes it as Ana.
Expect Tenant acme read its record. The same key was absent in tenant beta.
If the login fails, check the account file path and the credentials.
If the identity is unexpected, check the user-to-tenant assignment before
writing data.
Use ordinary keys and index names after login. Skeg applies the tenant scope on the connection. Use payload filters to select rows within that scope. On a listener without strict authentication, anonymous connections use tenant zero.
Per-tenant quotas
The admin tenant can set these limits for a tenant:
| Limit | What it counts |
|---|---|
max_vectors | Live vector rows across the tenant’s indexes and shards. Replacing a live row keeps the count the same. |
max_disk_bytes | Live KV records and payload blobs in the value log across the tenant’s shards. |
Vector files, graphs, WAL files and obsolete data awaiting reclamation also use disk space. Monitor free space separately. A payload overwrite can need quota headroom while Skeg stages the replacement blob.
Setting quotas (admin commands)
From a connection authenticated in the admin tenant, set and read the limits. This example caps the exercise tenant at 1000 live vectors and 1 MiB of logical KV and payload data.
SKEG.QUOTA.SET acme 1000 1048576
SKEG.QUOTA.GET acme
Expect OK from the set and two bulk strings from the read, in vector-limit
then disk-byte order. Use * in either position to leave that limit
unlimited. The .quotas sidecar beside auth.kdb persists the limits.
Include it when you back up a tenant store.
Tenants share server CPU, memory and storage. See operating Skeg for process limits and maintenance.
Finish the exercise
Stop Skeg with Ctrl+C when finished. Remove the exercise directory after shutdown if you no longer need the data and credentials.