oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1# Base
2
3Base is the front door for a small business. Your team signs in with their
4work email, you invite the people you work with, and you install apps from a
5Store. Base runs on a CARLOS Platform account, and each app you install runs
6as its own instance on that account.
7
8Base only says who someone is. Each app decides what that person may do.
9
10## Run it on your machine
11
12Copy `.env.local.example` to `.env.local` and fill it in, then:
13
14 ./run.sh
15
16It builds Base and listens on `127.0.0.1:8830` (change it with `BASE_ADDR`,
17which must stay on `127.0.0.1`). The database is `base.db` next to the script.
18
19Sign-in assertions only work between `https://` hostnames, and the verifier
20rejects IP addresses, so `http://127.0.0.1:8830` is no good as `BASE_ORIGIN`
21once you install an app. Share the port and use the origin it prints:
22
23 carlos devbox share --port 8830
24
25Put that origin in `BASE_ORIGIN`, and set `BASE_ALLOW_LOGGED_MAIL=1` only if
26the origin is on loopback and you want sign-in links printed to the log
27instead of emailed.
28
29## Settings
30
31Everything is an environment variable. `BASE_ORIGIN`, `BASE_OWNER` and
32`BASE_INSTANCE_KEY` are required.
33
34- `BASE_ORIGIN` is Base's public address: `https://` and a hostname, no path.
35 (`http://localhost` is allowed for local runs.)
36- `BASE_OWNER` is the email address of the owner, who can invite everyone else.
37- `BASE_INSTANCE_KEY` is a long random secret that seals sign-in state.
38 Keep it and don't change it: changing it breaks sign-in links in flight.
39 `openssl rand -base64 32` makes a good one.
40- `BASE_NAME` is what your team calls Base, such as "Acme" (default `Base`).
41- `BASE_SLUG` names the apps' hostnames: `<slug>-<appid>.<BASE_APPS_DOMAIN>`.
42 Lowercase letters, digits and `-`, at most 19 characters (default `base`).
43- `BASE_TIMEZONE` is where dates are shown, and the time zone Ask sends Equipo so the Assistant writes times in it ("Paused until 21:00"); default `Europe/Dublin`.
44- `BASE_ASSERTION_KEY` is Base's signing key. `go run ./tools/keygen` prints
45 a fresh one. Without it, no one can open an installed app. Keep it stable
46 across restarts: apps check sign-ins against its public half.
47- `BASE_ALLOW_LOGGED_MAIL=1` prints sign-in links instead of sending them.
48 Local only; Base refuses it on a non-loopback origin.
49- `BASE_EQUIPO_ORIGIN` is the Equipo whose Assistant answers "Ask Base
50 anything", such as `https://equipo.example.com`. Without it the Ask field
51 stays off. Each person connects Equipo once, from Settings or the Ask
52 panel; Base keeps their Equipo key sealed with `BASE_INSTANCE_KEY`, so
53 changing that key disconnects everyone from Equipo.
54 When a person connects, Base tells Equipo its own address (`BASE_ORIGIN`)
55 and gives it a token for that person alone. Equipo's Assistant uses the
56 token to read Base's apps, people and settings as that person. Connecting
57 again replaces the token, and disconnecting withdraws it. Equipo takes the
58 address only if its operator lists it in `EQUIPO_ASSISTANT_HOSTS`. Until
59 then the chat still works, but the Assistant can't see Base: Base logs
60 `host_not_allowed` and tries again the next time the person opens the chat.
61- `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows first
62 in its grid of apps, each opening in a new tab. Write each as
63 `id=address`, separated by commas, in the order you want them, such as
64 `calendar=https://calendar.oficina.works,fichas=https://fichas.oficina.works`.
65 The ids are `calendar`, `docs`, `sheets`, `slides`, `memoria`, `calls`,
66 `fichas` and `equipo`, and each address is `https://` and a hostname only.
67 Base refuses to start with an id it doesn't know. Without it, Home lists no
68 Oficina apps.
69
70To let your team sign in with Oficina ID, set all four of these. Without them
71Base has only its own sign-in. With some but not all, it refuses to start.
72Oficina ID needs `https://` in `BASE_ORIGIN`.
73
74- `BASE_HOME_ISSUER` is Oficina ID's address, such as `https://id.oficina.works`.
75- `BASE_HOME_CONSUMER_ID` is the id Oficina ID lists Base under, with Base's
76 origin.
77- `BASE_HOME_KEYS_BASE64` is Oficina ID's public keys: base64 of a JSON object
78 that maps each key id to the base64 of that public key.
79- `BASE_HOME_DEK_BASE64` is base64 of 32 random bytes that seal Oficina
80 sign-ins in flight and the links between accounts. Give Base a key of its
81 own and keep it: changing it breaks every connected account.
82 `openssl rand -base64 32` makes a good one.
83- `HOME_DIRECTORY_ORIGIN` is optional: the address of the Oficina directory.
84 Base checks it but doesn't link to it yet.
85
86With Oficina ID on, the sign-in page leads with "Sign in with Oficina", and
87email and passkeys stay below it. Everyone signs in with their email once and
88connects their Oficina account from Settings; after that, Oficina signs them
89in. Only members get in, and inviting people is still by email.
90
91Each connection is tied to `BASE_ORIGIN`. If you move Base to a new address,
92Oficina ID stops signing people in until they connect again: each person
93signs in with their email once and connects their Oficina account, from
94Settings or straight from "Sign in with Oficina". The old connection is
95cleared then. Nothing else is needed.
96
97Base's Mac and iPhone app signs in with Oficina ID too, through
98`POST /native/oficina-id`; its session lasts seven days, and the app renews
99it. Someone must have signed in to Base on the web with Oficina ID once
100before the app lets them in. The app reads and calls what
101`docs/api/base-native-v1.md` describes.
102
103The app connects Ask Base with Oficina ID, so there's no code to approve in
104Equipo. Base signs the person in to Equipo with Oficina ID on their behalf
105and keeps the Equipo key sealed, as it does one from the code. This works
106only for someone Equipo has already linked to their Oficina ID (they've
107signed in to Equipo with it); for anyone else the app shows that Ask isn't
108set up for them yet, and they can connect it with a code from Base on the
109web. A key made this way lasts seven days, not thirty: it ends with the
110Equipo session it was made with, or sooner if the person signs out of
111Equipo or leaves the team there. The app makes a new one after five days,
112without asking. Base never signs that Equipo session out, because doing so
113would end the key.
114
115To install apps, Base also needs to reach the Platform. Without these five and
116`BASE_ASSERTION_KEY`, it still runs and logs that installs are off.
117
118- `BASE_PLATFORM_CONSOLE` is the console's address.
119- `BASE_PLATFORM_ACCOUNT` is the account Base runs on.
120- `BASE_PLATFORM_INSTANCE_TOKEN` is a service credential with the `instance`
121 role.
122- `BASE_PLATFORM_OPERATE_TOKEN` is a second one with the `operate` role.
123 A credential holds one role, so you need two. Both are account-wide:
124 create them without `--app`.
125- `BASE_APPS_DOMAIN` is the domain apps live under. Base checks at start-up
126 that it and `BASE_ORIGIN` make addresses an app can accept sign-ins from:
127 a hostname, not an IP address, and no `:443`.
128
129Base installs Welcome when it starts. If the owner uninstalls Welcome, Base
130remembers and leaves it off; installing it from the Store brings it back.
131An installed app keeps the address it was installed at, even if you change
132`BASE_SLUG` or `BASE_APPS_DOMAIN` later.
133
134Outside loopback, Base sends mail through `CARLOS_SMTP_HOST` and
135`CARLOS_SMTP_FROM`.
136
137## Deploy
138
139Build the binaries, then deploy Base to a channel:
140
141 make release
142 carlos deploy --app base --channel edge releases/base-linux-arm64-<version>
143
144`make release` refuses to build from a dirty tree. It fetches Timeless Sans
145if it isn't there yet (this needs the network), and refuses to build unless
146the font is exactly the pinned file. It builds `base`,
147`scratchpad` and `welcome` for linux/arm64 into `releases/`, named with the
148commit. Set the `BASE_*` settings with `carlos env set --app base KEY=value`.
149
150## Before anyone can install an app
151
152This is a one-time job for whoever runs the account, and you repeat it when
153you add an app to the catalogue. The Platform needs each app to exist, have a
154release, and have instances enabled before Base is allowed to create one for a
155team:
156
157 scripts/prepare-apps.sh <account> releases [<version>]
158
159Pass the version (the commit in the binary names) if `releases/` holds more
160than one build; the script refuses to guess. For every app in `internal/catalog/catalog.json` it claims the name, ships
161the binary and promotes it to `edge`, and enables instances. Run it again if something
162fails halfway; steps already done are skipped. It stops if the account
163doesn't list an app but the name can't be claimed, because someone else owns it. You need to be logged in with
164`carlos auth login` first.
165
166Not every catalogue app is built here. Contra's binary comes from its own
167repository (`carlos/contra`), and it must be shipped with mail submission on,
168which this script doesn't do. So before running the script:
169
1701. Run `make release` in Contra. It writes `releases/contra-linux-arm64` and
171 prints the version it stamped.
1722. Ship it yourself on Base's account (`BASE_PLATFORM_ACCOUNT`; `oficina` in
173 production): `carlos ship --app contra --account <account> --mail submit
174 --version <version> releases/contra-linux-arm64`. Claim the name first with
175 `carlos apps create` if the account doesn't have `contra` yet. An app
176 called `contra` on another account is a different app and doesn't matter.
1773. Copy the binary into Base's `releases/` as `contra-linux-arm64-<version>`,
178 the same version. The script then finds it already shipped, promotes it to
179 `edge` and enables instances.
180
181Contra's version is its own commit, not Base's, so keep one build of each app
182in `releases/` rather than passing a version: a version you pass must match
183every app's file name.
184
185## Writing an app Base can install
186
187Base starts your app with four variables. Read them, and verify sign-ins
188against them:
189
190- `BASE_APP_ORIGIN` is your app's own address.
191- `BASE_APP_ISSUER` is Base's address. Accept assertions only from this issuer.
192- `BASE_APP_CONSUMER_ID` is the id of your app in the catalogue.
193- `BASE_APP_KEYS` is base64 of a JSON object that maps each key id (`kid`) to
194 the base64 of that key's 65-byte public key. Check each assertion's
195 signature against the key its `kid` names.
196
197`internal/consumer` does all of this for a Go app, and adds a sign-out
198(`POST /auth/signout`) that ends the app's own session. Give people a button
199for it: signing out of Base doesn't sign them out of your app.
200
201Nothing in Base is specific to one app. `internal/scratchpad` is the small
202example to copy, and its README says who can use it: anyone the Base that
203installed it vouches for, with no roles of their own.
204
205## Checks
206
207`make ci` is the gate. `make browser` drives Chromium through Base and the
208apps it installs; set `RASTRILLO_CHROME` to a Chromium first. `make fonts`
209fetches Timeless Sans, which the licence keeps out of the repository. Without
210it development and test builds fall back to DM Sans; a release never does.
211
212`docs/live-check.md` is the by-hand check against a real account.
213