Skip to content

Commit 2b149d6

Browse files
committed
feat(auth): admins send announcements to every account or chosen ones, which land in their inbox and by email
Administrators draft an announcement, check it, and send it at the revision they checked, to every account or up to 1,000 chosen ones. Sending writes each recipient a notification of kind announcement, from the recipients it locks, and records announcement_sent, whose emails go out on the announcement channel and link the inbox. The announcement's page counts who read it. Part of #362 and #365.
1 parent 7346c2f commit 2b149d6

81 files changed

Lines changed: 3924 additions & 111 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: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,16 @@ just auth account alice picture remove --reason "Impersonates someone"
271271
- Accounts are named by handle, ID or a verified email of an active account.
272272
- `--output json` prints the views the dashboard shows for `user search`
273273
(`UserPage`), `user show` (`UserDetail`), `audit list` (`EventPage`), `client
274-
list`, `invite list` and `admin list`, as defined in `piquel_common::admin`.
274+
list`, `invite list`, `admin list`, `announcement list` and `announcement show`
275+
(`AnnouncementDetail`), as defined in `piquel_common::admin`.
275276
`audit verify --output json` prints the verification.
276277
- `audit verify` and `audit prune` are described in
277278
[audit-history.md](docs/security/audit-history.md). `audit prune` connects as
278279
the schema owner when `AUTH_DATABASE_OWNER_URL` is set, since auth's own role
279280
may not delete events.
280281
- `user disable|delete`, `user recover`, `user undo-recovery`, `session revoke-all`,
281-
`admin revoke`, `client disable|suspend|delete`, `audit prune`, and `account …
282+
`admin revoke`, `client disable|suspend|delete`, `audit prune`, `announcement
283+
send`, and `account …
282284
passkeys revoke`, `identities unlink` and
283285
`sessions revoke-all` describe what they will change and ask for confirmation.
284286
Without a terminal they refuse unless given `--yes`.
@@ -323,8 +325,9 @@ just auth account alice picture remove --reason "Impersonates someone"
323325
- Failures print their causes and exit with 1; usage errors exit with 2.
324326

325327
Administrators manage accounts, their settings and security history, sessions,
326-
invitations, other administrators, handles, the delivery queue, signing keys and
327-
the origins approved for clients' pages to sign users in from the admin dashboard,
328+
invitations, other administrators, handles, announcements, the delivery queue,
329+
signing keys and the origins approved for clients' pages to sign users in from
330+
the admin dashboard,
328331
which auth serves on `AUTH_ADMIN_LISTENER` for the dashboard's origin,
329332
`AUTH_ADMIN_ORIGIN`, and which only a private route reaches.
330333
Its pages call `AdminService` in-process; there is no admin API.
@@ -387,18 +390,21 @@ Piquel tells its owner about the account, newest first, with the unread count in
387390
the settings sidebar and on the overview. Today that is a replaced primary
388391
address, a removed address, a recovery that revoked the account's passkeys,
389392
enrolled one or was undone, an account disabled, enabled, scheduled for deletion
390-
or restored, and a handle or display name changed, or a profile picture removed,
391-
by support. Each notification opens on a page of its own, which marks it read
392-
when the browser came from auth's own pages, so a link from another site cannot
393-
dismiss one, and shows the security history entry of the event it came from
394-
while the history keeps it, with "This wasn’t me" where the history allows a
395-
report. A notification holds no personal data, so it reads the same after its
396-
event's personal data is erased or the event is pruned.
393+
or restored, a handle or display name changed, or a profile picture removed, by
394+
support, and administrators' announcements. Each notification opens on a page of
395+
its own, which marks it read when the browser came from auth's own pages, so a
396+
link from another site cannot dismiss one, and shows the security history entry
397+
of the event it came from while the history keeps it, with "This wasn’t me"
398+
where the history allows a report. A notification holds no personal data, so it
399+
reads the same after its event's personal data is erased or the event is pruned;
400+
an announcement holds the text its administrators wrote, which goes with its
401+
recipients.
397402

398403
Each notification is also emailed: a recovery's to every verified address, a
399404
replaced or removed address's to that address, and any other to the primary
400405
verified address. The email says what the inbox says, and links the
401-
notification's page.
406+
notification's page; an announcement's goes out on a channel of its own and
407+
links the inbox.
402408

403409
The owner marks one unread, or every one read, in settings or through
404410
`POST /account/notifications/{id}/read`, `…/{id}/unread` and
@@ -439,6 +445,43 @@ sign-in. For development, `just auth mailpit` runs a local Mailpit: set
439445
`http://localhost:8025`. Sending domains need SPF, DKIM and DMARC; see
440446
[infra/README.md](infra/README.md#email).
441447

448+
### Announcements
449+
450+
Administrators tell accounts what they must know, such as a security incident or
451+
a change to the privacy policy, with an announcement: a subject and a plain text,
452+
to every account or to up to 1,000 chosen ones. It is emailed to each recipient's
453+
primary verified address, and every recipient, including those without an
454+
address, gets it as a notification in their inbox (see
455+
[Notifications](#notifications)), whose page keeps its paragraphs. Its page on
456+
the dashboard says how many recipients read it. It is not for support
457+
conversations, which happen elsewhere.
458+
459+
An announcement starts as a draft, which goes to nobody and which any
460+
administrator may change or discard; its page shows the email exactly as it will
461+
be sent, and how many recipients it reaches. Sending it needs the dashboard's
462+
passkey confirmation, and sends only the revision that was checked: a draft
463+
changed meanwhile, by another administrator say, is refused, to be checked again.
464+
Once sent, nothing, not even the database's own role, changes its text. One to
465+
everyone goes to every account at that moment, disabled ones and
466+
ones being deleted included, since Piquel still holds their data. Sending records
467+
an `announcement_sent` event with who sent it and to how many accounts.
468+
469+
```sh
470+
just auth announcement draft --subject "Security incident on 2 November" \
471+
--body-file incident.txt --everyone # or --to alice --to bob; prints the draft's ID
472+
just auth announcement show <id> # its text, recipients, and once sent, its emails
473+
just auth announcement edit <id> --subject "…" --body-file - --to alice
474+
just auth announcement send <id> --revision <n> # the revision `show` printed; asks first
475+
just auth announcement discard <id> # a draft only
476+
just auth announcement list
477+
```
478+
479+
Its emails go out on the `announcement` delivery channel, apart from the `email`
480+
channel's verification and recovery links, so sending one to every account
481+
holds none of them back. Each is sent to the address the account has when it
482+
goes out, for up to three days, and dropped once the account has none. The
483+
dashboard counts them by status while the queue keeps them.
484+
442485
### Data export and account deletion
443486

444487
Owners download their data and delete their account on
@@ -466,7 +509,9 @@ probation sign-in.
466509
- **Purge:** every five minutes, one replica purges the accounts past their grace
467510
period. It deletes the apps the account registered, leaving tombstones with
468511
only their ID, settings and dates, then the account with its emails, passkeys,
469-
identities, sessions, grants, consents and email deliveries, and the personal
512+
identities, sessions, grants, consents, email and announcement deliveries, and
513+
the announcements to chosen accounts it was the last recipient of, which may
514+
concern it, and the personal
470515
data (IP, device, provider subjects, app origins, operators' reasons) of every
471516
event it is the subject or actor of, including one a request records while the
472517
purge runs. The events stay, with pseudonymous IDs only. Its handles stay in the
@@ -494,7 +539,8 @@ their records come with #66 and #97.
494539

495540
### Outbound deliveries
496541

497-
Messages for other systems, such as back-channel logout tokens and email, wait in
542+
Messages for other systems, such as back-channel logout tokens, email and
543+
announcements, wait in
498544
a queue in the database until a worker sends them. Inspect and repair it with:
499545

500546
```sh

‎apps/auth-service/assets/dashboard.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
* needs `data-form-time` left to show its form. Once too little is left:
1111
* - a click on a link marked `data-confirm-first`, to a change's page, opens the
1212
* dialog, then follows the link;
13-
* - a form in the page's `<main>` posting, a change, opens the dialog, then posts.
13+
* - a form in the page's `<main>` posting, a change, opens the dialog, then posts,
14+
* unless it is marked `data-unconfirmed`, as a change that needs no
15+
* confirmation, such as writing a draft announcement, is; a button of it marked
16+
* `data-confirms`, such as the draft's "Send", still asks.
1417
* The dialog's `data-passkey-confirm` button runs the passkey ceremony for the
1518
* dashboard's origin, which auth lists as a related origin of its RP ID: the
1619
* dialog's `data-confirmation-start` starts it, and its `data-confirmation-finish`
@@ -219,8 +222,10 @@ function wire(document) {
219222
confirmedForm = undefined;
220223
return;
221224
}
222-
if (!form.closest('main') || confirmed(0)) return;
223225
const submitter = event.submitter;
226+
const unconfirmed =
227+
form.hasAttribute('data-unconfirmed') && !submitter?.hasAttribute('data-confirms');
228+
if (!form.closest('main') || unconfirmed || confirmed(0)) return;
224229
const opened = confirm(() => {
225230
// Its submit event runs within the call, or not at all if it is invalid.
226231
confirmedForm = form;

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Admin failures, from the dashboard or the CLI, and their status and message.
22
3+
use super::UserRef;
34
use crate::{
45
ClientRegistryError, KeyError, deletion::DeletionError, handles::HandlesError,
56
security::ApiError,
@@ -134,6 +135,33 @@ pub enum AdminError {
134135
/// No administrator reserved this handle.
135136
#[error("this handle is not on the reserved list")]
136137
HandleNotReserved,
138+
/// An announcement's subject is blank, longer than 150 characters, or not one
139+
/// line.
140+
#[error("give a subject of 1 to 150 characters, on one line")]
141+
InvalidSubject,
142+
/// An announcement's text is blank, longer than 20,000 characters, or holds
143+
/// control characters other than line breaks and tabs.
144+
#[error("give a text of 1 to 20,000 characters, without control characters")]
145+
InvalidBody,
146+
/// An announcement to chosen accounts names none.
147+
#[error("name at least one account, or send it to everyone")]
148+
NoRecipients,
149+
/// An announcement names more accounts than one may be chosen for.
150+
#[error("name at most 1,000 accounts, or send it to everyone")]
151+
TooManyRecipients,
152+
/// An account an announcement names does not exist.
153+
#[error("no account has the ID, handle or verified email {0}")]
154+
UnknownRecipient(UserRef),
155+
/// No announcement has this ID.
156+
#[error("no announcement has this ID")]
157+
AnnouncementNotFound,
158+
/// The draft changed since its sender checked it, such as by another
159+
/// administrator: they check it again before sending it.
160+
#[error("the draft changed since you checked it; check it again before sending it")]
161+
AnnouncementChanged,
162+
/// The announcement was sent, and what was sent never changes.
163+
#[error("the announcement was sent, so it can no longer change")]
164+
AnnouncementSent,
137165
/// Persistence failed.
138166
#[error(transparent)]
139167
Database(#[from] DatabaseError),
@@ -207,6 +235,14 @@ impl AdminError {
207235
Self::HandleNotReleased => "handle_not_released",
208236
Self::HandleReserved => "handle_reserved",
209237
Self::HandleNotReserved => "handle_not_reserved",
238+
Self::InvalidSubject => "invalid_subject",
239+
Self::InvalidBody => "invalid_body",
240+
Self::NoRecipients => "no_recipients",
241+
Self::TooManyRecipients => "too_many_recipients",
242+
Self::UnknownRecipient(_) => "unknown_recipient",
243+
Self::AnnouncementNotFound => "announcement_not_found",
244+
Self::AnnouncementSent => "announcement_sent",
245+
Self::AnnouncementChanged => "announcement_changed",
210246
Self::Database(_) => "database",
211247
Self::Client(_) => "client",
212248
Self::Deletion(_) => "deletion",
@@ -248,7 +284,11 @@ impl From<AdminError> for ApiError {
248284
match error {
249285
AdminError::InvalidReason
250286
| AdminError::InvalidInviteExpiry(_)
251-
| AdminError::InvalidHandoff => Self::bad_request(message),
287+
| AdminError::InvalidHandoff
288+
| AdminError::InvalidSubject
289+
| AdminError::InvalidBody
290+
| AdminError::NoRecipients
291+
| AdminError::TooManyRecipients => Self::bad_request(message),
252292
AdminError::Handle(error) => error.into(),
253293
AdminError::SessionEnded | AdminError::StepUpRequired(_) => Self::unauthorized(message),
254294
AdminError::NotAdministrator
@@ -262,6 +302,8 @@ impl From<AdminError> for ApiError {
262302
| AdminError::DeliveryNotFound { .. }
263303
| AdminError::HandleNotReleased
264304
| AdminError::HandleNotReserved
305+
| AdminError::UnknownRecipient(_)
306+
| AdminError::AnnouncementNotFound
265307
| AdminError::SigningKey(KeyError::Unknown(_)) => Self::not_found(message),
266308
AdminError::AlreadyDisabled
267309
| AdminError::AlreadyActive
@@ -278,6 +320,8 @@ impl From<AdminError> for ApiError {
278320
| AdminError::AlreadyAdministrator
279321
| AdminError::NotAnAdministrator
280322
| AdminError::HandleReserved
323+
| AdminError::AnnouncementSent
324+
| AdminError::AnnouncementChanged
281325
// A stored key that cannot sign is refused, and the form says which.
282326
| AdminError::SigningKey(
283327
KeyError::Stored { .. } | KeyError::Mismatched(_) | KeyError::NoActiveKey,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ pub use operator::Operator;
2727
pub(crate) use overview::{Kinds, Overview, Problem};
2828
pub use service::AdminService;
2929
pub(crate) use sign_in::{DashboardSignIn, SignedInAdmin};
30-
pub use types::{GracePeriod, HandleProblem, InvalidLifetime, InviteExpiry, Reason, UserRef};
30+
pub use types::{
31+
AnnouncementDraft, AnnouncementRecipients, GracePeriod, HandleProblem, InvalidLifetime,
32+
InviteExpiry, Reason, UserRef,
33+
};
3134

3235
/// Administrative scenarios over the service, and the harness the shared
3336
/// settings' tests also use.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,18 @@ operations! {
102102
VerifyAuditChain,
103103
/// Delete the audit history through a checkpoint.
104104
PruneAuditChain,
105+
/// List announcements, drafts and sent ones.
106+
ListAnnouncements,
107+
/// Show one announcement, with whom its email reaches.
108+
ViewAnnouncement,
109+
/// Draft an announcement to every account or to chosen ones.
110+
DraftAnnouncement,
111+
/// Change a draft announcement.
112+
EditAnnouncement,
113+
/// Delete a draft announcement.
114+
DiscardAnnouncement,
115+
/// Send a draft announcement: email it, and show it in its recipients'
116+
/// settings.
117+
SendAnnouncement,
105118
}
106119
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ impl AdminService {
3030
user: &UserRef,
3131
) -> Result<UserId, AdminError> {
3232
operator.authorize_read(&self.database).await?;
33-
let found = match user {
33+
self.lookup(user).await?.ok_or(AdminError::UserNotFound)
34+
}
35+
36+
/// The ID of the account `user` names, as [`Self::find_user`] finds it, for an
37+
/// operator already authorized to read.
38+
pub(super) async fn lookup(&self, user: &UserRef) -> Result<Option<UserId>, AdminError> {
39+
Ok(match user {
3440
UserRef::Id(id) => self
3541
.database
3642
.users()
@@ -57,8 +63,7 @@ impl AdminService {
5763
.map(|email| email.user_id),
5864
Err(_) => None,
5965
},
60-
};
61-
found.ok_or(AdminError::UserNotFound)
66+
})
6267
}
6368

6469
/// The handle of the account `user_id`, in any status, which names it.

0 commit comments

Comments
 (0)