Skip to main content

Day 1: your first hour with a local tenant

You ran btk3s up and it printed some URLs. This is what to do next: log in, find the credentials, call the API, and see what was already created for you.

The URLs​

URLWhat
https://<domain>/web client
https://<domain>/swagger/index.htmlAPI docs, through the gateway
https://<domain>/api/v1/...the API itself
https://auth.<domain>/Keycloak
https://device.<domain>/onboarding, including EST for devices
mqtt.<domain>:8883the MQTT broker

<domain> is the domain: in btk3s.yaml. btk3s hosts show prints all of them filled in, and says whether anything is needed to reach them.

Trust the local CA​

Every hostname is served with a certificate from a CA created on your machine, so browsers warn and curl refuses until you trust it:

btk3s hosts trust

It rebuilds the trust bundle from the running tenant, writes one anchor file per root, and prints the command for the OS you browse from, then the two browsers that keep their own store rather than reading the OS one: Firefox everywhere, and Chrome/Chromium on Linux.

Three roots, because a tenant serves three hosts from three chains: cert-manager's CA for https://<domain>/, this tenant's onboarding root for https://device.<domain>/, and its device CA for the broker on mqtt.<domain>:8883. Trust all three — with only the first, onboarding fails for a device while the console looks fine; without the third, every MQTT connection fails. Install locally has the full matrix.

btk3s api and btk3s btpy already trust it, so this is only needed for the browser and for curl of your own — --cacert ~/.local/state/btk3s/ca-bundle.pem works without touching any store.

Log in​

btk3s creds

Two accounts, and they are not the same one:

  • admin@beacontower.dev at https://<domain>/ - the web client and the API. This is the tenant's default user.
  • beacontower at https://auth.<domain>/ - Keycloak's own admin console. The username is beacontower, not admin.

Passwords are masked; btk3s creds admin --show prints one, which is also how a script gets it:

PW=$(btk3s creds admin --show)

btk3s up mints both (user-service-default-user-password, keycloak-admin-password) into your Azure Key Vault and copies them into the tenant's Vault, and External Secrets copies them into the cluster; creds reads the copy the services actually use. btk3s up secrets on its own mints nothing: it lists what is missing.

From btk3s 0.7.8, signing in to a local tenant's web client asks for the password only; after btk3s update, run btk3s up once for it to take effect. A production tenant also asks for a one-time code from an authenticator app; to sign in that way here, put mfa: true in btk3s.yaml and run btk3s up. mfa: takes true or false, and btk3s up refuses anything else.

Call the API​

btk3s api /organizations
btk3s api /assets/my-first-device/debug/info
btk3s api -X POST /assets/dev-01/bind -d '{"autobindRemoteInstanceIds":["mqtt::dev-01"]}'

It signs in as the default user, adds the token and the CA, and pretty-prints what comes back. For a script that must make its own call:

TOK=$(btk3s api --token)

To browse what exists, open Swagger — the same API, with every path and schema:

https://<domain>/swagger/index.html

Two things that cost people an afternoon:

  • A Keycloak client you make yourself is not enough. Its client_credentials token belongs to no organization, and every read is refused with "does not have the required privilege", which reads like a broken token rather than missing setup. For an integration, create a service account instead: Call the API as a service account. btk3s api always uses the default user.
  • The API lives under /api/v1. Anything else under / falls through to the web client, which answers 200 with the SPA's HTML. btk3s api says so instead of printing a page at you.

What is already there​

btk3s up data created all of this, so you are not starting from an empty tenant:

btk3s api /organizations | jq -r '.[].displayName'
btk3s api /models | jq -r '.[].id'
btk3s api /providers | jq -r '.[].id'
ThingWhat it is
organization btk3severything you create is related to it; there are no rows without relations
15 privileges on itwhat makes the default user effectively a superadmin
3 DTDL modelsdtmi:jemac;4.2 (telemetry only), dtmi:jemac;4.4 (writable properties, so you can test a desired-property round trip), dtmi:bt_simple_sensor;1.1 (the minimal target)
provider mqttthe MQTT provider, plus a provider template
a routing target per tiertier 1 at mqtt.<domain>:8883, tier 2 at mqtt.<domain>:8884
an enrollment group per tiereach on its tier's routing target, with a responseTemplate, so a device gets settings back

up prints both group ids when it finishes, and writes them to ~/.local/state/btk3s/btpy.env ($XDG_STATE_HOME/btk3s/btpy.env if you set that) as BTK3S_EG_TIER1 and BTK3S_EG_TIER2, with BTK3S_ORG and BTK3S_MODEL. source that file to have them in your shell. It also holds the admin password, so keep it to yourself.

Authorisation, when a call is refused​

Access is a chain of relationships in SpiceDB, not a column in a database:

environment:default #<priv>_privilegee @tenant:default
tenant:default #<priv>_privilegee @organization:<guid>
organization:<guid> #owner @user:<guid>

All four levels must hold, for each of the 15 privilege types. If a call returns "does not have the required privilege", the token is usually fine and a link in that chain is missing.

Set relationships through the API or the SpiceDB CLI — never by writing to a database directly. Every POST also creates the relation between the organization and the resource; going around the API leaves resources that nothing can see.

Talking to it as a device​

The device-facing side is a separate host with its own certificate chain: the CA that EST hands out is the CA that signed the broker's certificate. doctor checks both, so there is nothing to verify by hand:

btk3s doctor          # the Domain section covers EST and the broker

Drive a real device end to end with the device CLI, btpy:

btk3s btpy device up  -d dev-01 -g <tier-2 group> -m 'dtmi:jemac;4.4' --tier 2 --telemetry-format jemac
btk3s btpy device run -d dev-01 --tier 2 --telemetry-format jemac --interval-ms 5000

up printed the group ids; device run keeps publishing until --count, --duration or Ctrl-C.

Because the domain is a nip.io name resolved from public DNS, a real device on your LAN can reach all of this — no /etc/hosts, no proxy.

Stopping and starting​

k3s keeps running across reboots, and the tenant comes back with it. To free the machine:

sudo systemctl stop k3s      # everything stops; Azure keeps costing a little
btk3s down # remove the tenant, keep Azure and the env layer
btk3s cloud destroy # destroy Azure too

After btk3s down, btk3s up rebuilds in about 20 minutes. After cloud destroy, add btk3s cloud up first and allow an hour.

Next​

  • Drive devices — tiers, and the rest of the device CLI.
  • When something is wrong — doctor, repair, and the symptoms one by one.
  • Upgrade — move to the newest release.
  • Develop a provider — the one thing you add to a tenant rather than replace in it.
  • btk3s --help — every command, one line each. --help after init, doctor, login, update, bug, api, creds, down or provider prints its arguments and flags, and btk3s btpy --help is the device CLI's own. The other commands have no help of their own.