Skip to content

feat(auth): account settings administrators can change on the owner's behalf - #170

Merged
PiquelChips merged 5 commits into
mainfrom
feat/act-on-behalf
Oct 23, 2026
Merged

PiquelChips merged 5 commits into
mainfrom
feat/act-on-behalf

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Administrators could disable accounts and end sessions, but not change a user's settings. Removing a stolen passkey, unlinking an identity or removing an address took SQL against production. Part of #110. Its dashboard half comes with the in-process dashboard (PR 5 of the UI consolidation plan), so #110 stays open.

This is PR 1 of that plan. It is the service layer only: the dashboard will call it in-process, so it adds no admin API surface.

How

Operations on a Subject.

  • The settings an administrator may share with the owner are AccountService operations (src/account), written next to their setting (passkey, federation, emails, sessions, history).
  • A change takes a Subject: the account, and who acts on it. That is the owner with their session, or an Operator with the reason it must give.
  • A read takes a Viewer, which needs no reason. An operator therefore cannot make a change without a reason: it doesn't compile.
  • The owner's /account routes run them, through one router built from AccountOperation.
  • auth-service account <user> … runs them as the operator at the terminal.
  • The owner's behaviour is unchanged, and the existing owner tests only gained the shared router in their setup.

What is shared. Administrators may view, edit and remove, but never add a way to sign in or receive the account's mail.

Area Shared Owner only
Passkeys list, rename, remove add, confirm
Social identities list, unlink link
Email addresses list, make primary, remove add, verify
Sessions list, sign out one, sign out all
History read report an entry
OIDC clients all (administrators use AdminService's)

Sealed actors. These make "administrators never add a credential" enforceable once the dashboard calls the service in-process:

  • Subject's and Viewer's fields are private. Only their extractors build an owner's, from the session cookie. Operators get theirs from Subject::operator, ConfirmedSubject::operator and Viewer::operator.
  • Operator::Admin holds an AdminSession. Its fields are private to the admin module, so only the admin API's token authenticator creates one.
  • Owner-only operations stay in their modules' HTTP handlers. When they move into the service, they'll take an owner-only type.

When an administrator or operator acts:

  • Every change needs a reason. It goes into the event context and is stored in event_personal_data.reason (migration 0015), so retention and purges delete it.
  • The owner's history shows "By a Piquel administrator: "reason"".
  • Events record Actor::Admin or Actor::Cli. Reads are recorded as AccountViewed, like user show.
  • An administrator may not change another administrator's account. Operator::lock, moved out of AdminService, refuses it before waiting for the account lock and again under it.
  • Subject::commit rechecks the administrator's rights, session and passkey confirmation before committing, as AdminService::finish does. The CLI may change administrators' accounts.
  • A change that signs the owner out elsewhere, such as removing a passkey, ends every session, since the administrator has none of the owner's to keep. Sessions an operator ends record RevocationReason::Admin.

CLI.

  • account <user> passkeys|identities|emails|sessions|history …. Every change needs --reason.
  • Removing a passkey, unlinking and signing out everywhere also ask for confirmation.
  • AccountOperation is declared with the same macro as AdminOperation. The owner's router and the CLI match it exhaustively, and the coverage test parses a command line for every operation of both lists.

Tests

  • Administrators through AccountService (account::tests, database):
    • An administrator renames and removes another account's passkey and unlinks its identity. Each event has Actor::Admin and the reason, and the owner's history shows both.
    • Refusals, table-driven: an administrator's account, an unknown account, a non-administrator, an ended session and a stale confirmation are each refused, with nothing changed.
    • A revocation of the actor's rights, or a grant to the target, that commits while the change waits for the account lock refuses it, with nothing written. Removing the check under the lock fails this test. The CLI may change the administrator.
    • The last passkey stays, removed by an administrator or by the owner's route, even with an identity linked.
    • An administrator's read lists every session with current: false, and is recorded as AccountViewed by them.
  • CLI: every account operation has its command, and account … sessions revoke-all records the operator with the reason.
  • Storage: the personal-data test also checks the reason stays out of the event row, reads back, and erases.
  • Other checks: just db test (166), just test, just lint, just doc, just web check, prettier.

Not in this PR

  • Dashboard pages for these settings: they come with the in-process dashboard.
  • Authorizing administrators' reads. AccountService reads, like AdminService's, rely on the caller having authenticated them. Next PR: every AdminService method takes &Operator and authorizes it, reads included. AccountService reads will follow the same rule.
  • Security alerts (feat(auth): security alerts #83) and published: true (feat(web): public profiles at sourceorigin.dev/@handle #101): neither exists yet.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol (via T3 Code)

🤖 Generated with Claude Code

…s behalf

Administrators could disable accounts and end sessions, but not change a
user's settings: removing a stolen passkey or unlinking an identity took
SQL against production.

The settings an administrator may share with the owner now live in one
router, mounted at /account for the owner and at
/users/{user_id}/account on the admin listener. Handlers take a Subject,
the account and who acts, instead of a session, and run AccountService
operations that the `account` CLI command runs too. Administrators may
view, edit and remove, but never add a way to sign in or receive mail.
Every change on the admin mount needs a reason, stored with its events
as personal data and shown in the owner's history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8763d988-05e3-4023-920f-e5f4347bd8d3
📥 Commits

Reviewing files that changed from the base of the PR and between b370337 and 36d177c.

📒 Files selected for processing: 53
  • README.md
  • apps/auth-service/src/account/error.rs
  • apps/auth-service/src/account/mod.rs
  • apps/auth-service/src/account/subject.rs
  • apps/auth-service/src/account/tests.rs
  • apps/auth-service/src/admin/caller.rs
  • apps/auth-service/src/admin/mod.rs
  • apps/auth-service/src/admin/operation.rs
  • apps/auth-service/src/admin/service.rs
  • apps/auth-service/src/admin/tests.rs
  • apps/auth-service/src/admin/types.rs
  • apps/auth-service/src/cli/account.rs
  • apps/auth-service/src/cli/admin.rs
  • apps/auth-service/src/cli/client.rs
  • apps/auth-service/src/cli/console.rs
  • apps/auth-service/src/cli/error.rs
  • apps/auth-service/src/cli/handle.rs
  • apps/auth-service/src/cli/invite.rs
  • apps/auth-service/src/cli/mod.rs
  • apps/auth-service/src/cli/session.rs
  • apps/auth-service/src/cli/tests.rs
  • apps/auth-service/src/cli/user.rs
  • apps/auth-service/src/emails/mod.rs
  • apps/auth-service/src/emails/tests.rs
  • apps/auth-service/src/federation/identities.rs
  • apps/auth-service/src/federation/mod.rs
  • apps/auth-service/src/federation/tests.rs
  • apps/auth-service/src/history/mod.rs
  • apps/auth-service/src/history/tests.rs
  • apps/auth-service/src/lib.rs
  • apps/auth-service/src/operations.rs
  • apps/auth-service/src/passkey/error.rs
  • apps/auth-service/src/passkey/mod.rs
  • apps/auth-service/src/passkey/tests.rs
  • apps/auth-service/src/passkey/types.rs
  • apps/auth-service/src/routes.rs
  • apps/auth-service/src/security/mod.rs
  • apps/auth-service/src/sessions/mod.rs
  • apps/auth-service/src/sessions/tests.rs
  • apps/piquel-web/src/lib/History.svelte
  • crates/common/src/events.rs
  • crates/database/.sqlx/query-373ee5f059f46dd6c1fc1c7868737d4fafcb153f3bab187e07225d6ab5b661ed.json
  • crates/database/.sqlx/query-541618e02510feb91705bd2a2b159a72deb3c100b617b192255cf984b4fee39b.json
  • crates/database/.sqlx/query-af7512781fa362a02208733d4ab0a8e500542ab72bb0de645339ce19ec983271.json
  • crates/database/.sqlx/query-d6f47830c67cc1171f7bf64f97e2d72b55646a8a73b5d7574b73398cd6c00f94.json
  • crates/database/migrations/0015_event_reasons.sql
  • crates/database/src/repositories/deliveries/tests.rs
  • crates/database/src/repositories/events/mod.rs
  • crates/database/src/repositories/events/tests.rs
  • crates/database/tests/security.rs
  • docs/architecture/rust-conventions.md
  • docs/architecture/surfaces.md
  • just/auth.just
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

PiquelChips and others added 2 commits October 23, 2026 23:43
…ccount

The test revoked the actor's rights and granted the target's before the
change started, so it still passed without the check under the account
lock. Both now commit while the change waits for that lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… mount

The admin JSON API will be deleted once the dashboard moves into auth and
calls the services in-process, so it should not grow. The shared settings
stay as AccountService operations on a Subject, run by the owner's routes
and the `account` command, without the /users/{user_id}/account mount, its
reason header or the challenge it needed on ApiError.

The actors are sealed: only the extractor builds an owner's Subject, from
the session cookie, and only the admin API's authenticator builds an
Operator::Admin, whose AdminSession fields are private to the admin
module. The admin-side scenarios now call AccountService directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips PiquelChips changed the title feat(auth): administrators change an account's settings on its owner's behalf feat(auth): account settings administrators can change on the owner's behalf Oct 23, 2026
A reading Subject carried no reason but was accepted by changes too, so
an in-process caller could commit an administrator's change without one.
Reads now take a Viewer, which needs no reason, and a Subject is built
for an operator only with one, so such a change no longer compiles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips PiquelChips self-assigned this Oct 23, 2026
@PiquelChips PiquelChips added enhancement New feature or request apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI schema-change Any changes to the database schema admin The admin dashboard at admin.sourceorigin.dev labels Oct 23, 2026
@PiquelChips PiquelChips added this to the 0.1 milestone Oct 23, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Oct 23, 2026
@PiquelChips PiquelChips moved this from Needs Triage to In Progress in sourceorigin.dev Oct 23, 2026
Also says in the docs that reads take a Viewer and changes a Subject.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips
PiquelChips enabled auto-merge (squash) October 23, 2026 22:23
@PiquelChips
PiquelChips merged commit 2043954 into main Oct 23, 2026
11 checks passed
@PiquelChips
PiquelChips deleted the feat/act-on-behalf branch October 23, 2026 22:23
@github-project-automation github-project-automation Bot moved this from In Progress to Done in sourceorigin.dev Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

admin The admin dashboard at admin.sourceorigin.dev apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI enhancement New feature or request schema-change Any changes to the database schema

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant