Let a Core keep a token for one owner's apps on a host

coreapp login <host>/<owner> saves a token used for that owner's
repositories and images before the host's token, so apps from different
accounts on one host can use different tokens. git sends it only under
https://<host>/<owner>/; docker gets it for that pull only. Errors name
the token that was tried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 20:51:41 -07:00
co-authored by Claude Opus 5.5
parent c337ba2530
commit f0468c43f2
6 changed files with 114 additions and 48 deletions
+8 -1
View File
@@ -306,7 +306,14 @@ Steps:
repository and package: installed at `https://pub-test.dev.fedcom.net/` repository and package: installed at `https://pub-test.dev.fedcom.net/`
(HTTP 200), `list` shows the source `@v0.1.0`, no docker login left (HTTP 200), `list` shows the source `@v0.1.0`, no docker login left
on the Core on the Core
- [ ] Tokens per host+owner, if a Core needs several accounts on one host - Done 2026-12-03: tokens per host+owner. `coreapp login
<host>/<owner>` keeps a token for that owner's apps, used before the
host's (repository: its first path segment; image: the one after the
registry); git's header is scoped to `https://<host>/<owner>/`.
Tested on dev.fedcom.net with David's pub-test: a wrong owner token
is used first and fails with a hint naming it, another owner's
leaves the host's in use, logout, and a re-install pulled the image
with the host's token
- [ ] Superpanel would manage these tokens - [ ] Superpanel would manage these tokens
- Done 2026-12-03: downgrades and digests. Installing an older release - Done 2026-12-03: downgrades and digests. Installing an older release
than the installed one is refused unless `--downgrade` (coreapps than the installed one is refused unless `--downgrade` (coreapps
+6 -3
View File
@@ -100,7 +100,7 @@ each new app explains the files and the settings it gets.
| `coreapp list` | The apps on the Core installed this way | | `coreapp list` | The apps on the Core installed this way |
| `coreapp install [--downgrade] <https://host/owner/repo>[@tag]` | Install a published app from its repository on the Core, as its owner would: shows what it is and needs, asks, then installs (default: the newest release tag; an older release than the installed one only with `--downgrade`) | | `coreapp install [--downgrade] <https://host/owner/repo>[@tag]` | Install a published app from its repository on the Core, as its owner would: shows what it is and needs, asks, then installs (default: the newest release tag; an older release than the installed one only with `--downgrade`) |
| `coreapp update <name>` | Update an app installed from a repository to its newest release | | `coreapp update <name>` | Update an app installed from a repository to its newest release |
| `coreapp login <host>` / `logout <host>` / `logins` | Give the Core a token for private apps from a host (asks for the user and token), forget it, list them | | `coreapp login <host>[/<owner>]` / `logout <host>[/<owner>]` / `logins` | Give the Core a token for private apps from a host, or from one owner (user or organization) there (asks for the user and token), forget it, list them |
| `coreapp publish [--platform <list>]` | Build the release image, push it to the registry in `coreapp.toml` (`image:version`, never replacing a published version) and tag the commit `v<version>` | | `coreapp publish [--platform <list>]` | Build the release image, push it to the registry in `coreapp.toml` (`image:version`, never replacing a published version) and tag the commit `v<version>` |
| `coreapp remove` | Uninstall it from the Core, with its database and sign-in client (asks first) | | `coreapp remove` | Uninstall it from the Core, with its database and sign-in client (asks first) |
@@ -119,8 +119,11 @@ It reads only `coreapp.toml` and `icon.png` at the newest release tag
`version`, and pulls the image from its registry. The repository and the `version`, and pulls the image from its registry. The repository and the
image can be private: `coreapp login gitea.example.com` gives the Core a image can be private: `coreapp login gitea.example.com` gives the Core a
token for that host (for Gitea, one with read access to repositories and token for that host (for Gitea, one with read access to repositories and
packages), which the installer uses for the repository and the image. It packages), which the installer uses for the repository and the image.
keeps tokens in `/etc/coreapps/credentials` on the Core (root only); docker `coreapp login gitea.example.com/my-team` gives one for that owner's apps
only (used before the host's), for when apps from different accounts on
one host need different tokens; git sends it only under
`https://gitea.example.com/my-team/`. It keeps tokens in `/etc/coreapps/credentials` on the Core (root only); docker
gets the token only for each pull, so the Core keeps no docker login. gets the token only for each pull, so the Core keeps no docker login.
The Core runs the image it pulled at install, by its digest The Core runs the image it pulled at install, by its digest
(`image:version@sha256:...`), so pushing the tag again can't change an (`image:version@sha256:...`), so pushing the tag again can't change an
+15
View File
@@ -568,6 +568,21 @@ has a `coreapp.toml` with a published, public `image` (e.g. after
token shown); on the Core `/etc/coreapps` is 700, `credentials` 600, and token shown); on the Core `/etc/coreapps` is 700, `credentials` 600, and
`/root/.docker/config.json` has no entry for the host. `coreapp logout `/root/.docker/config.json` has no entry for the host. `coreapp logout
<host>`: installing fails again. <host>`: installing fails again.
6a. Tokens per owner: `coreapp login <host>/<owner>` with a wrong token is
rejected, the file unchanged. With a token saved for `<host>/<owner>`
(on the Core, a wrong one written with `write_credentials`, to see which
is used), `coreapps plan https://<host>/<owner>/<repo>` uses it before
the host's: "Couldn't read ... (It used the token for <host>/<owner>:
check it can read this repository.)"; with one for another owner, the
host's token is used and the plan works. `coreapp logins` shows
"<host>/<owner> (user ...; for <owner>'s apps)"; `logout
<host>/<Owner>` (any case) forgets it. Keys are lowercase; git's header
is scoped to `https://<host>/<Owner>/` as the URL spells the owner
(`git config --get-urlmatch` gives it for `/Owner/app`, not for
`/owner/app`, `/Ownerx/app` or other owners). The image is pulled with
the owner's token (`<registry>/<owner>/<name>`), or else the host's;
re-installing pub-test with the host's token pulls it again (same
digest), with no docker login left.
7. `coreapp remove` in the app's folder (or `coreapps remove <name>` on the 7. `coreapp remove` in the app's folder (or `coreapps remove <name>` on the
Core) removes it like any other. Core) removes it like any other.
+22 -11
View File
@@ -42,8 +42,10 @@
# installed one) # installed one)
# coreapp update <name> update an app installed from a repository to its # coreapp update <name> update an app installed from a repository to its
# newest release # newest release
# coreapp login <host> give the Core a token for private apps from host # coreapp login <host>[/<owner>]
# (asks for the user and token); logout <host>, # give the Core a token for private apps from host
# (asks for the user and token; with /<owner>, for
# that owner's apps only); logout <host>[/<owner>],
# logins: forget one, list them # logins: forget one, list them
# coreapp publish [--platform <list>] # coreapp publish [--platform <list>]
# build the release image and push it to the # build the release image and push it to the
@@ -519,12 +521,20 @@ cmd_update() {
} }
cmd_login() { cmd_login() {
local host="${1:-}" user token local key="${1:-}" host user token
[[ $# -eq 1 && "$host" =~ ^[a-z0-9][a-z0-9.:-]*$ ]] \ [[ $# -eq 1 && "$key" =~ ^[A-Za-z0-9][A-Za-z0-9.:-]*(/[A-Za-z0-9][A-Za-z0-9._-]*)?$ ]] \
|| die "Usage: coreapp login <host> (e.g. coreapp login gitea.federated.computer)" || die "Usage: coreapp login <host>[/<owner>] (e.g. coreapp login gitea.federated.computer, or gitea.federated.computer/my-team for one owner's apps)"
host="${key%%/*}"
if [[ "$key" == */* ]]; then
echo "The Core in '$VM' keeps this token to install private apps from ${key#*/}"
echo "on $host (their repositories and images); other owners' apps there use"
echo "the token for $host, if it has one."
else
echo "The Core in '$VM' keeps this token to install private apps from $host:" echo "The Core in '$VM' keeps this token to install private apps from $host:"
echo "their repositories and images. For Gitea, make a token for it with read" echo "their repositories and images."
echo "access to repositories and packages (Settings > Applications)." fi
echo "For Gitea, make a token for it with read access to repositories and"
echo "packages (Settings > Applications)."
read -r -p "User on $host: " user read -r -p "User on $host: " user
[[ "$user" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || die "'$user' isn't a user name." [[ "$user" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || die "'$user' isn't a user name."
read -r -s -p "Token: " token read -r -s -p "Token: " token
@@ -532,15 +542,16 @@ cmd_login() {
init_core init_core
sync_installer sync_installer
# On stdin, so it's never in a command line # On stdin, so it's never in a command line
printf '%s\n' "$token" | core "$REMOTE_INSTALLER/coreapps login $host $user" printf '%s\n' "$token" | core "$REMOTE_INSTALLER/coreapps login $key $user"
} }
cmd_logout() { cmd_logout() {
local host="${1:-}" local key="${1:-}"
[[ $# -eq 1 && "$host" =~ ^[a-z0-9][a-z0-9.:-]*$ ]] || die "Usage: coreapp logout <host>" [[ $# -eq 1 && "$key" =~ ^[A-Za-z0-9][A-Za-z0-9.:-]*(/[A-Za-z0-9][A-Za-z0-9._-]*)?$ ]] \
|| die "Usage: coreapp logout <host>[/<owner>]"
init_core init_core
sync_installer sync_installer
core "$REMOTE_INSTALLER/coreapps logout $host" core "$REMOTE_INSTALLER/coreapps logout $key"
} }
cmd_logins() { cmd_logins() {
+58 -30
View File
@@ -22,9 +22,12 @@ coreapps update [--addon-ok] <name> update an app installed from a
repository to its newest release repository to its newest release
coreapps remove <name> uninstall an app installed by coreapps coreapps remove <name> uninstall an app installed by coreapps
coreapps list the apps installed by coreapps coreapps list the apps installed by coreapps
coreapps login <host> <user> keep a token (read from stdin) for coreapps login <host>[/<owner>] <user>
keep a token (read from stdin) for
installing private apps from host installing private apps from host
coreapps logout <host> forget host's token (with /<owner>: that owner's apps only,
used before the host's token)
coreapps logout <host>[/<owner>] forget that token
coreapps logins the hosts this Core has tokens for coreapps logins the hosts this Core has tokens for
coreapps mail <name> what the Core's mail server did with the coreapps mail <name> what the Core's mail server did with the
mail the app sent in the last day mail the app sent in the last day
@@ -136,10 +139,14 @@ GIT_ENV = {"PATH": "/usr/bin:/bin", "GIT_TERMINAL_PROMPT": "0",
"GIT_CONFIG_GLOBAL": "/dev/null", "HOME": "/nonexistent", "GIT_CONFIG_GLOBAL": "/dev/null", "HOME": "/nonexistent",
"LC_ALL": "C"} "LC_ALL": "C"}
GIT_TIMEOUT = 120 GIT_TIMEOUT = 120
# Tokens for private repositories and registries, by host (root only) # Tokens for private repositories and registries (root only), by host, or
# by host/owner for one account or organization's apps on a host where
# others need another token
CREDENTIALS = "/etc/coreapps/credentials" CREDENTIALS = "/etc/coreapps/credentials"
HOST = r"[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?(?::[0-9]{1,5})?" HOST = r"[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?(?::[0-9]{1,5})?"
LOGIN_USER = r"[A-Za-z0-9][A-Za-z0-9._-]{0,63}" LOGIN_USER = r"[A-Za-z0-9][A-Za-z0-9._-]{0,63}"
OWNER = r"[a-z0-9][a-z0-9._-]{0,63}"
LOGIN_KEY = HOST + r"(?:/" + OWNER + r")?"
TOKEN = r"[A-Za-z0-9._~+/=-]{8,512}" TOKEN = r"[A-Za-z0-9._~+/=-]{8,512}"
@@ -358,16 +365,17 @@ def read_credentials():
return {} return {}
except tomllib.TOMLDecodeError as e: except tomllib.TOMLDecodeError as e:
raise Refused(f"{CREDENTIALS} isn't valid: {e}") raise Refused(f"{CREDENTIALS} isn't valid: {e}")
return {host: c for host, c in data.items() return {key: c for key, c in data.items()
if isinstance(c, dict) and re.fullmatch(LOGIN_USER, str(c.get("user", ""))) if re.fullmatch(LOGIN_KEY, key) and isinstance(c, dict)
and re.fullmatch(LOGIN_USER, str(c.get("user", "")))
and re.fullmatch(TOKEN, str(c.get("token", "")))} and re.fullmatch(TOKEN, str(c.get("token", "")))}
def write_credentials(creds): def write_credentials(creds):
os.makedirs(os.path.dirname(CREDENTIALS), mode=0o700, exist_ok=True) os.makedirs(os.path.dirname(CREDENTIALS), mode=0o700, exist_ok=True)
os.chmod(os.path.dirname(CREDENTIALS), 0o700) os.chmod(os.path.dirname(CREDENTIALS), 0o700)
text = ("# Tokens coreapps uses to install private apps, by host. Manage with\n" text = ("# Tokens coreapps uses to install private apps, by host or host/owner\n"
"# coreapps login / logout.\n") "# (used first for that owner's apps). Manage with coreapps login / logout.\n")
for host in sorted(creds): for host in sorted(creds):
text += f'\n["{host}"]\nuser = "{creds[host]["user"]}"\ntoken = "{creds[host]["token"]}"\n' text += f'\n["{host}"]\nuser = "{creds[host]["user"]}"\ntoken = "{creds[host]["token"]}"\n'
new = CREDENTIALS + ".new" new = CREDENTIALS + ".new"
@@ -377,12 +385,24 @@ def write_credentials(creds):
os.rename(new, CREDENTIALS) os.rename(new, CREDENTIALS)
def basic_auth(host): def basic_auth(host, owner=""):
"""'user:token' in base64 for host, or None.""" """(the login's key, 'user:token' in base64) for owner's apps on host:
c = read_credentials().get(host) host/owner's token, else host's; or (None, None)."""
if not c: creds = read_credentials()
return None for key in ([f"{host}/{owner.lower()}"] if owner else []) + [host]:
return base64.b64encode(f"{c['user']}:{c['token']}".encode()).decode() c = creds.get(key)
if c:
return key, base64.b64encode(f"{c['user']}:{c['token']}".encode()).decode()
return None, None
def login_key(arg):
"""host or host/owner, checked and in lowercase."""
key = arg.lower().rstrip("/")
if not re.fullmatch(LOGIN_KEY, key):
raise Refused(f"'{arg}' isn't a host name (like gitea.example.com) or a host and "
"owner (gitea.example.com/my-team).")
return key
def url_host(url): def url_host(url):
@@ -420,10 +440,9 @@ def check_token(host, user, token):
return False if status in (401, 403) else None return False if status in (401, 403) else None
def login(host, user): def login(arg, user):
host = host.lower() key = login_key(arg)
if not re.fullmatch(HOST, host): host = key.split("/", 1)[0]
raise Refused(f"'{host}' isn't a host name (like gitea.example.com).")
if not re.fullmatch(LOGIN_USER, user): if not re.fullmatch(LOGIN_USER, user):
raise Refused(f"'{user}' isn't a user name.") raise Refused(f"'{user}' isn't a user name.")
token = sys.stdin.readline().strip() token = sys.stdin.readline().strip()
@@ -433,20 +452,22 @@ def login(host, user):
if ok is False: if ok is False:
raise Refused(f"{host} rejected the token for {user}. Nothing was saved.") raise Refused(f"{host} rejected the token for {user}. Nothing was saved.")
creds = read_credentials() creds = read_credentials()
creds[host] = {"user": user, "token": token} creds[key] = {"user": user, "token": token}
write_credentials(creds) write_credentials(creds)
say(f"Saved a token for {user}@{host}" say(f"Saved a token for {user}@{host}"
+ (f", for {key.split('/', 1)[1]}'s apps there" if "/" in key else "")
+ (" (its registry accepts it)." if ok else " (couldn't check it with its registry).")) + (" (its registry accepts it)." if ok else " (couldn't check it with its registry)."))
return 0 return 0
def logout(host): def logout(arg):
key = login_key(arg)
creds = read_credentials() creds = read_credentials()
if creds.pop(host.lower(), None) is None: if creds.pop(key, None) is None:
say(f"No token for {host}.") say(f"No token for {key}.")
return 0 return 0
write_credentials(creds) write_credentials(creds)
say(f"Forgot the token for {host}.") say(f"Forgot the token for {key}.")
return 0 return 0
@@ -454,8 +475,9 @@ def list_logins():
creds = read_credentials() creds = read_credentials()
if not creds: if not creds:
say("No tokens: this Core installs public apps only.") say("No tokens: this Core installs public apps only.")
for host in sorted(creds): for key in sorted(creds):
say(f"{host} (user {creds[host]['user']})") say(f"{key} (user {creds[key]['user']}"
+ (f"; for {key.split('/', 1)[1]}'s apps)" if "/" in key else ")"))
return 0 return 0
@@ -519,10 +541,16 @@ def fetch_repo(arg, staging):
"https://host/owner/repo (no user or password in it).") "https://host/owner/repo (no user or password in it).")
url = normalize_url(url) url = normalize_url(url)
host = url_host(url) host = url_host(url)
token = basic_auth(host) owner = url.split("://", 1)[1].split("/")[1]
auth = (f"https://{host}", token) if token else None key, token = basic_auth(host, owner)
no_access = ("" if token else # git sends it only under the login's address: the owner's (as the URL
f" If it's private, give this Core a token for {host}: coreapp login {host}.") # spells it; git compares paths exactly), or the host's
auth = ((f"https://{host}/{owner}" if "/" in key else f"https://{host}"), token) \
if token else None
no_access = (f" If it's private, give this Core a token for {host}: coreapp login {host} "
f"(or coreapp login {host}/{owner.lower()} for {owner}'s apps only)."
if not token else
f" (It used the token for {key}: check it can read this repository.)")
if tag and not re.fullmatch(TAG, tag): if tag and not re.fullmatch(TAG, tag):
raise Refused(f"'{tag}' isn't a release tag (v and a version, like v1.2.0).") raise Refused(f"'{tag}' isn't a release tag (v and a version, like v1.2.0).")
if not tag: if not tag:
@@ -834,8 +862,8 @@ def ensure_image(m, pull=False):
raise Refused(f"The image {ref} isn't on this Core, and localhost/ images " raise Refused(f"The image {ref} isn't on this Core, and localhost/ images "
"can't be pulled. coreapp deploy copies it here.") "can't be pulled. coreapp deploy copies it here.")
say(f"Pulling {ref}...") say(f"Pulling {ref}...")
registry = m["image"].split("/", 1)[0] registry, owner = m["image"].split("/")[:2]
token = basic_auth(registry) _, token = basic_auth(registry, owner)
# The token goes in a docker config just for this pull, so the Core # The token goes in a docker config just for this pull, so the Core
# keeps no docker login # keeps no docker login
with tempfile.TemporaryDirectory(prefix="coreapps-docker-") as config: with tempfile.TemporaryDirectory(prefix="coreapps-docker-") as config:
+4 -2
View File
@@ -41,8 +41,10 @@ To check a release the way a Core's owner will get it:
`version` has to match the tag. `version` has to match the tag.
- Coreapps are often private: for a private repository and image, the Core - 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 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 for a user name and a read-only token (repositories and packages); or for
the user's to enter, not yours. one owner there, `coreapp login <gitea-host>/<owner>`, when that owner's
apps need another account's token. That's the user's to enter, not
yours.
- On the same Core, `coreapp deploy` from the folder and `coreapp install` - On the same Core, `coreapp deploy` from the folder and `coreapp install`
from the repository update the same app (same name, data and database). 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 - A Core keeps running the image it installed, by digest: a release can't