The Core's admin account is always an admin of the app
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>
This commit is contained in:
@@ -416,6 +416,15 @@ Steps:
|
|||||||
the first admin comes from a setup link in the log, not whoever signs
|
the first admin comes from a setup link in the log, not whoever signs
|
||||||
in first; apps with their own client-setup step take `OIDC_*`
|
in first; apps with their own client-setup step take `OIDC_*`
|
||||||
instead; icons under 80 pixels get a note
|
instead; icons under 80 pixels get a note
|
||||||
|
- Decided 2026-12-03 (David): on a Core, the Core's admin account
|
||||||
|
`admin@<domain>` (uid `admin`, the one member of `admins`; Federated's
|
||||||
|
own apps make it their admin too) is always an admin of the app,
|
||||||
|
trusted only from the Core's sign-in. Every app's `.env` has
|
||||||
|
`CORE_ADMIN_EMAIL`; the skill says so instead of a setup link, and
|
||||||
|
the sso example shows it. Supermarket (setup link) should change
|
||||||
|
to it
|
||||||
|
- [ ] David: sign in to a `coreapp new --sso` app as admin in a
|
||||||
|
browser ("the app's admin")
|
||||||
- [ ] 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)
|
||||||
|
|||||||
@@ -192,8 +192,9 @@ The Core's own scripts trace secrets, so their output goes to
|
|||||||
`docker-compose.yml.in`, `env.in`, `install`, `uninstall`, `icon.png`,
|
`docker-compose.yml.in`, `env.in`, `install`, `uninstall`, `icon.png`,
|
||||||
`coreapp.toml` and `.coreapp` (`needs=`); `/federated/apps/hello/.env`
|
`coreapp.toml` and `.coreapp` (`needs=`); `/federated/apps/hello/.env`
|
||||||
is root's, mode 600, with `IMAGE_VERSION` equal to `version` and a
|
is root's, mode 600, with `IMAGE_VERSION` equal to `version` and a
|
||||||
random `APP_SECRET`, and `CORE_DOMAIN` the Core's domain (an app
|
random `APP_SECRET`, `CORE_DOMAIN` the Core's domain and
|
||||||
installed before `CORE_DOMAIN` existed gets it on its next update).
|
`CORE_ADMIN_EMAIL` `admin@<domain>` (an app installed before they
|
||||||
|
existed gets them on its next update).
|
||||||
Superpanel's catalog
|
Superpanel's catalog
|
||||||
(`/federated/apps/superpanel/data/catalog.json`) lists `hello`.
|
(`/federated/apps/superpanel/data/catalog.json`) lists `hello`.
|
||||||
3. `coreapp check`: `OK: HTTP 200, valid certificate.` (the first
|
3. `coreapp check`: `OK: HTTP 200, valid certificate.` (the first
|
||||||
@@ -354,6 +355,11 @@ has the `DB_*` variables, `.coreapp` says `needs=postgres`.
|
|||||||
/nope (its forms: /signin, /signin/core)". sso-demo's `/` (a link, not
|
/nope (its forms: /signin, /signin/core)". sso-demo's `/` (a link, not
|
||||||
a form): "didn't lead to the Core's sign-in". A page with two
|
a form): "didn't lead to the Core's sign-in". A page with two
|
||||||
hidden-only forms: "several forms ... pick one with --form".
|
hidden-only forms: "several forms ... pick one with --form".
|
||||||
|
12. The Core's admin: a new `coreapp new --sso` app, deployed, `coreapp
|
||||||
|
signin --cookies jar`: its page says "Signed in as coreapp.test ...
|
||||||
|
groups: none." (not admin). With `CORE_ADMIN_EMAIL` in its `.env` set
|
||||||
|
to the test account's address in other capitals, recreated: "..., the
|
||||||
|
app's admin." In a browser as `admin@<domain>`: "the app's admin".
|
||||||
|
|
||||||
### With mysql
|
### With mysql
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,7 @@ IMAGE_VERSION=@VERSION@
|
|||||||
APP_URL=https://{{NAME}}.@DOMAIN@
|
APP_URL=https://{{NAME}}.@DOMAIN@
|
||||||
# The Core's domain; set only on a Core, so an app can tell it runs on one
|
# The Core's domain; set only on a Core, so an app can tell it runs on one
|
||||||
CORE_DOMAIN=@DOMAIN@
|
CORE_DOMAIN=@DOMAIN@
|
||||||
|
# The Core's admin account: always an admin of the app, when signed in with
|
||||||
|
# the Core (needs "sso")
|
||||||
|
CORE_ADMIN_EMAIL=admin@@DOMAIN@
|
||||||
APP_SECRET=@APP_SECRET:RANDOM:LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL@
|
APP_SECRET=@APP_SECRET:RANDOM:LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL@
|
||||||
|
|||||||
+21
-7
@@ -54,6 +54,7 @@ What the Core gives every app:
|
|||||||
| `APP_SECRET` | 32 random letters and digits, for signing cookies, sessions |
|
| `APP_SECRET` | 32 random letters and digits, for signing cookies, sessions |
|
||||||
| `IMAGE_VERSION` | The installed version (`coreapp deploy` builds with plain `docker build .`, no build args, so read the version from here, not a build-time `VERSION`) |
|
| `IMAGE_VERSION` | The installed version (`coreapp deploy` builds with plain `docker build .`, no build args, so read the version from here, not a build-time `VERSION`) |
|
||||||
| `CORE_DOMAIN` | The Core's domain (`<domain>`). Set only on a Core: an app that also runs elsewhere can use it to tell |
|
| `CORE_DOMAIN` | The Core's domain (`<domain>`). Set only on a Core: an app that also runs elsewhere can use it to tell |
|
||||||
|
| `CORE_ADMIN_EMAIL` | `admin@<domain>`, the Core's admin account: always an admin of the app (see `sso`) |
|
||||||
|
|
||||||
`APP_SECRET` isn't hex or base64: an app that wants key bytes (e.g. 32
|
`APP_SECRET` isn't hex or base64: an app that wants key bytes (e.g. 32
|
||||||
bytes for encryption) derives them, e.g. SHA-256 of `APP_SECRET`. It
|
bytes for encryption) derives them, e.g. SHA-256 of `APP_SECRET`. It
|
||||||
@@ -187,10 +188,23 @@ may log; it should retry).
|
|||||||
today's Cores: they have two groups, `admins` and `everybody`, but
|
today's Cores: they have two groups, `admins` and `everybody`, but
|
||||||
Authelia's settings don't find them yet (for Federated to fix). Read `groups`
|
Authelia's settings don't find them yet (for Federated to fix). Read `groups`
|
||||||
if the app can use it, but don't depend on it for roles.
|
if the app can use it, but don't depend on it for roles.
|
||||||
- The app's first admin: not "whoever signs in first" (any employee could
|
- **The app's admin is the Core's admin.** On a Core, the account
|
||||||
be first). Prefer a one-time setup link or code the app prints in its log
|
`CORE_ADMIN_EMAIL` (`admin@<domain>`, the Core's own admin, as in
|
||||||
(`coreapp logs`, or `coreapp shell '<app's command>'`), then admins it
|
Federated's apps) is always an admin of the app, from its first sign-in:
|
||||||
names in its own settings. Later, the Core's `admins` group.
|
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 `email` in 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 in `oidc.py`. `coreapp signin`
|
||||||
|
signs in as the test account, not the admin, so ask the user to sign in
|
||||||
|
once as `admin@<domain>` in a browser and check it gets the admin pages.
|
||||||
- Discovery: `$OIDC_ISSUER/.well-known/openid-configuration`. The Core
|
- Discovery: `$OIDC_ISSUER/.well-known/openid-configuration`. The Core
|
||||||
routes `authelia.<domain>` from inside the app's container to the real
|
routes `authelia.<domain>` from inside the app's container to the real
|
||||||
HTTPS endpoint, with a valid certificate, so normal TLS verification works.
|
HTTPS endpoint, with a valid certificate, so normal TLS verification works.
|
||||||
@@ -377,9 +391,9 @@ 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,
|
Authelia bans an account for a few minutes after repeated failed sign-ins,
|
||||||
so don't loop on it.
|
so don't loop on it.
|
||||||
|
|
||||||
Still ask the user to sign in once in a browser with their own account
|
Still ask the user to sign in once in a browser before a release, as the
|
||||||
before a release: it checks what a script can't (the app's pages, and a
|
Core's admin (`admin@<domain>`): it checks what a script can't (the app's
|
||||||
real person's account).
|
pages, and that the admin gets the admin role).
|
||||||
|
|
||||||
### 4. When something fails
|
### 4. When something fails
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ keep its values and add new ones):
|
|||||||
| `APP_SECRET` | A random secret, for signing cookies and such |
|
| `APP_SECRET` | A random secret, for signing cookies and such |
|
||||||
| `IMAGE_VERSION` | The version that's installed |
|
| `IMAGE_VERSION` | The version that's installed |
|
||||||
| `CORE_DOMAIN` | The Core's domain (set only on a Core) |
|
| `CORE_DOMAIN` | The Core's domain (set only on a Core) |
|
||||||
|
| `CORE_ADMIN_EMAIL` | `admin@<domain>`, the Core's admin account: always an admin of the app, when it signs in with the Core |
|
||||||
|
|
||||||
`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); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
|
`DB_PASSWORD` (`needs = ["mysql"]` the same, for MariaDB); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
|
||||||
|
|||||||
@@ -88,9 +88,10 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
"SELECT count(*) FROM visits WHERE person = %s", (user["sub"],)
|
"SELECT count(*) FROM visits WHERE person = %s", (user["sub"],)
|
||||||
).fetchone()[0]
|
).fetchone()[0]
|
||||||
people = db.execute("SELECT count(DISTINCT person) FROM visits").fetchone()[0]
|
people = db.execute("SELECT count(DISTINCT person) FROM visits").fetchone()[0]
|
||||||
|
admin = ", the app's admin" if user.get("admin") else ""
|
||||||
self.page(
|
self.page(
|
||||||
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
|
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
|
||||||
f" ({html.escape(user['email'])}).</p>"
|
f" ({html.escape(user['email'])}){admin}.</p>"
|
||||||
f"<p>Your visits: <strong id=\"visits\">{mine}</strong>"
|
f"<p>Your visits: <strong id=\"visits\">{mine}</strong>"
|
||||||
f" (people who have visited: {people}), counted in PostgreSQL.</p>"
|
f" (people who have visited: {people}), counted in PostgreSQL.</p>"
|
||||||
'<p><a href="/logout">Sign out</a></p>'
|
'<p><a href="/logout">Sign out</a></p>'
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
user = oidc.read_session(self.cookie("session"))
|
user = oidc.read_session(self.cookie("session"))
|
||||||
if user:
|
if user:
|
||||||
groups = ", ".join(user.get("groups") or []) or "none"
|
groups = ", ".join(user.get("groups") or []) or "none"
|
||||||
|
admin = ", the app's admin" if user.get("admin") else ""
|
||||||
body = (
|
body = (
|
||||||
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
|
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
|
||||||
f" ({html.escape(user['email'])}), groups: {html.escape(groups)}.</p>"
|
f" ({html.escape(user['email'])}), groups: {html.escape(groups)}"
|
||||||
|
f"{admin}.</p>"
|
||||||
'<p><a href="/logout">Sign out</a></p>'
|
'<p><a href="/logout">Sign out</a></p>'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Authorization code flow with PKCE, and a signed session cookie. Settings
|
Authorization code flow with PKCE, and a signed session cookie. Settings
|
||||||
come from the environment (.env on the Core): APP_URL, APP_SECRET,
|
come from the environment (.env on the Core): APP_URL, APP_SECRET,
|
||||||
OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET.
|
OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET, CORE_ADMIN_EMAIL.
|
||||||
|
|
||||||
location, flow = start_login() # /login: redirect to Authelia
|
location, flow = start_login() # /login: redirect to Authelia
|
||||||
user = finish_login(query, flow) # /auth/callback: who signed in
|
user = finish_login(query, flow) # /auth/callback: who signed in
|
||||||
@@ -29,6 +29,9 @@ ISSUER = os.environ["OIDC_ISSUER"].rstrip("/")
|
|||||||
CLIENT_ID = os.environ["OIDC_CLIENT_ID"]
|
CLIENT_ID = os.environ["OIDC_CLIENT_ID"]
|
||||||
CLIENT_SECRET = os.environ["OIDC_CLIENT_SECRET"]
|
CLIENT_SECRET = os.environ["OIDC_CLIENT_SECRET"]
|
||||||
REDIRECT_URI = APP_URL + "/auth/callback"
|
REDIRECT_URI = APP_URL + "/auth/callback"
|
||||||
|
# The Core's admin account (admin@<domain>) is always the app's admin. Only
|
||||||
|
# trusted here, from the Core's sign-in: never from an address someone types
|
||||||
|
CORE_ADMIN_EMAIL = os.environ.get("CORE_ADMIN_EMAIL", "").lower()
|
||||||
SESSION_SECONDS = 3600
|
SESSION_SECONDS = 3600
|
||||||
FLOW_SECONDS = 600
|
FLOW_SECONDS = 600
|
||||||
|
|
||||||
@@ -100,7 +103,8 @@ def start_login():
|
|||||||
|
|
||||||
|
|
||||||
def finish_login(query, flow_cookie):
|
def finish_login(query, flow_cookie):
|
||||||
"""Who signed in: {sub, name, email, groups}, from Authelia's answer."""
|
"""Who signed in: {sub, name, email, groups, admin}, from Authelia's
|
||||||
|
answer."""
|
||||||
flow = unsign(flow_cookie)
|
flow = unsign(flow_cookie)
|
||||||
if not flow or not hmac.compare_digest(flow["state"], query.get("state", "")):
|
if not flow or not hmac.compare_digest(flow["state"], query.get("state", "")):
|
||||||
raise SignInError("The sign-in expired or didn't start here. Try again.")
|
raise SignInError("The sign-in expired or didn't start here. Try again.")
|
||||||
@@ -132,6 +136,7 @@ def finish_login(query, flow_cookie):
|
|||||||
"name": info.get("name") or info.get("preferred_username") or info["sub"],
|
"name": info.get("name") or info.get("preferred_username") or info["sub"],
|
||||||
"email": info.get("email", ""),
|
"email": info.get("email", ""),
|
||||||
"groups": info.get("groups", []),
|
"groups": info.get("groups", []),
|
||||||
|
"admin": bool(CORE_ADMIN_EMAIL) and info.get("email", "").lower() == CORE_ADMIN_EMAIL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user