Let an app name the oldest database server it works with

coreapp.toml's [postgres] or [mysql] min_version: the installer compares
it with the Core's PostgreSQL or MariaDB on install and update, and
refuses an older Core with both versions, instead of the app failing
later. coreapp core reads the versions the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 20:31:23 -07:00
co-authored by Claude Opus 5.5
parent cf18bef278
commit c60d99baba
7 changed files with 102 additions and 30 deletions
+6 -3
View File
@@ -497,9 +497,12 @@ Steps:
pg_trgm and earthdistance, a refused postgis, and a rollback that pg_trgm and earthdistance, a refused postgis, and a rollback that
kept them. Also fixed: `needs` with both postgres and mysql was kept them. Also fixed: `needs` with both postgres and mysql was
meant to be refused, but the check never ran meant to be refused, but the check never ran
- [ ] PostgreSQL 18 on the Core (Federated's), or a minimum version - Done 2026-12-03: `[postgres]` / `[mysql]` `min_version` in
in coreapp.toml that the installer checks, so an app refuses to coreapp.toml: the installer compares it with the Core's server
install on an older Core instead of failing later (numerically) on install and update, and refuses an older one
with both versions. Tested on dev.fedcom.net (PostgreSQL 17.6,
MariaDB 12.1.2)
- [ ] PostgreSQL 18 on the Core (Federated's; David is asking)
- [ ] David: the agent's changes, for Supermarket's own repository - [ ] David: the agent's changes, for Supermarket's own repository
(and a login CSRF it noticed in the app's sign-in: its OIDC state (and a login CSRF it noticed in the app's sign-in: its OIDC state
isn't tied to a browser cookie) isn't tied to a browser cookie)
+3 -2
View File
@@ -68,8 +68,9 @@ callback = "/auth/openid/core" # default "/auth/callback"
pkce = false # default true pkce = false # default true
token_auth = "client_secret_post" # default "client_secret_basic" token_auth = "client_secret_post" # default "client_secret_basic"
[postgres] # optional: extensions only a superuser can make [postgres] # optional ([mysql] has min_version too)
extensions = ["vector"] min_version = "16" # an older Core's PostgreSQL refuses the app
extensions = ["vector"] # ones only a superuser can make
``` ```
The app has no scripts or compose file: the Core side is made by The app has no scripts or compose file: the Core side is made by
+9
View File
@@ -233,6 +233,15 @@ The Core's own scripts trace secrets, so their output goes to
the table and its index. `[postgres]` without `"postgres"` in needs, an the table and its index. `[postgres]` without `"postgres"` in needs, an
unknown setting or a bad name is refused; so is `needs` with both unknown setting or a bad name is refused; so is `needs` with both
postgres and mysql. postgres and mysql.
5d. `min_version`: on the Core's PostgreSQL 17.6, a new app with
`[postgres]` `min_version = "18"` is refused before anything is built
("Vectest needs PostgreSQL 18 or newer ...; this Core has 17.6");
`"17"` installs; raising it to `"18"` in an update is refused and the
app keeps running. A `--mysql` app with `[mysql]` `min_version = "13"`
is refused ("needs MariaDB 13 or newer ...; this Core has 12.1.2").
Comparison is numeric (`"17.10"` is newer than 17.6); `min_version =
17.4` (a TOML number with a dot) and `">=18"` are refused with a hint;
`[mysql]` has no `extensions`.
6. `coreapp status` (address and port), `coreapp logs`, `coreapp shell` 6. `coreapp status` (address and port), `coreapp logs`, `coreapp shell`
(exit with `exit`), `coreapp shell 'id; echo $APP_URL'` (prints both, (exit with `exit`), `coreapp shell 'id; echo $APP_URL'` (prints both,
no terminal needed, also when piped), `coreapp list` (all apps installed no terminal needed, also when piped), `coreapp list` (all apps installed
+64 -21
View File
@@ -99,6 +99,7 @@ FIELDS = {
"needs": None, "needs": None,
"sso": None, "sso": None,
"postgres": None, "postgres": None,
"mysql": None,
} }
REQUIRED = ["name", "title", "version", "image", "port"] REQUIRED = ["name", "title", "version", "image", "port"]
@@ -109,9 +110,13 @@ SSO_DEFAULTS = {"callback": "/auth/callback", "pkce": True,
SSO_CALLBACK = r"/[A-Za-z0-9._~/-]{0,200}" SSO_CALLBACK = r"/[A-Za-z0-9._~/-]{0,200}"
SSO_TOKEN_AUTH = ["client_secret_basic", "client_secret_post"] SSO_TOKEN_AUTH = ["client_secret_basic", "client_secret_post"]
# [postgres]: extensions the Core's superuser enables in the app's database # [postgres] and [mysql]: the oldest server version the app works with
# (ones the app's own user can't, like vector) # (the installer refuses an older Core), and for postgres the extensions
POSTGRES_SETTINGS = ["extensions"] # the Core's superuser makes in the app's database (ones the app's own user
# can't, like vector)
DB_SETTINGS = {"postgres": ["min_version", "extensions"], "mysql": ["min_version"]}
DB_SERVER = {"postgres": "PostgreSQL", "mysql": "MariaDB"}
MIN_VERSION = r"[0-9]{1,4}(?:\.[0-9]{1,4}){0,2}"
EXTENSION = r"[a-z0-9][a-z0-9_-]{0,62}" EXTENSION = r"[a-z0-9][a-z0-9_-]{0,62}"
# Repositories apps are installed from: https only, no user or password in # Repositories apps are installed from: https only, no user or password in
@@ -162,20 +167,31 @@ def read_sso(value):
return sso return sso
def read_postgres(value): def read_database(need, value):
"""coreapp.toml's [postgres] table, checked.""" """coreapp.toml's [postgres] or [mysql] table, checked."""
known = DB_SETTINGS[need]
if not isinstance(value, dict): if not isinstance(value, dict):
raise Refused('coreapp.toml: postgres must be a table: [postgres] with extensions = ["vector"].') raise Refused(f"coreapp.toml: {need} must be a table: [{need}] with {', '.join(known)}.")
unknown = sorted(set(value) - set(POSTGRES_SETTINGS)) unknown = sorted(set(value) - set(known))
if unknown: if unknown:
raise Refused(f"coreapp.toml: [postgres]: unknown setting(s) {', '.join(unknown)} " raise Refused(f"coreapp.toml: [{need}]: unknown setting(s) {', '.join(unknown)} "
f"(it knows {', '.join(POSTGRES_SETTINGS)}).") f"(it knows {', '.join(known)}).")
db = {"min_version": "", "extensions": []}
if "min_version" in value:
version = value["min_version"]
if isinstance(version, int) and not isinstance(version, bool):
version = str(version)
if not isinstance(version, str) or not re.fullmatch(MIN_VERSION, version):
raise Refused(f'coreapp.toml: [{need}] min_version must be a {DB_SERVER[need]} '
'version, like min_version = "18" or "17.4".')
db["min_version"] = version
extensions = value.get("extensions", []) extensions = value.get("extensions", [])
if not isinstance(extensions, list) or not all( if not isinstance(extensions, list) or not all(
isinstance(e, str) and re.fullmatch(EXTENSION, e) for e in extensions): isinstance(e, str) and re.fullmatch(EXTENSION, e) for e in extensions):
raise Refused('coreapp.toml: [postgres] extensions must be a list of extension names, ' raise Refused('coreapp.toml: [postgres] extensions must be a list of extension names, '
'like extensions = ["vector"].') 'like extensions = ["vector"].')
return {"extensions": sorted(set(extensions))} db["extensions"] = sorted(set(extensions))
return db
def read_manifest(folder): def read_manifest(folder):
@@ -200,7 +216,8 @@ def read_manifest(folder):
raise Refused(f"coreapp.toml needs {', '.join(missing)}.") raise Refused(f"coreapp.toml needs {', '.join(missing)}.")
m = {"description": "", "health": "/", "docs": "", "needs": [], "sso": dict(SSO_DEFAULTS), m = {"description": "", "health": "/", "docs": "", "needs": [], "sso": dict(SSO_DEFAULTS),
"postgres": {"extensions": []}} "postgres": {"min_version": "", "extensions": []},
"mysql": {"min_version": "", "extensions": []}}
for key, value in data.items(): for key, value in data.items():
if key == "port": if key == "port":
if not isinstance(value, int) or isinstance(value, bool) or not 1 <= value <= 65535: if not isinstance(value, int) or isinstance(value, bool) or not 1 <= value <= 65535:
@@ -218,8 +235,8 @@ def read_manifest(folder):
"(both give the app DB_* settings).") "(both give the app DB_* settings).")
elif key == "sso": elif key == "sso":
value = read_sso(value) value = read_sso(value)
elif key == "postgres": elif key in DB_SETTINGS:
value = read_postgres(value) value = read_database(key, value)
else: else:
if not isinstance(value, str) or not re.fullmatch(FIELDS[key], value): if not isinstance(value, str) or not re.fullmatch(FIELDS[key], value):
raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. " raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. "
@@ -227,8 +244,9 @@ def read_manifest(folder):
m[key] = value m[key] = value
if "sso" in data and "sso" not in m["needs"]: if "sso" in data and "sso" not in m["needs"]:
raise Refused('coreapp.toml: [sso] is for apps with "sso" in needs.') raise Refused('coreapp.toml: [sso] is for apps with "sso" in needs.')
if "postgres" in data and "postgres" not in m["needs"]: for need in DB_SETTINGS:
raise Refused('coreapp.toml: [postgres] is for apps with "postgres" in needs.') if need in data and need not in m["needs"]:
raise Refused(f'coreapp.toml: [{need}] is for apps with "{need}" in needs.')
if m["name"] in RESERVED: if m["name"] in RESERVED:
raise Refused(f"'{m['name']}' is one of the Core's own hostnames. Pick another name.") raise Refused(f"'{m['name']}' is one of the Core's own hostnames. Pick another name.")
m["dbname"] = "coreapp_" + m["name"].replace("-", "_") m["dbname"] = "coreapp_" + m["name"].replace("-", "_")
@@ -623,6 +641,7 @@ def plan(m, origin=None, downgrade=False, drop_database=False):
else: else:
p["new_needs"] = list(m["needs"]) p["new_needs"] = list(m["needs"])
p["dropped_needs"] = [] p["dropped_needs"] = []
check_db_version(m)
p["new_extensions"] = extensions_to_enable(m, p) p["new_extensions"] = extensions_to_enable(m, p)
for key in ("source", "tag", "commit"): for key in ("source", "tag", "commit"):
if origin: if origin:
@@ -630,6 +649,34 @@ def plan(m, origin=None, downgrade=False, drop_database=False):
return p return p
def db_version(need):
"""The Core's PostgreSQL or MariaDB version, like "17.6", or ""."""
if need == "postgres":
out = run(["docker", "exec", "postgresql", "postgres", "--version"]).stdout
found = re.search(r"\) ([0-9][0-9.]*[0-9])", out)
else:
out = run(["docker", "exec", "pdnsmysql", "mariadb", "--version"]).stdout
found = re.search(r"([0-9][0-9.]*[0-9])-MariaDB", out)
return found.group(1) if found else ""
def check_db_version(m):
"""Refused if the app's database server here is older than its
[postgres] or [mysql] min_version."""
for need in DB_SETTINGS:
wanted = m[need]["min_version"]
if need not in m["needs"] or not wanted:
continue
have = db_version(need)
if not have:
raise Refused(f"Couldn't find this Core's {DB_SERVER[need]} version to check "
f"[{need}] min_version = \"{wanted}\". Is it running?")
key = lambda v: [int(x) for x in v.split(".")]
if key(have) < key(wanted):
raise Refused(f"{m['title']} needs {DB_SERVER[need]} {wanted} or newer "
f"([{need}] min_version in coreapp.toml); this Core has {have}.")
def extensions_to_enable(m, p): def extensions_to_enable(m, p):
"""[postgres] extensions the app's database doesn't have yet, or Refused """[postgres] extensions the app's database doesn't have yet, or Refused
if this Core's PostgreSQL doesn't have one.""" if this Core's PostgreSQL doesn't have one."""
@@ -1433,9 +1480,7 @@ def core_info():
"""The Core's services, versions and machine, as apps see them.""" """The Core's services, versions and machine, as apps see them."""
domain, _ = federated_settings() domain, _ = federated_settings()
rows = [("Domain", domain)] rows = [("Domain", domain)]
pg = run(["docker", "exec", "postgresql", "postgres", "--version"]).stdout rows.append(("PostgreSQL", (db_version("postgres") or "?") + ' (needs = ["postgres"])'))
found = re.search(r"\) ([0-9][0-9.]*)", pg)
rows.append(("PostgreSQL", (found.group(1) if found else "?") + ' (needs = ["postgres"])'))
ext = run(["docker", "exec", "postgresql", "psql", "-U", "postgres", "-Atc", ext = run(["docker", "exec", "postgresql", "psql", "-U", "postgres", "-Atc",
"SELECT v.trusted, string_agg(e.name || ' ' || e.default_version, ', ' ORDER BY e.name) " "SELECT v.trusted, string_agg(e.name || ' ' || e.default_version, ', ' ORDER BY e.name) "
"FROM pg_available_extensions e JOIN pg_available_extension_versions v " "FROM pg_available_extensions e JOIN pg_available_extension_versions v "
@@ -1445,9 +1490,7 @@ def core_info():
trusted, _, names = line.partition("|") trusted, _, names = line.partition("|")
rows.append((" extensions the app can enable" if trusted == "t" else rows.append((" extensions the app can enable" if trusted == "t" else
" extensions only the Core can enable", names)) " extensions only the Core can enable", names))
maria = run(["docker", "exec", "pdnsmysql", "mariadb", "--version"]).stdout rows.append(("MariaDB", (db_version("mysql") or "?") + ' (needs = ["mysql"])'))
found = re.search(r"([0-9][0-9.]*)-MariaDB", maria)
rows.append(("MariaDB", (found.group(1) if found else "?") + ' (needs = ["mysql"])'))
rows.append(("Authelia", image_tag("authelia") + ' (needs = ["sso"], OpenID Connect)')) rows.append(("Authelia", image_tag("authelia") + ' (needs = ["sso"], OpenID Connect)'))
rows.append(("Mail server", "docker-mailserver " + image_tag("mail") rows.append(("Mail server", "docker-mailserver " + image_tag("mail")
+ ' (needs = ["email"], sending with SMTP and STARTTLS)')) + ' (needs = ["email"], sending with SMTP and STARTTLS)'))
+13 -1
View File
@@ -113,6 +113,16 @@ them with the Core. Check the app's requirements against them before
choosing a need (its docs, the images in its own compose file, its choosing a need (its docs, the images in its own compose file, its
migrations): a feature the Core's version lacks fails only when the code migrations): a feature the Core's version lacks fails only when the code
using it runs, so deploy, `coreapp check` and a sign-in can all pass. using it runs, so deploy, `coreapp check` and a sign-in can all pass.
If the app needs a newer database server than some Cores have, put its
oldest working version in `coreapp.toml`, so an older Core refuses to
install it (with both versions in the message) instead of breaking later:
```toml
[postgres]
min_version = "16" # or [mysql] min_version = "11.4" (MariaDB's numbering)
```
Use what the app's docs or code require, not just today's version.
| What | Today | For the app | | What | Today | For the app |
|---|---|---| |---|---|---|
@@ -199,6 +209,7 @@ 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 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`). 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). `coreapp new --mysql` adds the need (there's no example app for it).
`[mysql] min_version` works as for postgres; there are no extensions.
### `sso`: sign-in with Core accounts ### `sso`: sign-in with Core accounts
@@ -268,7 +279,8 @@ works. Ask the user to confirm delivery to a real address.
A newer database server than the Core's (an app that needs PostgreSQL 18: A newer database server than the Core's (an app that needs PostgreSQL 18:
if the app also supports SQLite, that in `/data` is a fine choice, and say if the app also supports SQLite, that in `/data` is a fine choice, and say
so in your report), the Core's AI features (offering so in your report; otherwise set `min_version`, which refuses on this
Core, and report it), the Core's AI features (offering
tools to its AI agent, or using its model), extra services such as Redis or 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. 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 If the app can't work without one of these, say so plainly in your report
+2 -1
View File
@@ -47,7 +47,8 @@ keep its values and add new ones):
`needs = ["postgres"]` adds `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and `needs = ["postgres"]` adds `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and
`DB_PASSWORD` (`needs = ["mysql"]` the same, for MariaDB; PostgreSQL `DB_PASSWORD` (`needs = ["mysql"]` the same, for MariaDB; PostgreSQL
extensions only a superuser can make, like vector, go in `coreapp.toml`'s extensions only a superuser can make, like vector, go in `coreapp.toml`'s
`[postgres] extensions`); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and `[postgres] extensions`, and the oldest server version it works with in
`min_version`); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
`OIDC_CLIENT_SECRET` (the client's callback, PKCE and secret method are in `OIDC_CLIENT_SECRET` (the client's callback, PKCE and secret method are in
`coreapp.toml`'s `[sso]`); `needs = ["email"]` adds `SMTP_HOST`, `SMTP_PORT` `coreapp.toml`'s `[sso]`); `needs = ["email"]` adds `SMTP_HOST`, `SMTP_PORT`
(587), `SMTP_SECURITY` (`starttls`), `SMTP_USER`, `SMTP_PASSWORD` and (587), `SMTP_SECURITY` (`starttls`), `SMTP_USER`, `SMTP_PASSWORD` and
+5 -2
View File
@@ -30,7 +30,10 @@ needs = []
# pkce = true # whether it sends PKCE (S256) # pkce = true # whether it sends PKCE (S256)
# token_auth = "client_secret_basic" # or "client_secret_post" # token_auth = "client_secret_basic" # or "client_secret_post"
# With "postgres": extensions the app's database user can't make itself, # With "postgres" (or "mysql"): the oldest server version the app works
# made by the Core (coreapp core lists what it has) # with, so an older Core refuses it; for postgres, extensions the app's
# database user can't make itself, made by the Core (coreapp core lists
# the versions and extensions it has)
# [postgres] # [postgres]
# min_version = "16"
# extensions = ["vector"] # extensions = ["vector"]