Every app's .env gets CORE_ADMIN_EMAIL (admin@<domain>, the Core's own admin, as Federated's apps use). The skill says apps make that account an admin on each Core sign-in, trusting only Authelia's email, instead of a setup link; the sso example apps show the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 KiB
name, description
| name | description |
|---|---|
| coreapp | Build, port and test apps ("Coreapps") for Federated Core with coreapp-dev. Use this whenever someone wants to make an app run on a Federated Core, package an existing web app or repository for a Core, write or fix a coreapp.toml, give an app sign-in with Core accounts (Authelia) or a database on the Core's PostgreSQL, or deploy and test an app on the Core in the local coreapp-dev VM (coreapp deploy, coreapp check), even if they just say "make this work on our Core" or "Coreapp". |
Making apps for Federated Core
A Federated Core is a self-hosted server that runs many apps as Docker
containers behind one domain. A Coreapp is an app anyone can publish
and a Core's owner can install. coreapp-dev is the kit for making them: it
runs a real Core in a VM on this computer, and the coreapp command deploys
the app you're working on to it.
How a Coreapp works
An app is a repository with:
| File | What it is |
|---|---|
coreapp.toml |
What the Core needs to know (below) |
Dockerfile |
Builds the app's image |
| the app's code | Whatever the Dockerfile uses |
icon.png |
Its icon in the Core's dashboard: a square PNG, 256x256 is good, up to 1 MB (shown at 40x40). Without one, or if it isn't a PNG, the Core shows a default icon |
That's all. The app has no scripts and no compose file: a trusted
installer on the Core (coreapps) reads coreapp.toml and makes the rest:
the container on the Core's network, the HTTPS route and certificate for
https://<name>.<domain>, the app's settings and secrets, and whatever it
needs (its database, its sign-in client). This is deliberate: a Core
installs apps from other people's repositories, so an app gets to declare
what it needs, never to run commands on the Core. Don't try to get around
it (SSHing into the Core to edit files, adding scripts the Core should run):
whatever you change by hand there is lost on the next deploy and won't exist
on anyone else's Core.
What the Core gives every app:
-
One container, from the app's image, serving plain HTTP on one port. Traefik on the Core terminates HTTPS at
https://<name>.<domain>and forwards to that port. -
/datainside the container: kept on the Core across updates, restarts and reboots. The Core makes it belong to the user the image runs as (USERin the Dockerfile) before starting the container, so the image doesn't need to create or chown/dataitself (what the image has at/datais hidden by the mount anyway). Everything else in the container is thrown away on each update, so anything the app must keep (uploads, SQLite files, generated keys) goes under/data. -
Environment variables (from a
.envfile made once at install; updates keep the values and add new ones):Variable Value APP_URLhttps://<name>.<domain>, the app's public addressAPP_SECRET32 random letters and digits, for signing cookies, sessions IMAGE_VERSIONThe installed version ( coreapp deploybuilds with plaindocker build ., no build args, so read the version from here, not a build-timeVERSION)CORE_DOMAINThe Core's domain ( <domain>). Set only on a Core: an app that also runs elsewhere can use it to tellCORE_ADMIN_EMAILadmin@<domain>, the Core's admin account: always an admin of the app (seesso)APP_SECRETisn't hex or base64: an app that wants key bytes (e.g. 32 bytes for encryption) derives them, e.g. SHA-256 ofAPP_SECRET. It never changes, and it lives only in the app's.envon the Core (/federated/apps/<name>/.env, beside/data): anything encrypted with it is unreadable without that file.plus the ones each need adds (below).
coreapp.toml
name = "my-app" # id and hostname: https://my-app.<domain>
title = "My App" # shown in the Core's dashboard
description = "What it does, in a sentence"
docs = "https://example.com/docs" # optional; installed from a repository, defaults to it
image = "localhost/coreapp/my-app" # image name; the Core runs image:version
version = "0.1.0" # the image tag; raise it for each release
port = 8080 # the port the app serves HTTP on (any; 8080 is usual)
health = "/health" # a path that answers once it's up
needs = ["postgres", "sso"] # what it needs from the Core, or [] ("mysql", "email" too)
The installer is strict, because these values end up in files on the Core that are read by shell and YAML:
name: 2-31 lowercase letters, digits and-, starting with a letter, not ending with-. Names of Federated's own apps (nextcloud, gitea, ...) and the Core's hostnames (www, mail, ...) are refused.title: up to 40 letters, digits, spaces and. , ! ? ( ) & + _ -.description: up to 200 characters, no",$, backtick,\,@or line breaks.image: must start with its registry. While developing, uselocalhost/coreapp/<name>:coreapp deploybuilds it here and copies it to the Core, and it can't be pulled from anywhere by mistake. (A name without a registry, likeme/app, would mean Docker Hub, so it's refused.)version: letters, digits,.,_,-.port: a number, not a string. Use whatever port the app already listens on; for a new app, 8080. It's only reachable inside the Core.health: a path starting with/. Deploy waits until it answers with any status below 500 (so/is fine for an app without a health endpoint, even if it redirects to a sign-in page);coreapp checkwants a 2xx there, so prefer a path that returns 200 without signing in.- Unknown settings are refused, so a typo doesn't go unnoticed.
coreapp deploy checks the file first and says exactly what's wrong.
Needs
postgres: its own database
The Core makes a PostgreSQL user and database just for this app, and adds:
| Variable | Value |
|---|---|
DB_HOST |
postgresql.<domain> (resolves only on the Core's network, which the app is on) |
DB_PORT |
5432 |
DB_NAME, DB_USER |
coreapp_<name> with - as _ (e.g. coreapp_my_app) |
DB_PASSWORD |
random |
The server is PostgreSQL shared with the Core's other apps; the app owns its
database and nothing else. There's no superuser access, so the app creates
its own tables (migrations at startup are the usual way). At boot the
database may come up after the app: retry the connection instead of
exiting. Many apps want a URL; build it from these variables in the
entrypoint or the app's config (e.g.
postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME).
mysql: its own MySQL database (MariaDB)
For apps that need MySQL or MariaDB instead of PostgreSQL (use postgres
when the app supports both; an app can't have both). The Core makes a user
and database on its MariaDB 12 (the pdnsmysql container, shared with
PowerDNS and the Core's other apps), and adds the same variables:
| Variable | Value |
|---|---|
DB_HOST |
pdnsmysql.<domain> (resolves only on the Core's network) |
DB_PORT |
3306 |
DB_NAME, DB_USER |
coreapp_<name> with - as _ |
DB_PASSWORD |
random |
The database is utf8mb4; the app has all privileges on it and nothing
else. The rest is as for postgres (migrations, retrying at boot; a URL
is mysql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME).
coreapp new --mysql adds the need (there's no example app for it).
sso: sign-in with Core accounts
The Core registers the app as an OpenID Connect client with its Authelia, and adds:
| Variable | Value |
|---|---|
OIDC_ISSUER |
https://authelia.<domain> |
OIDC_CLIENT_ID |
coreapp-<name> |
OIDC_CLIENT_SECRET |
random |
The client, by default:
- Redirect URI: exactly
https://<name>.<domain>/auth/callback($APP_URL/auth/callback). - Authorization code flow, PKCE with S256 required, client authentication
client_secret_basic(secret in the Authorization header).
If the app's sign-in can't be configured to match (many have a fixed
callback path, and many don't send PKCE), change the client in
coreapp.toml instead of working around it in the app:
[sso]
callback = "/auth/openid/core" # the app's callback path (default "/auth/callback")
pkce = false # the app doesn't send PKCE (default true)
token_auth = "client_secret_post" # it sends the secret in the form (default client_secret_basic)
Set only what the app needs, and say in a comment why. Find out from the
app's documentation or source: the callback path it puts in redirect_uri
(sometimes built in the browser, e.g. /auth/openid/<provider key>; then
pick the key so the path is known), whether it sends code_challenge,
and how it sends the secret. Authelia checks the redirect URI when the
sign-in starts (an error page instead of its login page if it's wrong), but
PKCE and the secret only after the person has signed in, so a curl of the
authorize URL can't show those are right: coreapp signin can (see
"Deploy and test"). Changing
[sso] and deploying registers the client again; Authelia restarts for it
(a few seconds of 404s from it, which an app checking discovery at startup
may log; it should retry).
-
Scopes:
openid profile email groups. Userinfo givessub,preferred_username,name,email, andgroups, which is empty on today's Cores: they have two groups,adminsandeverybody, but Authelia's settings don't find them yet (for Federated to fix). Readgroupsif the app can use it, but don't depend on it for roles. -
The app's admin is the Core's admin. On a Core, the account
CORE_ADMIN_EMAIL(admin@<domain>, the Core's own admin, as in Federated's apps) is always an admin of the app, from its first sign-in: no setup link, no first-come owner. It can then make other people admins in the app. Two rules:- Trust it only from the Core's sign-in: the
emailin Authelia's userinfo or ID token, compared case-insensitively. Never make a local account, a sign-up or an invitation with that address an admin; anyone could type it. - Every time, not only the first: if its admin role was taken away in the app, its next Core sign-in gives it back.
If the app has its own first-run setup (an owner to create, a setup link), skip it on a Core: the Core's admin is the owner. The example app (
coreapp new --sso) shows the check inoidc.py.coreapp signinsigns in as the test account, not the admin, so ask the user to sign in once asadmin@<domain>in a browser and check it gets the admin pages. - Trust it only from the Core's sign-in: the
-
Discovery:
$OIDC_ISSUER/.well-known/openid-configuration. The Core routesauthelia.<domain>from inside the app's container to the real HTTPS endpoint, with a valid certificate, so normal TLS verification works. -
Sign-out in the app ends the app's session; the person stays signed in to the Core.
Use the app's own OpenID Connect support or its framework's library where it
has one: most self-hosted apps have "generic OIDC" settings that map onto
these variables. If the app has its own step for setting up its client (an
admin makes a secret in its settings, or pastes a client block into the
identity provider), skip it on the Core: fill its settings from OIDC_*,
so sign-in works with no admin step, and don't show those instructions when
the Core gave the client. For a standard-library Python example of the whole flow,
coreapp new --sso example makes one (oidc.py).
email: sending mail
The Core makes a mail account just for this app, for sending (no inbox), and adds:
| Variable | Value |
|---|---|
SMTP_HOST |
mail.<domain> (the Core's mail server; valid certificate) |
SMTP_PORT |
587 |
SMTP_SECURITY |
starttls (connect, then STARTTLS; not implicit TLS) |
SMTP_USER |
coreapp-<name> |
SMTP_PASSWORD |
random |
SMTP_FROM |
<name>@<domain>, the address to send from |
Most apps have SMTP settings; map these onto them. Mail to SMTP_FROM
isn't delivered anywhere (the account has no mailbox), so set a reply-to
if people should be able to answer. The account can't sign in to anything
else on the Core. coreapp new --email adds the need (there's no example
app for it).
Not available yet
The Core's AI features (offering
tools to its AI agent, or using its model), extra services such as Redis or
a second container, extra hostnames, and public ports other than HTTPS.
If the app can't work without one of these, say so plainly in your report
rather than working around it; the gap is useful to know. The same goes for
a need that doesn't fit the app (e.g. a sign-in [sso] can't describe):
report it rather than writing a proxy, bridge or second service into the
app's container. If it's optional
(e.g. email notifications), leave it off and note it.
Workflow
1. Check the tools
command -v coreapp && coreapp-vm list
coreapp-vm list should show the VM coreserver running. If coreapp is
missing or the VM isn't running, stop and tell the user: setting those up
(installing coreapp-dev, creating and provisioning the Core) is theirs to do
(coreapp-vm start only starts an existing VM).
2a. A new app
coreapp new my-app # plain (a static page on busybox)
coreapp new --postgres my-app # with a database (Python example)
coreapp new --sso my-app # with sign-in (Python example)
coreapp new --postgres --sso my-app # both
It makes ./my-app with a working example, coreapp.toml and a README.
Replace the example with the real app.
2b. An existing app (porting)
Work in the app's repository. Add coreapp.toml (copy the example above),
and make the Dockerfile fit the Core:
-
Listen on
0.0.0.0and onport, plain HTTP. No TLS in the app. -
Know its public address:
APP_URL(many apps need a "base URL" or "trusted host" setting; it's behind a proxy that sendsX-Forwarded-Proto: httpsandX-Forwarded-For). -
Keep state in
/data: point upload folders, SQLite files and generated keys there. If the app needs a directory structure under/data, create it at startup (it starts empty). -
Send mail with
needs = ["email"], if the app sends any (password resets, notifications): mapSMTP_*onto its mail settings. -
If the app also runs elsewhere (a desktop or another server edition sharing the Dockerfile), keep those working: choose the Core's behaviour in the app when
CORE_DOMAINis set (the Core's variables become defaults; the app's own explicit settings still win), not by changing the Dockerfile'sENVorENTRYPOINTfor everyone. The Core builds theDockerfileat the repository's root. -
Read settings from the environment, mapping the Core's names to the app's in an entrypoint script or config file if they differ (
SECRET_KEY="$APP_SECRET",DATABASE_URL=...). Set the app's own variables outright rather than "only if unset": upstream images often set defaults inENV(a SQLite path, a port) that would win otherwise. -
Images without a shell (built
FROM scratchor distroless) can't run an entrypoint script, andcoreapp shellcan't open one. Copy a static busybox in and run the script with it:FROM busybox:1.37-musl AS busybox FROM upstream/image:1.2.3 COPY --from=busybox /bin/busybox /bin/busybox COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/bin/busybox", "sh", "/entrypoint.sh"](end it with
execand the upstream entrypoint; call tools as/bin/busybox mkdir ...). Prefer this to a program of your own. -
Run as a non-root user if the image allows.
/datais given to whatever user the image runs as, so this is enough:RUN useradd --system --uid 1000 --home-dir /data app # Debian-based images USER app(
adduser -S -u 1000 -h /data appon Alpine.) Many upstream images already have a user; use it. -
Give it its own
icon.png: the project's logo, square, as a PNG (convert an SVG or ICO; 256x256 is good). The template's is a placeholder.coreapp deployandpublishsay if it's unusable, not square or under 80 pixels;publishrefuses one the Core can't use. -
Answer on
healthonce ready (a dedicated health endpoint, or/if it returns 2xx-4xx without signing in). -
One container. If the upstream project ships a compose file with several services, keep only the app, use
needs = ["postgres"](or["mysql"]for MySQL/MariaDB) for its database, and stop if it needs other services (see "Not available yet").
Keep the app's other files as they are; add .dockerignore entries for
coreapp.toml, icon.png and .git so they don't bust the build cache.
3. Deploy and test
coreapp deploy # check coreapp.toml, build, copy the image, install or update
coreapp check # https://<name>.<domain><health> answers with a valid certificate
Deploying again updates the app in place: same address, same secrets, same data and database. Change something, deploy, look. A new version isn't needed for each try; raise it when you release.
A deploy only replaces the container when something changed (the image or
the settings). To test that data really survives a new container, use
coreapp deploy --recreate, which always starts a fresh one.
coreapp deploy may ask before installing on a Core whose plan bills apps
as add-ons. That question is for the user; don't answer it yourself.
Then test it like a person would: open https://<name>.<domain>/ (curl it,
or ask the user to use a browser), sign in if it has sso, and check that
what it stores survives coreapp deploy --recreate (data in /data and
the database).
Sign in with coreapp signin: it signs in to the app as a browser would,
on the real Authelia with the app's real client, as the Core's test account
(coreapp.test@<domain>, display name coreapp.test, in no groups; made on
the Core in the VM when first needed, with a new password each time). It
prints each step, with Authelia's error if the client doesn't fit, and says
whether it got back to the app signed in:
coreapp signin # starts at /login
coreapp signin /auth/login # the app's own page that starts sign-in
coreapp signin /signin # a page whose button starts sign-in: pressed
coreapp signin --cookies jar /login && curl -b jar https://<name>.<domain>/api/me
A page with a sign-in button (a form with only hidden fields, such as a
CSRF token) is submitted as a person pressing it would; with several such
forms, pick one with --form <action>. Don't add routes to the app just for
the test.
For apps whose sign-in starts in the browser's JavaScript (single-page
apps: the page builds the authorize URL itself), coreapp signin --code
starts at Authelia with the app's client and stops at the app's callback,
printing it with the code; give that to the app as its page would (e.g.
Vikunja's: POST /api/v1/auth/openid/<key>/callback with code and
redirect_url). Its state is not the app's, so a callback that checks
state (a server-side callback page) refuses it: use the path form for those.
Authelia bans an account for a few minutes after repeated failed sign-ins,
so don't loop on it.
Still ask the user to sign in once in a browser before a release, as the
Core's admin (admin@<domain>): it checks what a script can't (the app's
pages, and that the admin gets the admin role).
4. When something fails
| Command | Shows |
|---|---|
coreapp status |
Its container, address, port, needs, URL |
coreapp logs / coreapp logs -f |
The app's own log |
coreapp signin [path] |
Signs in with the Core's test account and shows each step |
coreapp shell '<command>' |
Run one command in its container, e.g. coreapp shell 'id; env; ls -l /data' (without a command it opens an interactive shell, which needs a terminal) |
coreapp list |
All apps on the Core installed this way |
coreapp remove |
Uninstall it (asks first; deletes its data and database) |
Common causes:
- "doesn't answer at http://192.168.5.x:PORT/...": the app crashed (see
coreapp logs), listens on another port or on 127.0.0.1, orhealthpoints at a path that fails or redirects to an error. - "Rolled back": an update failed, so the Core put back the version that
ran before, with its settings, its database and
/dataas they were before the update (/dataonly where the Core's filesystem can copy it instantly; the message says), and undid needs the update added. Whatever the failed version wrote is gone. Its log is printed above that line (coreapp logsnow shows the old version's). When the version wasn't raised, the image that failed is the one running again. coreapp checkfails but deploy worked: a new certificate can take a minute; it retries for two. It also tries the VM directly, which tells the app apart from the way in.- Sign-in fails (
coreapp signinshows Authelia's error and hint): "The 'redirect_uri' parameter does not match" means the app's callback isn't the client's ([sso] callback); "invalid_client" means it sends the secret another way ([sso] token_auth); a PKCE error means[sso] pkcedoesn't match what the app does. - Permission denied under
/data: the app switches to another user after starting (the Core gives/datato the image'sUSER), or it writes somewhere else in the container (coreapp shell 'id; ls -ld /data').
The installer's own log (the Core's install scripts) is on the Core in
/federated/logs/coreapps/. It contains secrets, so don't print it in full;
look at the end of it with coreapp-vm ssh tail -n 40 /federated/logs/coreapps/<name>-install.log
only when a deploy fails in the installer itself.
5. Publishing (when the user asks for a release)
A published app is a tagged commit in its repository plus its image in a registry, from which any Core can install it. Only publish when the user asks: it pushes to their registry and tags their repository.
- Set
imageincoreapp.tomlto the registry: for an app on a Gitea server,<gitea-host>/<owner>/<repo>in lowercase (Gitea's container registry is on the same host).coreapp publishsuggests one from the git remote.coreapp deploykeeps working with that name. - Raise
versionif this version was published before (published versions are never replaced). - Commit everything;
coreapp publishrefuses uncommitted changes. coreapp publishbuilds the image for linux/amd64 (add--platform linux/amd64,linux/arm64for ARM Cores too), pushesimage:version, and tags the commitv<version>. It needsdocker login <registry>first; that's the user's to do (for Gitea, with a token that has thewrite:packagescope).- The user pushes the commit and tag:
git push && git push origin v<version>.
New apps also have .gitea/workflows/publish.yml, which does the same on
the Gitea server when a v* tag is pushed, if the repository has an
Actions runner that can use Docker and the secrets REGISTRY_USER and
REGISTRY_TOKEN. When porting an existing app, copy it from a new app
(coreapp new x) if the user wants it.
To check a release the way a Core's owner will get it:
coreapp install https://<gitea-host>/<owner>/<repo> installs it on the
Core in the VM from the repository (the newest v* tag; @v1.2.0 for
another), pulling the published image, and coreapp update <name> moves it
to a newer release. Coreapps are often private: for a private repository
and image, the Core needs a token for the host first, coreapp login <gitea-host>, which asks for a user name and a read-only token
(repositories and packages). That's the user's to enter, not yours. The Core
only reads coreapp.toml and icon.png from the repository; version has
to match the tag. On the same Core, coreapp deploy from the folder and
coreapp install from the repository update the same app (same name, data
and database). A Core keeps running the image it installed, by digest: a
release can't be fixed by pushing its tag again (installing it again is
refused), so publish a new version. Going back to an older release needs
coreapp install --downgrade <url>@v<old>; the user decides that, since
the older version may not understand the newer one's data.
Reporting back
When you're done, tell the user:
- what you changed in the repository (
coreapp.toml, Dockerfile, config), - what you tested and how (deploy, check, which pages, a redeploy keeping
data,
coreapp signin), and what they still need to test themselves (signing in in a browser with their own account), - anything the app needs that the Core doesn't offer yet, and how you handled it,
- anything in coreapp-dev that got in the way or was unclear. coreapp-dev is new, and this is how it gets better.