Skip to content

Commit c336c47

Browse files
PiquelChipsclaude
andcommitted
feat(auth): let owners download their data and delete their account
Owners download their data and delete their account on /settings/data, after a recent passkey confirmation checked under the account lock. A deleted account waits 30 days in 'deleting'; a passkey sign-in then offers to restore it, in its own cookie, and the sign-in page restores it and signs in with that passkey. A job purges accounts past their grace period with their owned clients and the personal data of their events; their handles stay, ownerless, so nobody takes them again. Operators schedule, restore and purge through AdminService, the dashboard and the CLI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ddd021b commit c336c47

85 files changed

Lines changed: 4591 additions & 183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ just auth user enable alice
211211
just auth user recover alice --reason "Lost every passkey"
212212
just auth user recover alice --reason "Phone stolen" --revoke --keep <passkey-id>
213213
just auth user undo-recovery alice --reason "Owner confirmed by phone"
214+
just auth user delete alice --reason "Asked by email" # see Data export and account deletion
215+
just auth user restore alice --reason "Changed their mind"
214216
just auth session revoke <session-id> # one session, as `user show` lists it
215217
just auth session revoke-all alice # every session of the account
216218
just auth audit --user alice --kind session_revoked
@@ -223,7 +225,7 @@ just auth account alice emails remove <email-id> --reason "Asked by email"
223225
- `--output json` prints the views the dashboard shows for `user search`
224226
(`UserPage`), `user show` (`UserDetail`), `audit` (`EventPage`), `client list`,
225227
`invite list` and `admin list`, as defined in `crates/admin-api`.
226-
- `user disable`, `user recover`, `user undo-recovery`, `session revoke-all`,
228+
- `user disable|delete`, `user recover`, `user undo-recovery`, `session revoke-all`,
227229
`admin revoke`, `client
228230
disable|suspend|delete`, and `account … passkeys revoke`, `identities unlink` and
229231
`sessions revoke-all` describe what they will change and ask for confirmation.
@@ -331,6 +333,53 @@ sign-in. For development, `just auth mailpit` runs a local Mailpit: set
331333
`http://localhost:8025`. Sending domains need SPF, DKIM and DMARC; see
332334
[infra/README.md](infra/README.md#email).
333335

336+
### Data export and account deletion
337+
338+
Owners download their data and delete their account on
339+
`auth.piquel.fr/settings/data`. Both need a passkey confirmation from the last five
340+
minutes, checked under the account lock, so no administrator can do either for
341+
them, and neither can a session that never confirms, such as a recovery's
342+
probation sign-in.
343+
344+
- **Download** sends one versioned JSON file (`"format": "piquel.account-export"`):
345+
profile, the handles it holds or held, email addresses, passkeys (label, dates
346+
and backup state, no key material), linked identities, devices with their IP
347+
addresses, an administrator's dashboard sign-ins, consents, refresh grants, the
348+
apps the account registered, its recoveries (dates, state and the passkey each
349+
enrolled, never a link) and the security history. It is read
350+
from one snapshot, holds no secret or digest, nothing may cache it, and it is
351+
recorded in the history.
352+
- **Deleting** asks for the account's handle. The account becomes `deleting`, every
353+
session and refresh grant ends, their apps receive back-channel logout tokens, and
354+
it can no longer sign in or authorize. For 30 days, signing in with one of its
355+
passkeys asks to restore it instead of signing in: the offer, valid for five
356+
minutes and used once, lives in its own cookie, and restoring signs in with that
357+
passkey, as its sign-in would have: a recovery's passkey in probation confirms
358+
nothing.
359+
- **Purge:** every five minutes, one replica purges the accounts past their grace
360+
period. It deletes the apps the account registered, leaving tombstones without
361+
an owner, then the account with its emails, passkeys, identities, sessions,
362+
grants, consents and email deliveries, and the personal data (IP, device,
363+
provider subjects, operators' reasons) of every event it is the subject or actor
364+
of. The events stay, with pseudonymous IDs only. Its handles stay in the handles
365+
table without an owner, so no account claims them until an operator releases
366+
them (`handle release`).
367+
368+
Administrators schedule and restore deletions from the account's page on the
369+
admin dashboard, with a reason the owner sees in their history. Operators do the
370+
same with the CLI, which alone also purges at once, in any status, since that
371+
cannot be undone:
372+
373+
```sh
374+
just auth user delete alice --reason "Asked by email" # 30 days of grace
375+
just auth user restore alice --reason "Changed their mind"
376+
just auth user delete mallory --immediately --reason "Spam" # cannot be undone
377+
```
378+
379+
Nobody can delete the last active administrator's account. Auth does not email the
380+
account about its deletion yet, and the signals that tell applications to erase
381+
their records come with #66 and #97.
382+
334383
### Outbound deliveries
335384

336385
Messages for other systems, such as back-channel logout tokens and email, wait in

‎apps/auth-service/src/account/error.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::{
44
AdminError,
55
clients::OwnedClientError,
6+
deletion::DeletionError,
67
emails::EmailError,
78
federation::FederationError,
89
grants::GrantError,
@@ -47,6 +48,9 @@ pub(crate) enum AccountError {
4748
/// A recovery link was refused, or a recovery could not be undone.
4849
#[error(transparent)]
4950
Recovery(#[from] RecoveryError),
51+
/// The account could not be exported, deleted or restored.
52+
#[error(transparent)]
53+
Deletion(#[from] DeletionError),
5054
/// The owner's session ended, or lacks a recent enough passkey confirmation.
5155
#[error(transparent)]
5256
Owner(#[from] SessionError),
@@ -71,6 +75,7 @@ impl From<AccountError> for ApiError {
7175
AccountError::History(error) => error.into(),
7276
AccountError::Client(error) => error.into(),
7377
AccountError::Recovery(error) => error.into(),
78+
AccountError::Deletion(error) => error.into(),
7479
AccountError::Owner(error) => error.into(),
7580
AccountError::Operator(error) => error.into(),
7681
AccountError::Database(error) => error.into(),

‎apps/auth-service/src/admin/error.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Admin failures, from the dashboard or the CLI, and their status and message.
22
3-
use crate::{ClientRegistryError, handles::HandlesError, security::ApiError};
3+
use crate::{
4+
ClientRegistryError, deletion::DeletionError, handles::HandlesError, security::ApiError,
5+
};
46
use piquel_common::{DeliveryId, PasskeyId, protocol::step_up::StepUpRequirement};
57
use piquel_crypto::CryptoError;
68
use piquel_repository::DatabaseError;
@@ -97,8 +99,13 @@ pub enum AdminError {
9799
#[error("the account has no recovery that can still be undone")]
98100
NoRecoveryToUndo,
99101
/// Only active accounts can become administrators.
100-
#[error("the account is disabled; enable it before granting administrator rights")]
102+
#[error(
103+
"the account is disabled or being deleted; only active accounts can become administrators"
104+
)]
101105
AccountDisabled,
106+
/// The account is scheduled for deletion, which only restoring it ends.
107+
#[error("the account is scheduled for deletion; restore it first")]
108+
DeletionScheduled,
102109
/// The account is already an administrator.
103110
#[error("the account is already an administrator")]
104111
AlreadyAdministrator,
@@ -124,6 +131,9 @@ pub enum AdminError {
124131
/// A client change was refused or failed.
125132
#[error(transparent)]
126133
Client(#[from] ClientRegistryError),
134+
/// Deleting, restoring or purging the account was refused or failed.
135+
#[error(transparent)]
136+
Deletion(#[from] DeletionError),
127137
/// Secret generation failed.
128138
#[error(transparent)]
129139
Crypto(#[from] CryptoError),
@@ -162,6 +172,7 @@ impl AdminError {
162172
Self::GrantDuringRecovery => "grant_during_recovery",
163173
Self::NoRecoveryToUndo => "no_recovery_to_undo",
164174
Self::AccountDisabled => "account_disabled",
175+
Self::DeletionScheduled => "deletion_scheduled",
165176
Self::AlreadyAdministrator => "already_administrator",
166177
Self::NotAnAdministrator => "not_an_administrator",
167178
Self::OwnRights => "own_rights",
@@ -170,6 +181,7 @@ impl AdminError {
170181
Self::HandleNotReleased => "handle_not_released",
171182
Self::Database(_) => "database",
172183
Self::Client(_) => "client",
184+
Self::Deletion(_) => "deletion",
173185
Self::Crypto(_) => "crypto",
174186
Self::Event(_) => "event",
175187
Self::Link(_) => "link",
@@ -230,10 +242,12 @@ impl From<AdminError> for ApiError {
230242
| AdminError::NoRecoveryToUndo
231243
| AdminError::GrantDuringRecovery
232244
| AdminError::AccountDisabled
245+
| AdminError::DeletionScheduled
233246
| AdminError::AlreadyAdministrator
234247
| AdminError::NotAnAdministrator => Self::conflict(message),
235248
AdminError::Database(error) => error.into(),
236249
AdminError::Client(error) => error.into(),
250+
AdminError::Deletion(error) => error.into(),
237251
error @ (AdminError::Crypto(_) | AdminError::Event(_) | AdminError::Link(_)) => {
238252
Self::internal(error)
239253
}

‎apps/auth-service/src/admin/operation.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ operations! {
2222
RecoverAccount,
2323
/// Undo an account's recovery for its owner, once they are confirmed.
2424
UndoRecovery,
25+
/// Schedule an account's deletion, with a grace period.
26+
ScheduleDeletion,
27+
/// Restore an account scheduled for deletion.
28+
RestoreUser,
29+
/// Delete an account at once, without a grace period.
30+
PurgeUser,
2531
/// End every session of an account.
2632
RevokeUserSessions,
2733
/// End one session.

0 commit comments

Comments
 (0)