Compare commits
1 Commits
main
..
323e2038b6
| Author | SHA1 | Date | |
|---|---|---|---|
| 323e2038b6 |
+2
-15
@@ -12,12 +12,6 @@ The host's contract version is now 0.5.0, so discovery refuses a plugin whose `a
|
|||||||
`0.4.x`. Change the literal in each plugin's manifest when you upgrade, and add `assetHref` to any
|
`0.4.x`. Change the literal in each plugin's manifest when you upgrade, and add `assetHref` to any
|
||||||
`RequestContext` your tests build by hand: `assetHref: (href) => href`.
|
`RequestContext` your tests build by hand: `assetHref: (href) => href`.
|
||||||
|
|
||||||
### `@plainpages/plugin-api` exports `KetoError`
|
|
||||||
|
|
||||||
A plugin that calls `ctx.system.keto` can tell a Keto failure from any other error with
|
|
||||||
`instanceof KetoError`, as it already can a `KratosError` or a `HydraError`. The error carries the HTTP
|
|
||||||
`status`. It adds to the plugin API, so an installed plugin needs no change.
|
|
||||||
|
|
||||||
### The core dashboard view is `dashboard`, not `index`
|
### The core dashboard view is `dashboard`, not `index`
|
||||||
|
|
||||||
`views/index.ejs` is now `views/dashboard.ejs`. The `apiVersion` check can't see this: a plugin view
|
`views/index.ejs` is now `views/dashboard.ejs`. The `apiVersion` check can't see this: a plugin view
|
||||||
@@ -40,15 +34,8 @@ and answers with the error page. It used to leave some grants gone and the membe
|
|||||||
|
|
||||||
Deleting a group now also removes it from every group it was a member of, in the same Keto
|
Deleting a group now also removes it from every group it was a member of, in the same Keto
|
||||||
transaction as the rest. It used to stay listed there, so a group re-created with the same name was
|
transaction as the rest. It used to stay listed there, so a group re-created with the same name was
|
||||||
back in every parent.
|
back in every parent. A parent whose only member was the deleted group is left with no members, and
|
||||||
|
so no longer exists as a group.
|
||||||
### The admin example removes a group's grants and parent memberships when its last member leaves
|
|
||||||
|
|
||||||
A group with no members no longer exists, and now neither do its grants or its memberships in other
|
|
||||||
groups. This holds when the last member is removed, and the group page then says so. It also holds
|
|
||||||
when deleting a group leaves its parent with no members, and so on up through each ancestor left
|
|
||||||
empty. A group re-created with the same name used to get the old group's permissions and parents back.
|
|
||||||
Groups already left empty by an earlier version keep theirs, and re-creating one still restores them.
|
|
||||||
|
|
||||||
### The admin example keeps a user's permissions section when it refuses a self-deactivate or self-delete
|
### The admin example keeps a user's permissions section when it refuses a self-deactivate or self-delete
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ services:
|
|||||||
# Dev mail catcher — Kratos recovery/verification emails land here (web UI on 8025).
|
# Dev mail catcher — Kratos recovery/verification emails land here (web UI on 8025).
|
||||||
# kratos.yml points the courier at smtp://mailpit:1025; prod uses a real SMTP via env.
|
# kratos.yml points the courier at smtp://mailpit:1025; prod uses a real SMTP via env.
|
||||||
mailpit:
|
mailpit:
|
||||||
image: axllent/mailpit:v1.34.0
|
image: axllent/mailpit:v1.33.1
|
||||||
ports:
|
ports:
|
||||||
- "8025:8025"
|
- "8025:8025"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -581,20 +581,3 @@ Read most (opens and searches):
|
|||||||
- `src/function-limits.test.ts` 2
|
- `src/function-limits.test.ts` 2
|
||||||
- `AGENTS.md` 1
|
- `AGENTS.md` 1
|
||||||
- `CHANGELOG.md` 1
|
- `CHANGELOG.md` 1
|
||||||
|
|
||||||
## Reading cost, chunk f1bfd1c341a4, finished 2026-11-09T00:42:43Z
|
|
||||||
|
|
||||||
84281 new input tokens before the first commit.
|
|
||||||
|
|
||||||
Read most (opens and searches):
|
|
||||||
|
|
||||||
- `todo.md` 9
|
|
||||||
- `README.md` 5
|
|
||||||
- `examples/plugins/auth-admin/admin-groups.ts` 5
|
|
||||||
- `examples/plugins/auth-admin/admin-shared.ts` 5
|
|
||||||
- `src/auth/keto-client.ts` 5
|
|
||||||
- `AGENTS.md` 3
|
|
||||||
- `examples/plugins/auth-admin/admin-users.ts` 3
|
|
||||||
- `src/auth/hydra-admin.ts` 3
|
|
||||||
- `src/http/app-admin.test.ts` 3
|
|
||||||
- `CHANGELOG.md` 2
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ services:
|
|||||||
|
|
||||||
# Catches the courier's mail (kratos.yml → smtp://mailpit:1025), so a test can read an emailed code.
|
# Catches the courier's mail (kratos.yml → smtp://mailpit:1025), so a test can read an emailed code.
|
||||||
mailpit:
|
mailpit:
|
||||||
image: axllent/mailpit:v1.34.0
|
image: axllent/mailpit:v1.33.1
|
||||||
mem_limit: 128m
|
mem_limit: 128m
|
||||||
memswap_limit: 128m
|
memswap_limit: 128m
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// Groups admin screen: list / create / delete Keto groups and manage membership.
|
// Groups admin screen: list / create / delete Keto groups and manage membership.
|
||||||
// A group is a Keto subject set `Group:<name>#members`; a member is a user or a nested group (see
|
// A group is a Keto subject set `Group:<name>#members`; a member is a user or a nested group (see
|
||||||
// parseSubject). Writes go only to Keto (README "stateless"). Keto has no "create object": a group
|
// parseSubject). Writes go only to Keto (README "stateless"). Keto has no "create object" — a group
|
||||||
// exists exactly while it has ≥1 member, so create writes its first-member tuple, and removing the
|
// exists exactly while it has ≥1 member, so create writes its first-member tuple and delete removes
|
||||||
// last member deletes the group (see `withEmptiedGroups`).
|
// every tuple that makes it a group or puts it in another. Pure builders turn tuples + the request URL into view models; below them are thin
|
||||||
// Pure builders turn tuples + the request URL into view models; below them are thin
|
|
||||||
// per-route handlers (keyed on ctx.params) over a shared `withGroups` gate — admin-only, CSRF-guarded,
|
// per-route handlers (keyed on ctx.params) over a shared `withGroups` gate — admin-only, CSRF-guarded,
|
||||||
// each returning a RouteResult.
|
// each returning a RouteResult.
|
||||||
|
|
||||||
@@ -370,7 +369,7 @@ async function groupDetailPage({ ctx, keto, kratosAdmin }: GroupsDeps, name: str
|
|||||||
|
|
||||||
// GET /auth-admin/groups/:name — the detail + membership page.
|
// GET /auth-admin/groups/:name — the detail + membership page.
|
||||||
export const groupsDetail = withGroupName((deps, name) =>
|
export const groupsDetail = withGroupName((deps, name) =>
|
||||||
groupDetailPage(deps, name, { notice: grantsNotice(deps.ctx.url, deps.ctx.t) ?? emptiedNotice(deps.ctx.url, deps.ctx.t) ?? "" }));
|
groupDetailPage(deps, name, { notice: grantsNotice(deps.ctx.url, deps.ctx.t) ?? "" }));
|
||||||
|
|
||||||
// POST /auth-admin/groups/:name/permissions — the submitted checkboxes are the desired set. Members hold
|
// POST /auth-admin/groups/:name/permissions — the submitted checkboxes are the desired set. Members hold
|
||||||
// a group's permissions transitively, so the change reaches them at their next login or re-mint —
|
// a group's permissions transitively, so the change reaches them at their next login or re-mint —
|
||||||
@@ -420,56 +419,26 @@ export const groupsDeleteConfirm = withGroupName(async (deps, name) => {
|
|||||||
}) }, view: "confirm" };
|
}) }, view: "confirm" };
|
||||||
}, "write");
|
}, "write");
|
||||||
|
|
||||||
const EMPTIED_NOTICE = "group-emptied"; // the `info-msg` that removing a group's last member redirects with
|
// POST /auth-admin/groups/:name/delete — one Keto transaction removes the group's member tuples,
|
||||||
const emptiedNotice = (url: URL, t: Translate): string | undefined =>
|
// the tuples naming it as a member of a parent group, and the grants it holds, so a Keto failure
|
||||||
url.searchParams.get("info-msg") === EMPTIED_NOTICE ? t("admin.groups.emptied") : undefined;
|
// leaves the group as it was.
|
||||||
|
|
||||||
const tupleId = (t: RelationTuple): string => {
|
|
||||||
const subject = t.subject_set ? `${t.subject_set.namespace}:${t.subject_set.object}#${t.subject_set.relation}` : t.subject_id;
|
|
||||||
return `${t.namespace}:${t.object}#${t.relation}@${subject}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
// A group exists only through its members. Once `removing` leaves one of `groups` with none, the
|
|
||||||
// grants on its name and its memberships in other groups must go too, or re-creating the name would
|
|
||||||
// restore them. Emptying a group can empty its parents, so the walk climbs from each emptied group to
|
|
||||||
// the groups it is in, and a group left with a member ends that branch. Returns every tuple to delete
|
|
||||||
// (`removing` and those) and the emptied groups. A member added by another admin between these reads
|
|
||||||
// and the transaction lands in a stripped group: Keto has no conditional write.
|
|
||||||
async function withEmptiedGroups(keto: KetoClient, removing: readonly RelationTuple[], groups: readonly string[]): Promise<{ delete: RelationTuple[]; emptied: string[] }> {
|
|
||||||
const doomed = new Map(removing.map((t) => [tupleId(t), t]));
|
|
||||||
const pending = [...groups];
|
|
||||||
const emptied = new Set<string>(); // also ends the walk on a nesting cycle
|
|
||||||
for (let group = pending.pop(); group !== undefined; group = pending.pop()) {
|
|
||||||
if (emptied.has(group)) continue;
|
|
||||||
const members = await pagedTuples(keto, { namespace: GROUP_NS, object: group, relation: MEMBERS });
|
|
||||||
if (members.some((m) => !doomed.has(tupleId(m)))) continue; // may be reached again, by a sibling emptied later
|
|
||||||
emptied.add(group);
|
|
||||||
const subject = groupSubject(group);
|
|
||||||
const grants = (await heldPermissions(keto, subject)).map((permission) => grantTuple(permission, subject));
|
|
||||||
const inParents = await pagedTuples(keto, { namespace: GROUP_NS, relation: MEMBERS, ...subject });
|
|
||||||
for (const t of [...grants, ...inParents]) doomed.set(tupleId(t), t);
|
|
||||||
pending.push(...inParents.map((t) => t.object));
|
|
||||||
}
|
|
||||||
return { delete: [...doomed.values()], emptied: [...emptied] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logged with the groups that lost their grants, since the screen doesn't list them.
|
|
||||||
function logEmptied(deps: GroupsDeps, event: string, name: string, cascade: { delete: RelationTuple[]; emptied: string[] }): void {
|
|
||||||
const revoked = new Set(cascade.delete.filter((t) => t.namespace !== GROUP_NS).map((t) => t.object));
|
|
||||||
deps.ctx.log.info(event, { actor: deps.user.id, emptied: cascade.emptied.join(","), group: name, revoked: [...revoked].sort().join(",") });
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST /auth-admin/groups/:name/delete — one Keto transaction removes the group's member tuples and
|
|
||||||
// everything `withEmptiedGroups` finds, so a Keto failure leaves the group as it was.
|
|
||||||
export const groupsDelete = withGroupName(async (deps, name) => {
|
export const groupsDelete = withGroupName(async (deps, name) => {
|
||||||
const { ctx, keto } = deps;
|
const { ctx, keto, user } = deps;
|
||||||
await guardedForm(ctx); // CSRF-verify the POST
|
await guardedForm(ctx); // CSRF-verify the POST
|
||||||
const lost = await lostOnDelete(deps, name);
|
const lost = await lostOnDelete(deps, name);
|
||||||
if (lost.length > 0) return refuseSelfLockout(deps, name, "delete", lost);
|
if (lost.length > 0) return refuseSelfLockout(deps, name, "delete", lost);
|
||||||
|
// A Keto set exists only through its tuples, so leaving the grants or the parents' membership
|
||||||
|
// tuples behind would resurrect every permission and parent membership the moment someone
|
||||||
|
// re-created a group with the same name. A parent that had only this group as a member is left
|
||||||
|
// with none and so ceases to exist, as when its last member is removed by hand; its own grants
|
||||||
|
// and parent memberships stay (todo.md).
|
||||||
|
const subject = groupSubject(name);
|
||||||
|
const held = await heldPermissions(keto, subject);
|
||||||
|
const grants = held.map((permission) => grantTuple(permission, subject));
|
||||||
const members = await pagedTuples(keto, { namespace: GROUP_NS, object: name, relation: MEMBERS });
|
const members = await pagedTuples(keto, { namespace: GROUP_NS, object: name, relation: MEMBERS });
|
||||||
const cascade = await withEmptiedGroups(keto, members, [name]);
|
const inParents = await pagedTuples(keto, { namespace: GROUP_NS, relation: MEMBERS, ...subject });
|
||||||
await keto.transactTuples({ delete: cascade.delete, insert: [] });
|
await keto.transactTuples({ delete: [...grants, ...members, ...inParents], insert: [] });
|
||||||
logEmptied(deps, "admin: group deleted", name, cascade);
|
ctx.log.info("admin: group deleted", { actor: user.id, group: name, revoked: held.join(",") });
|
||||||
return { redirect: ADMIN_GROUPS_BASE };
|
return { redirect: ADMIN_GROUPS_BASE };
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -483,9 +452,6 @@ export const groupsRemoveMember = withGroupName(async (deps, name) => {
|
|||||||
const removesSelf = tuple.subject_set ? await isMember(keto, user.id, tuple.subject_set.object) : tuple.subject_id === `user:${user.id}`;
|
const removesSelf = tuple.subject_set ? await isMember(keto, user.id, tuple.subject_set.object) : tuple.subject_id === `user:${user.id}`;
|
||||||
const lost = removesSelf ? await lostOnLeaving(deps, name) : [];
|
const lost = removesSelf ? await lostOnLeaving(deps, name) : [];
|
||||||
if (lost.length > 0) return refuseSelfLockout(deps, name, "remove", lost);
|
if (lost.length > 0) return refuseSelfLockout(deps, name, "remove", lost);
|
||||||
const cascade = await withEmptiedGroups(keto, [tuple], [name]);
|
await keto.deleteTuple(tuple);
|
||||||
await keto.transactTuples({ delete: cascade.delete, insert: [] });
|
return { redirect: detailHref(name) };
|
||||||
if (cascade.emptied.length === 0) return { redirect: detailHref(name) };
|
|
||||||
logEmptied(deps, "admin: last group member removed", name, cascade);
|
|
||||||
return { redirect: `${detailHref(name)}?info-msg=${EMPTIED_NOTICE}` };
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ const messages = {
|
|||||||
"admin.groups.create": "Create group",
|
"admin.groups.create": "Create group",
|
||||||
"admin.groups.delete": "Delete group",
|
"admin.groups.delete": "Delete group",
|
||||||
"admin.groups.deleteMessage": "Delete group {{name}}? This can't be undone.",
|
"admin.groups.deleteMessage": "Delete group {{name}}? This can't be undone.",
|
||||||
"admin.groups.emptied": "That was the last member, so the group no longer exists and its permissions and parent groups are removed.",
|
|
||||||
"admin.groups.error.duplicate": "A group with that name already exists.",
|
"admin.groups.error.duplicate": "A group with that name already exists.",
|
||||||
"admin.groups.error.selfLockout": "This change would lock you out of {{permissions}}, which you hold through this group. Ask another administrator to make it.",
|
"admin.groups.error.selfLockout": "This change would lock you out of {{permissions}}, which you hold through this group. Ask another administrator to make it.",
|
||||||
"admin.groups.field.name": "Group name",
|
"admin.groups.field.name": "Group name",
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ const messages: AdminMessages = {
|
|||||||
"admin.groups.create": "Skapa grupp",
|
"admin.groups.create": "Skapa grupp",
|
||||||
"admin.groups.delete": "Radera grupp",
|
"admin.groups.delete": "Radera grupp",
|
||||||
"admin.groups.deleteMessage": "Ta bort gruppen {{name}}? Det går inte att ångra.",
|
"admin.groups.deleteMessage": "Ta bort gruppen {{name}}? Det går inte att ångra.",
|
||||||
"admin.groups.emptied": "Det var den sista medlemmen, så gruppen finns inte längre och dess behörigheter och föräldragrupper är borttagna.",
|
|
||||||
"admin.groups.error.duplicate": "Det finns redan en grupp med det namnet.",
|
"admin.groups.error.duplicate": "Det finns redan en grupp med det namnet.",
|
||||||
"admin.groups.error.selfLockout": "Ändringen skulle låsa ute dig från {{permissions}}, som du har genom den här gruppen. Be en annan administratör att göra den.",
|
"admin.groups.error.selfLockout": "Ändringen skulle låsa ute dig från {{permissions}}, som du har genom den här gruppen. Be en annan administratör att göra den.",
|
||||||
"admin.groups.field.name": "Gruppnamn",
|
"admin.groups.field.name": "Gruppnamn",
|
||||||
|
|||||||
Generated
+8
-8
@@ -8,11 +8,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@larvit/log": "2.6.1",
|
"@larvit/log": "2.6.1",
|
||||||
"ejs": "7.0.2",
|
"ejs": "7.0.2",
|
||||||
"lucide-static": "1.77.0",
|
"lucide-static": "1.70.0",
|
||||||
"postgres": "4.1.1"
|
"postgres": "4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mdn/browser-compat-data": "8.1.10",
|
"@mdn/browser-compat-data": "8.1.9",
|
||||||
"@types/ejs": "3.1.5",
|
"@types/ejs": "3.1.5",
|
||||||
"@types/node": "26.6.6",
|
"@types/node": "26.6.6",
|
||||||
"acorn": "8.19.0",
|
"acorn": "8.19.0",
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mdn/browser-compat-data": {
|
"node_modules/@mdn/browser-compat-data": {
|
||||||
"version": "8.1.10",
|
"version": "8.1.9",
|
||||||
"resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-8.1.10.tgz",
|
"resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-8.1.9.tgz",
|
||||||
"integrity": "sha512-hz+rLSYXWOcBI8OF+xMzVpA1vxbtYbYSPLPiw/IhKMTiKL7L5+YuyGDPr+QKhnRsgYERxvi4MYc0J74JTakD7A==",
|
"integrity": "sha512-7d8D9yzVS4ugLbt4clzc5DKU8dq85K0lRebjzpP43GxSr7vYKmczgfuEU+0beimjl5YmnHkcErtolg5t5ttb0A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "CC0-1.0"
|
"license": "CC0-1.0"
|
||||||
},
|
},
|
||||||
@@ -421,9 +421,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lucide-static": {
|
"node_modules/lucide-static": {
|
||||||
"version": "1.77.0",
|
"version": "1.70.0",
|
||||||
"resolved": "https://registry.npmjs.org/lucide-static/-/lucide-static-1.77.0.tgz",
|
"resolved": "https://registry.npmjs.org/lucide-static/-/lucide-static-1.70.0.tgz",
|
||||||
"integrity": "sha512-v+BzpQrjlwDRWPDzzAu5IFhOkI6jVKb91fsjw1ZSS7Tsb2YvRX5olRN0DXGW99LF2wV4fycuTf5aPOMC62ZW0g==",
|
"integrity": "sha512-A9UgY98g94IuHQY7rl7/AFwHX7T1qNpzryim+Kw5CGhdV2STobtBY+ib/Z44ohyqXEJB88gvXFAeJ87uOOHKLw==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/postgres": {
|
"node_modules/postgres": {
|
||||||
|
|||||||
+2
-2
@@ -18,11 +18,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@larvit/log": "2.6.1",
|
"@larvit/log": "2.6.1",
|
||||||
"ejs": "7.0.2",
|
"ejs": "7.0.2",
|
||||||
"lucide-static": "1.77.0",
|
"lucide-static": "1.70.0",
|
||||||
"postgres": "4.1.1"
|
"postgres": "4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@mdn/browser-compat-data": "8.1.10",
|
"@mdn/browser-compat-data": "8.1.9",
|
||||||
"@types/ejs": "3.1.5",
|
"@types/ejs": "3.1.5",
|
||||||
"@types/node": "26.6.6",
|
"@types/node": "26.6.6",
|
||||||
"acorn": "8.19.0",
|
"acorn": "8.19.0",
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ services:
|
|||||||
|
|
||||||
# Catches Kratos' recovery/verification emails — UI on http://localhost:8025
|
# Catches Kratos' recovery/verification emails — UI on http://localhost:8025
|
||||||
mailpit:
|
mailpit:
|
||||||
image: axllent/mailpit:v1.34.0
|
image: axllent/mailpit:v1.33.1
|
||||||
ports:
|
ports:
|
||||||
- "8025:8025"
|
- "8025:8025"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -446,112 +446,6 @@ test("admin group delete: removes the group from every parent, so re-creating th
|
|||||||
assert.deepEqual(tuples, [member("org", { subject_id: `user:${ada}` }), member("staff", { subject_id: "user:other" })]);
|
assert.deepEqual(tuples, [member("org", { subject_id: `user:${ada}` }), member("staff", { subject_id: "user:other" })]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tuples a group keeps after it loses its last member would be restored by re-creating its name.
|
|
||||||
const ADA = randomUUID();
|
|
||||||
const groupTuple = (object: string, subject: Partial<RelationTuple>): RelationTuple => ({ namespace: "Group", object, relation: "members", ...subject } as RelationTuple);
|
|
||||||
const inGroup = (object: string) => ({ subject_set: { namespace: "Group", object, relation: "members" } });
|
|
||||||
const grantTo = (group: string, permission = "users:read"): RelationTuple => ({ namespace: "Permission", object: permission, relation: "granted", ...inGroup(group) });
|
|
||||||
const groupsAdminHarness = (t: TestContext, tuples: RelationTuple[]) => adminHarness(t, { keto: fakeKeto(tuples), kratosAdmin: stubAdmin({}) });
|
|
||||||
|
|
||||||
test("admin group delete: a parent left with no members loses its grants and memberships, all the way up", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("eng", { subject_id: `user:${ADA}` }),
|
|
||||||
groupTuple("org", inGroup("eng")), grantTo("org"),
|
|
||||||
groupTuple("company", inGroup("org")), grantTo("company", "users:write"),
|
|
||||||
groupTuple("everyone", inGroup("company")), groupTuple("everyone", { subject_id: "user:other" }), grantTo("everyone", "groups:read"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
assert.equal((await post("/auth-admin/groups/eng/delete", `_csrf=${token}`)).status, 303);
|
|
||||||
assert.deepEqual(tuples, [groupTuple("everyone", { subject_id: "user:other" }), grantTo("everyone", "groups:read")]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group delete: a nesting cycle ends the cascade at a group that keeps a member", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("a", { subject_id: `user:${ADA}` }), groupTuple("a", inGroup("b")),
|
|
||||||
groupTuple("b", inGroup("a")), grantTo("b"),
|
|
||||||
groupTuple("c", inGroup("b")), groupTuple("c", { subject_id: "user:other" }), grantTo("c", "groups:read"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
assert.equal((await post("/auth-admin/groups/a/delete", `_csrf=${token}`)).status, 303);
|
|
||||||
assert.deepEqual(tuples, [groupTuple("c", { subject_id: "user:other" }), grantTo("c", "groups:read")]);
|
|
||||||
});
|
|
||||||
|
|
||||||
// The walk reaches `a` a second time, through the cycle, while `p` still waits: it must go on to `p`.
|
|
||||||
// Keto lists `p@b` before `a@b`, so `a` is popped before `p`.
|
|
||||||
test("admin group delete: a nesting cycle back to an emptied group doesn't end the cascade", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("a", { subject_id: `user:${ADA}` }), groupTuple("p", inGroup("b")), groupTuple("a", inGroup("b")),
|
|
||||||
groupTuple("b", inGroup("a")), grantTo("p"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
assert.equal((await post("/auth-admin/groups/a/delete", `_csrf=${token}`)).status, 303);
|
|
||||||
assert.deepEqual(tuples, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group delete: a diamond of nested groups empties the top once both its members are gone", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("eng", { subject_id: `user:${ADA}` }),
|
|
||||||
groupTuple("left", inGroup("eng")), groupTuple("right", inGroup("eng")),
|
|
||||||
groupTuple("top", inGroup("left")), groupTuple("top", inGroup("right")), grantTo("top"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
assert.equal((await post("/auth-admin/groups/eng/delete", `_csrf=${token}`)).status, 303);
|
|
||||||
assert.deepEqual(tuples, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group member removal: the last member leaving takes the group's grants and parent memberships with it", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("eng", { subject_id: `user:${ADA}` }), grantTo("eng"),
|
|
||||||
groupTuple("org", inGroup("eng")), groupTuple("org", { subject_id: "user:other" }),
|
|
||||||
groupTuple("solo", inGroup("org")), grantTo("solo", "users:write"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
const res = await post("/auth-admin/groups/eng/members/delete", `_csrf=${token}&member=user:${ADA}`);
|
|
||||||
assert.equal(res.headers.get("location"), "/auth-admin/groups/eng?info-msg=group-emptied");
|
|
||||||
assert.deepEqual(tuples, [groupTuple("org", { subject_id: "user:other" }), groupTuple("solo", inGroup("org")), grantTo("solo", "users:write")]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group member removal: removing someone who isn't a member changes nothing", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [groupTuple("eng", { subject_id: `user:${ADA}` }), grantTo("eng")];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
const res = await post("/auth-admin/groups/eng/members/delete", `_csrf=${token}&member=user:${randomUUID()}`);
|
|
||||||
assert.equal(res.headers.get("location"), "/auth-admin/groups/eng");
|
|
||||||
assert.equal(tuples.length, 2);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group member removal: a group that keeps a member keeps its grants and parents", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [groupTuple("eng", { subject_id: `user:${ADA}` }), groupTuple("eng", { subject_id: "user:bob" }), grantTo("eng"), groupTuple("org", inGroup("eng"))];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
const res = await post("/auth-admin/groups/eng/members/delete", `_csrf=${token}&member=user:${ADA}`);
|
|
||||||
assert.equal(res.headers.get("location"), "/auth-admin/groups/eng");
|
|
||||||
assert.equal(tuples.length, 3);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group member removal: a parent that keeps another nested group keeps its grants", async (t) => {
|
|
||||||
const tuples: RelationTuple[] = [
|
|
||||||
groupTuple("eng", { subject_id: `user:${ADA}` }),
|
|
||||||
groupTuple("left", inGroup("eng")), groupTuple("right", { subject_id: "user:other" }),
|
|
||||||
groupTuple("top", inGroup("left")), groupTuple("top", inGroup("right")), grantTo("top"),
|
|
||||||
];
|
|
||||||
const { post, token } = await groupsAdminHarness(t, tuples);
|
|
||||||
|
|
||||||
await post("/auth-admin/groups/eng/members/delete", `_csrf=${token}&member=user:${ADA}`);
|
|
||||||
assert.deepEqual(tuples, [groupTuple("right", { subject_id: "user:other" }), groupTuple("top", inGroup("right")), grantTo("top")]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("admin group member removal: the group page shows the notice that the group is gone", async (t) => {
|
|
||||||
const { get } = await groupsAdminHarness(t, []);
|
|
||||||
|
|
||||||
assert.match(await (await get("/auth-admin/groups/eng?info-msg=group-emptied")).text(), /That was the last member/);
|
|
||||||
});
|
|
||||||
|
|
||||||
// A double-clicked Save posts twice from one page; the second post finds the first one's result.
|
// A double-clicked Save posts twice from one page; the second post finds the first one's result.
|
||||||
// A save that changes nothing has nothing to refuse and nothing to revoke.
|
// A save that changes nothing has nothing to refuse and nothing to revoke.
|
||||||
test("admin permission grants: a save that changes nothing is not refused for a stale page and leaves live tokens alone", async (t) => {
|
test("admin permission grants: a save that changes nothing is not refused for a stale page and leaves live tokens alone", async (t) => {
|
||||||
|
|||||||
@@ -22,10 +22,3 @@ test("plugin-api re-exports the stable author value surface", () => {
|
|||||||
assert.equal(api.safeUrl("javascript:alert(1)"), "#"); // the URL sanitiser for rendering untrusted hrefs
|
assert.equal(api.safeUrl("javascript:alert(1)"), "#"); // the URL sanitiser for rendering untrusted hrefs
|
||||||
assert.equal(api.definePlugin({ apiVersion: "1.0.0" }).apiVersion, "1.0.0"); // identity helper works through the barrel
|
assert.equal(api.definePlugin({ apiVersion: "1.0.0" }).apiVersion, "1.0.0"); // identity helper works through the barrel
|
||||||
});
|
});
|
||||||
|
|
||||||
// A plugin matches a Keto failure with `instanceof`, so the barrel must export the class `ctx.system.keto` throws.
|
|
||||||
test("plugin-api re-exports the KetoError class the Keto client throws", async () => {
|
|
||||||
const { KetoError } = await import("../auth/keto-client.ts");
|
|
||||||
|
|
||||||
assert.equal(api.KetoError, KetoError);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export type { ExpandTree, KetoClient, RelationQuery, RelationTuple, SubjectSet }
|
|||||||
export type { HydraAdmin, OAuth2Client } from "../auth/hydra-admin.ts";
|
export type { HydraAdmin, OAuth2Client } from "../auth/hydra-admin.ts";
|
||||||
export { KratosError } from "../auth/kratos-public.ts";
|
export { KratosError } from "../auth/kratos-public.ts";
|
||||||
export { HydraError } from "../auth/hydra-admin.ts";
|
export { HydraError } from "../auth/hydra-admin.ts";
|
||||||
export { KetoError } from "../auth/keto-client.ts";
|
|
||||||
// Sanitise an untrusted URL (upstream/user data) before rendering it in an href/src — partials
|
// Sanitise an untrusted URL (upstream/user data) before rendering it in an href/src — partials
|
||||||
// escape text but not URL schemes, so a `javascript:`/`data:` URL would be live XSS (see docs).
|
// escape text but not URL schemes, so a `javascript:`/`data:` URL would be live XSS (see docs).
|
||||||
export { safeUrl } from "../http/safe-url.ts";
|
export { safeUrl } from "../http/safe-url.ts";
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|
||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||
|
| 65 | 0.6.0 | | | **Export `KetoError` from `@plainpages/plugin-api`, so a plugin can tell a Keto failure apart with `instanceof`.** | 1 | 2 | 1 | 2 | 1 | 7 by 3, 1 by 1 | 6.7 |
|
||||||
|
| 72 | 0.6.0 | | | **Delete a group's grants and parent memberships when its last member leaves, by group delete or by removing the member, so re-creating the name restores none.** | 2 | 2 | 2 | 4 | 3 | 2 by 4 | 4.2 |
|
||||||
| 14 | 0.6.0 | | | **Drop a double-clicked duplicate submit, with no client-side JavaScript.** | 4 | 2 | 3 | 7 | 7 | 2 by 7, 1 by 4 | 1.4 |
|
| 14 | 0.6.0 | | | **Drop a double-clicked duplicate submit, with no client-side JavaScript.** | 4 | 2 | 3 | 7 | 7 | 2 by 7, 1 by 4 | 1.4 |
|
||||||
| 67 | 0.6.0 | | | **Group `src/auth`'s modules into one subfolder per concern, with `bootstrap.ts` staying at `src/auth/bootstrap.ts`.** | 3 | 1 | 2 | 4 | 6 | code health by 4 | 1.0 |
|
| 67 | 0.6.0 | | | **Group `src/auth`'s modules into one subfolder per concern, with `bootstrap.ts` staying at `src/auth/bootstrap.ts`.** | 3 | 1 | 2 | 4 | 6 | code health by 4 | 1.0 |
|
||||||
| 19 | 0.7.0 | | question | **Run the documented Docker commands on macOS and fix whatever misbehaves.** | 2 | 2 | 1 | 3 | 3 | 1 by 3 | 3.3 |
|
| 19 | 0.7.0 | | question | **Run the documented Docker commands on macOS and fix whatever misbehaves.** | 2 | 2 | 1 | 3 | 3 | 1 by 3 | 3.3 |
|
||||||
@@ -24,6 +26,47 @@
|
|||||||
|
|
||||||
## Details
|
## Details
|
||||||
|
|
||||||
|
### 65. Export `KetoError` from `@plainpages/plugin-api`, so a plugin can tell a Keto failure apart with `instanceof`.
|
||||||
|
|
||||||
|
`src/plugin-host/plugin-api.ts` ~L47-48 exports `KratosError` and `HydraError`, but not `KetoError`
|
||||||
|
(`src/auth/keto-client.ts:43`), though `ctx.system.keto` throws it. The barrel is the contract
|
||||||
|
surface, so this adds to the plugin API: it ships in a minor, and `HOST_API_VERSION` must read
|
||||||
|
`0.6.0` when 0.6.0 is tagged (AGENTS.md → Rules). Adding is safe for installed plugins; removing it
|
||||||
|
later would take a major.
|
||||||
|
|
||||||
|
Touches:
|
||||||
|
|
||||||
|
- `src/plugin-host/plugin-api.ts`: the `export { KratosError }` and `export { HydraError }` lines (small)
|
||||||
|
- `src/plugin-host/plugin.ts`: `HOST_API_VERSION` (small)
|
||||||
|
- `src/plugin-host/plugin-api.test.ts`: the barrel's export test (small)
|
||||||
|
|
||||||
|
### 72. Delete a group's grants and parent memberships when its last member leaves, by group delete or by removing the member, so re-creating the name restores none.
|
||||||
|
|
||||||
|
In `examples/plugins/auth-admin/admin-groups.ts` a group exists exactly while it has a
|
||||||
|
`Group:<name>#members` tuple. Two paths empty a group but keep its other tuples, so re-creating the
|
||||||
|
name silently hands every new member the old permissions and parent memberships:
|
||||||
|
|
||||||
|
1. `groupsDelete` of a group that is a parent's only member: the parent ceases to exist but keeps
|
||||||
|
its `Permission:*#granted@Group:<parent>#members` grants and its memberships in grandparents.
|
||||||
|
2. `groupsRemoveMember` removing a group's last member, which today is a lone `deleteTuple`.
|
||||||
|
|
||||||
|
Fix both in one `transactTuples` with the removal: when the removal leaves a group with no members,
|
||||||
|
add its grants and the tuples naming it as a member of other groups to the delete. The cascade is
|
||||||
|
transitive: a grandparent emptied by its parent vanishing is the same bug one level up. The walk
|
||||||
|
stops at a group that keeps any member, so a nesting cycle (`groupsAddMember` refuses only a
|
||||||
|
self-nest) ends it. An emptied group grants nobody, so the cascade cannot change what
|
||||||
|
`lostToSelf` computes. Test it with nesting two levels deep and with a cycle.
|
||||||
|
|
||||||
|
When it ships, rewrite the comment at `groupsDelete` that points here, and the CHANGELOG entry "The
|
||||||
|
admin example removes a deleted group from the groups it was nested in", which then says a parent
|
||||||
|
left with no members no longer exists as a group. `lostToSelf`, in this file, is a place the seats
|
||||||
|
found hard; if the change touches it, make it easier to read.
|
||||||
|
|
||||||
|
Touches:
|
||||||
|
|
||||||
|
- `examples/plugins/auth-admin/admin-groups.ts`: `groupsDelete`, `groupsRemoveMember`, `lostToSelf` (small)
|
||||||
|
- `examples/plugins/auth-admin/admin-groups.test.ts`
|
||||||
|
|
||||||
### 14. Drop a double-clicked duplicate submit, with no client-side JavaScript.
|
### 14. Drop a double-clicked duplicate submit, with no client-side JavaScript.
|
||||||
|
|
||||||
A second identical POST is expected from a non-technical user, and today creates two
|
A second identical POST is expected from a non-technical user, and today creates two
|
||||||
@@ -93,29 +136,29 @@ Touches:
|
|||||||
- `src/auth/oauth-login.test.ts`
|
- `src/auth/oauth-login.test.ts`
|
||||||
- `src/auth/routes.ts`
|
- `src/auth/routes.ts`
|
||||||
- `src/auth/routes.test.ts`
|
- `src/auth/routes.test.ts`
|
||||||
- `src/auth/bootstrap.ts`: lines 7-18 (small)
|
- `src/auth/bootstrap.ts`: import lines (small)
|
||||||
- `src/auth/bootstrap.test.ts`: lines 5-13 (small)
|
- `src/auth/bootstrap.test.ts`: import lines (small)
|
||||||
- `src/plugin-host/plugin-api.ts`: lines 16-18 (small), lines 38-38 (small), lines 44-49 (small)
|
- `src/plugin-host/plugin-api.ts`: the `../auth/` export lines (small)
|
||||||
- `src/plugin-host/plugin.ts`: lines 7-7 (small)
|
- `src/plugin-host/plugin.ts`: the `Gate` import (small)
|
||||||
- `src/plugin-host/plugin.test.ts`: lines 15-15 (small)
|
- `src/plugin-host/plugin.test.ts`: the `AUTH_FLOWS` import (small)
|
||||||
- `src/plugin-host/discovery.ts`: lines 10-10 (small)
|
- `src/plugin-host/discovery.ts`: the `gate.ts` import (small)
|
||||||
- `src/plugin-host/system.ts`: lines 9-11 (small)
|
- `src/plugin-host/system.ts`: the three client-type imports (small)
|
||||||
- `src/http/app.ts`: lines 9-32 (small)
|
- `src/http/app.ts`: the `../auth/` import lines (small)
|
||||||
- `src/http/app.test.ts`: lines 1-17 (small)
|
- `src/http/app.test.ts`: import lines (small)
|
||||||
- `src/http/app-admin.test.ts`: lines 1-20 (small)
|
- `src/http/app-admin.test.ts`: import lines (small)
|
||||||
- `src/http/app-auth.test.ts`: lines 1-13 (small)
|
- `src/http/app-auth.test.ts`: import lines (small)
|
||||||
- `src/http/app-i18n.test.ts`: lines 1-14 (small)
|
- `src/http/app-i18n.test.ts`: import lines (small)
|
||||||
- `src/http/app-plugins.test.ts`: lines 1-18 (small)
|
- `src/http/app-plugins.test.ts`: import lines (small)
|
||||||
- `src/http/builtin-route.ts`: lines 4-4 (small)
|
- `src/http/builtin-route.ts`: the `Gate` import (small)
|
||||||
- `src/ui/chrome.ts`: lines 5-5 (small)
|
- `src/ui/chrome.ts`: the `gate.ts` import (small)
|
||||||
- `src/ui/nav.ts`: lines 6-6 (small)
|
- `src/ui/nav.ts`: the `gate.ts` import (small)
|
||||||
- `src/test-tooling/app-harness.ts`: lines 1-11 (small)
|
- `src/test-tooling/app-harness.ts`: import lines (small)
|
||||||
- `src/server.ts`: lines 3-14 (small)
|
- `src/server.ts`: the `./auth/` import lines (small)
|
||||||
- `src/function-limits.test.ts`: lines 17-20 (small)
|
- `src/function-limits.test.ts`: the `src/auth/` keys (small)
|
||||||
- `src/postgres.test.ts`: lines 46-46 (small)
|
- `src/postgres.test.ts`: the `src/auth/bootstrap.ts` path (small, only if bootstrap's path changes)
|
||||||
- `README.md`: `## Project layout`, `## Users, groups & permissions` (small), `## Building blocks` (small), `### Instant revoke: the optional denylist` (small), `### OAuth2 provider (Hydra)` (small), `## JWT signing key & rotation` (small), `### Scheduled rotation` (small), `### Emergency rotation (key compromise)` (small)
|
- `README.md`: `## Project layout`, `## Users, groups & permissions` (small), `## Building blocks` (small), `### Instant revoke: the optional denylist` (small), `### OAuth2 provider (Hydra)` (small), `## JWT signing key & rotation` (small), `### Scheduled rotation` (small), `### Emergency rotation (key compromise)` (small)
|
||||||
- `package.json`: lines 14-14 (small)
|
- `package.json`: the `gen-jwks` script (small)
|
||||||
- `compose.yml`: lines 130-130 (small), lines 161-161 (small)
|
- `compose.yml`: the `src/auth/bootstrap.ts` comment and command (small)
|
||||||
|
|
||||||
### 19. Run the documented Docker commands on macOS and fix whatever misbehaves.
|
### 19. Run the documented Docker commands on macOS and fix whatever misbehaves.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user