Skip to content

Commit 76be8ec

Browse files
authored
feat(admin): the dashboard runs deliveries, signing keys, handles and account history like the CLI (#345)
The admin dashboard lagged the operator CLI: delivery triage, signing keys, handle checks and an account's security history were terminal-only, and the overview told administrators to go run a command when deliveries backed up. Now the dashboard does them too, through `AdminService`, so permissions and audit events match every other admin change: - **Deliveries**: list by status and channel, retry and cancel from each row. The overview's "messages waiting" notice links straight to the queue. - **Signing keys**: list, rotate (optionally signing at once) and revoke. These are new `AdminOperation`s, and the `keys` commands run them too. The key change re-checks the administrator's rights and confirmation just before it commits, like any other change. **Import stays CLI-only**: the PEM private key should never pass through a browser (the reason sits next to its `None` arm). - **Handles**: a Handles page lists the accounts `handle check` lists and releases handles. The rename form can now allow a reserved handle, as `--allow-reserved` does. - **Security history**: a History tab on each account reuses the owner's timeline, read-only. Reading it needs no passkey confirmation, has no report buttons, and is recorded as a view. - **Data export stays the owner's**: an export copies every IP address and the whole history out of auth, so only the owner's recently confirmed session gets it. Support recovers the account instead. This is documented in `surfaces.md` and the account module. OIDC client management is out of scope here (another PR handles it). Verified on a preview: both `admin.spec.ts` tests pass against it, with screenshots of each new page. The new server-side tests and the affected admin, CLI, keys and settings tests pass on a scratch database, and clippy and the web lint pass. Reviewed with review-loop: 2 rounds with 2× GPT 6.1 Sol and Claude Opus 5.5 (the last after rebasing onto main). Verdict: approved > [!NOTE] > Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol and Claude Opus 5.5 (via T3 Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Admin dashboard - Added **Deliveries**, **Handles**, and **Signing Keys** pages to the administrator dashboard and sidebar. - The Deliveries page lists up to 100 deliveries. Administrators can filter by status and channel, and retry or cancel deliveries when the delivery state permits. The overview’s “messages waiting” notice links to the queue. - The Handles page lists reserved handles, shows the accounts that use them, and supports handle checks and releases. Administrators can also allow a reserved handle during a rename. - The Signing Keys page lists key types, states, and lifecycle dates. Administrators can rotate keys and revoke keys. Rotation can make the new key active immediately. - Key import remains CLI-only. Dashboard changes use `AdminService`; the key-change flow rechecks administrator rights before committing. ## Account security history - Added a read-only History tab to each account’s settings pages. It reuses the account timeline and records an administrator’s read as a view. - The administrator view has no report action. Owner-only reporting and confirmation behavior remain distinct from the administrator view. - Account-data export remains available only to the owner in a recently confirmed session. Administrators cannot export account data. Documentation describes the export’s contents and the recovery path for owners who have lost all passkeys. ## Service and data model - Added `AdminOperation`s for listing, rotating, revoking, and importing signing keys. Key list operations are classified as reads; key changes are classified as changes. - Added signing-key error handling, including API mappings for unknown keys, conflicts, database failures, cryptographic errors, and authorization refusals. - Added shared admin types for delivery status and summaries, and signing-key state, type, and summary data. The signing-key view omits key material. - Updated the database repositories to use the shared admin types. Added conversion from stored signing-key records to the public admin view. - Routed CLI list, rotate, revoke, and import commands through `AdminService`. Digest-usage and audit commands retain their existing paths. ## User interface and documentation - Added dashboard views and actions for delivery management, reserved handles, and signing keys. Delivery and key views show actions according to the available state and confirmation rules. - Updated delivery-queue, administration, signing-key, handle, account-export, and security-history documentation. - Extended the browser test suite with coverage for account history, key rotation and revocation, delivery filtering, and handle-release refusal. The supplied change summary does not establish test execution results. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a9232bd commit 76be8ec

42 files changed

Lines changed: 1607 additions & 153 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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ just auth keys digest-usage # stored token digests per digest key
146146
just auth keys import file:///path/key.pem # import a PEM key into an empty key set
147147
```
148148

149+
The admin dashboard's Signing keys page lists, rotates and revokes keys the same
150+
way. Importing stays at the terminal, so the PEM private key never passes
151+
through a browser.
152+
149153
`keys rotate` publishes the next key ahead of schedule. It still waits 24 hours
150154
before signing, so no verifier meets an unknown key. `--now` skips the wait:
151155
verifiers with a cached key set reject the new key's tokens until they fetch
@@ -314,7 +318,8 @@ just auth account alice apps remove <client-id> --reason "Impersonating app"
314318
to recover one.
315319
- Failures print their causes and exit with 1; usage errors exit with 2.
316320

317-
Administrators manage accounts, sessions, invitations, other administrators and
321+
Administrators manage accounts, their settings and security history, sessions,
322+
invitations, other administrators, handles, the delivery queue, signing keys and
318323
the origins approved for clients' pages to sign users in from the admin dashboard,
319324
which auth serves on `AUTH_ADMIN_LISTENER` for the dashboard's origin,
320325
`AUTH_ADMIN_ORIGIN`, and which only a private route reaches.
@@ -351,7 +356,9 @@ handle no account holds anymore, the only way one returns to the pool, for cases
351356
like a trademark dispute; to free a current handle, rename its account first.
352357
Every change is recorded as a domain event with its operator; a rename also with
353358
its reason, which the owner sees in their history. Administrators rename from the
354-
dashboard the same way, with a reason.
359+
dashboard the same way, with a reason, and may allow a reserved handle as
360+
`--allow-reserved` does; its Handles page lists the accounts `handle check` lists,
361+
and releases handles.
355362

356363
Upgrading from a release that stored usernames: run its `handle check`, and rename
357364
every account it lists with its `handle rename`, before deploying. The migration

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
//! a way to sign in or to receive the account's email, which would let them take
1010
//! the account over. Adding a passkey, linking an identity, adding an address
1111
//! and reporting a history entry take an [`Owner`], which only the session cookie
12-
//! builds, so an administrator cannot call them. Verifying an address is
12+
//! builds, so an administrator cannot call them. So does downloading the
13+
//! account's data: the export copies every IP address and the whole history out
14+
//! of auth, and only the owner's recently confirmed session may receive it.
15+
//! Support recovers an owner who lost every passkey instead, who then downloads
16+
//! it themselves. Verifying an address is
1317
//! authorized by its link's token instead, and takes the signed-in owner only if
1418
//! there is one, to refuse a browser signed in to another account. The owner's
1519
//! clients, which administrators manage through `AdminService`, are the owner's

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Admin failures, from the dashboard or the CLI, and their status and message.
22
33
use crate::{
4-
ClientRegistryError, deletion::DeletionError, handles::HandlesError, security::ApiError,
4+
ClientRegistryError, KeyError, deletion::DeletionError, handles::HandlesError,
5+
security::ApiError,
56
};
67
use piquel_common::{DeliveryId, PasskeyId, protocol::step_up::StepUpRequirement};
78
use piquel_crypto::CryptoError;
@@ -147,6 +148,20 @@ pub enum AdminError {
147148
/// The audit chain could not be verified or pruned.
148149
#[error(transparent)]
149150
Audit(#[from] crate::AuditError),
151+
/// A signing key change was refused or failed.
152+
#[error(transparent)]
153+
SigningKey(KeyError),
154+
}
155+
156+
impl From<KeyError> for AdminError {
157+
/// Keeps the operator's own refusal as it is, so the dashboard asks for a
158+
/// confirmation or a sign-in as for any change.
159+
fn from(error: KeyError) -> Self {
160+
match error {
161+
KeyError::Refused(refused) => *refused,
162+
error => Self::SigningKey(error),
163+
}
164+
}
150165
}
151166

152167
impl AdminError {
@@ -190,6 +205,7 @@ impl AdminError {
190205
Self::Event(_) => "event",
191206
Self::Link(_) => "link",
192207
Self::Audit(_) => "audit",
208+
Self::SigningKey(_) => "signing_key",
193209
}
194210
}
195211

@@ -235,7 +251,8 @@ impl From<AdminError> for ApiError {
235251
| AdminError::InvitationNotFound
236252
| AdminError::ClientNotFound
237253
| AdminError::DeliveryNotFound { .. }
238-
| AdminError::HandleNotReleased => Self::not_found(message),
254+
| AdminError::HandleNotReleased
255+
| AdminError::SigningKey(KeyError::Unknown(_)) => Self::not_found(message),
239256
AdminError::AlreadyDisabled
240257
| AdminError::AlreadyActive
241258
| AdminError::EmailClaimed(_)
@@ -249,14 +266,23 @@ impl From<AdminError> for ApiError {
249266
| AdminError::AccountDisabled
250267
| AdminError::DeletionScheduled
251268
| AdminError::AlreadyAdministrator
252-
| AdminError::NotAnAdministrator => Self::conflict(message),
253-
AdminError::Database(error) => error.into(),
269+
| AdminError::NotAnAdministrator
270+
// A stored key that cannot sign is refused, and the form says which.
271+
| AdminError::SigningKey(
272+
KeyError::Stored { .. } | KeyError::Mismatched(_) | KeyError::NoActiveKey,
273+
) => Self::conflict(message),
274+
AdminError::Database(error) | AdminError::SigningKey(KeyError::Database(error)) => {
275+
error.into()
276+
}
254277
AdminError::Client(error) => error.for_operators(),
255278
AdminError::Deletion(error) => error.into(),
256279
error @ (AdminError::Crypto(_)
257280
| AdminError::Event(_)
258281
| AdminError::Link(_)
259-
| AdminError::Audit(_)) => Self::internal(error),
282+
| AdminError::Audit(_)
283+
| AdminError::SigningKey(KeyError::Crypto(_) | KeyError::Refused(_))) => {
284+
Self::internal(error)
285+
}
260286
}
261287
}
262288
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ operations! {
8585
RetryDelivery,
8686
/// Cancel a pending or failed delivery.
8787
CancelDelivery,
88+
/// List signing keys, with their state and dates.
89+
ListSigningKeys,
90+
/// Publish a new signing key, or make it sign at once.
91+
RotateSigningKey,
92+
/// Delete a signing key at once, such as a compromised one.
93+
RevokeSigningKey,
94+
/// Import the deployment's PEM signing key into an empty key set.
95+
ImportSigningKey,
8896
/// Recompute the audit chain and check its checkpoints.
8997
VerifyAuditChain,
9098
/// Delete the audit history through a checkpoint.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Signing keys: listing, rotating, revoking and importing them, through the
2+
//! [`KeyStore`] the caller holds, which seals them with its key-encryption key.
3+
4+
use super::AdminService;
5+
use crate::{
6+
KeyStore,
7+
admin::{AdminError, Operator},
8+
};
9+
use piquel_common::{admin::SigningKey, protocol::jwt::KeyId};
10+
use piquel_crypto::Rs256Key;
11+
12+
impl AdminService {
13+
/// Lists every signing key, oldest first, without either half of the key.
14+
pub(crate) async fn list_signing_keys(
15+
&self,
16+
operator: &Operator,
17+
) -> Result<Vec<SigningKey>, AdminError> {
18+
operator.authorize_read(&self.database).await?;
19+
Ok(Self::views(self.database.signing_keys().list().await?))
20+
}
21+
22+
/// Publishes a `next` signing key in `keys`, or keeps the one already
23+
/// published, and returns its ID; with `immediately`, it signs at once, as
24+
/// [`KeyStore::rotate`] says. Every replica picks it up within a minute.
25+
pub(crate) async fn rotate_signing_key(
26+
&self,
27+
operator: &Operator,
28+
keys: &KeyStore,
29+
immediately: bool,
30+
) -> Result<KeyId, AdminError> {
31+
Ok(keys.rotate(operator, immediately).await?)
32+
}
33+
34+
/// Deletes signing key `id` from `keys` at once, as [`KeyStore::revoke`]
35+
/// does, and returns the key that signs instead, when it was the active one.
36+
pub(crate) async fn revoke_signing_key(
37+
&self,
38+
operator: &Operator,
39+
keys: &KeyStore,
40+
id: &KeyId,
41+
) -> Result<Option<KeyId>, AdminError> {
42+
Ok(keys.revoke(operator, id).await?)
43+
}
44+
45+
/// Imports `key`, the deployment's PEM key, into `keys` as the active key,
46+
/// if the key set is empty, and returns whether it did.
47+
pub(crate) async fn import_signing_key(
48+
&self,
49+
operator: &Operator,
50+
keys: &KeyStore,
51+
key: Rs256Key,
52+
) -> Result<bool, AdminError> {
53+
Ok(keys.import(operator, key).await?)
54+
}
55+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mod accounts;
99
mod clients;
1010
/// The event log, the audit chain that signs it, and the deliveries events cause.
1111
mod events;
12+
/// Signing keys, through the key store the caller holds.
13+
mod keys;
1214
/// Recovering an account whose owner lost every passkey, and undoing it.
1315
mod recovery;
1416

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Changing signing keys.
2+
3+
use super::*;
4+
use crate::security::CONFIRMATION_MAX_AGE;
5+
6+
/// Rotating the signing key checks its administrator as every change does, after
7+
/// its last write and before committing: one whose rights were revoked, or whose
8+
/// confirmation is stale, gets the refusal any change gets, and publishes nothing.
9+
#[tokio::test]
10+
#[ignore = "requires TEST_DATABASE_URL"]
11+
async fn signing_key_changes_check_their_administrator() {
12+
let harness = Harness::new().await;
13+
let service = harness.service();
14+
let keys = crate::KeyStore::new(
15+
harness.database.clone(),
16+
std::sync::Arc::new(crate::tests::key_encryption_key()),
17+
);
18+
let admin = harness.admin().await;
19+
let revoked = harness.admin().await;
20+
service
21+
.revoke_administrator(&cli(), revoked.user_id)
22+
.await
23+
.expect("revoke");
24+
let stale = Utc::now() - Duration::minutes(10);
25+
let step_up = StepUpRequirement::passkey_within(CONFIRMATION_MAX_AGE);
26+
for (operator, refusal) in [
27+
(operator(revoked, Utc::now()), AdminError::NotAdministrator),
28+
(operator(admin, stale), AdminError::StepUpRequired(step_up)),
29+
] {
30+
let refused = service
31+
.rotate_signing_key(&operator, &keys, true)
32+
.await
33+
.expect_err("rotate");
34+
assert_refused(&refused, &refusal, "rotate");
35+
}
36+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod administrators;
1717
mod deliveries;
1818
mod handles;
1919
mod invitations;
20+
mod keys;
2021
mod mutations;
2122
mod reads;
2223

‎apps/auth-service/src/admin/tests/reads.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl AdminOperation {
4848
],
4949
Self::ListAdministrators => vec![service.list_administrators(operator).await.map(drop)],
5050
Self::CheckHandles => vec![service.check_handles(operator).await.map(drop)],
51+
Self::ListSigningKeys => vec![service.list_signing_keys(operator).await.map(drop)],
5152
Self::ListDeliveries => vec![
5253
service
5354
.list_deliveries(operator, None, None, 1)
@@ -98,7 +99,10 @@ impl AdminOperation {
9899
| Self::RetryDelivery
99100
| Self::CancelDelivery
100101
| Self::RecoverAccount
101-
| Self::UndoRecovery => return None,
102+
| Self::UndoRecovery
103+
| Self::RotateSigningKey
104+
| Self::RevokeSigningKey
105+
| Self::ImportSigningKey => return None,
102106
})
103107
}
104108
}

‎apps/auth-service/src/cli/keys.rs‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! Signing keys, token digest keys and the audit key. None needs the HTTP
22
//! service, and every replica picks up a signing key change within a minute.
3+
//! Signing key commands run their admin operation, as the dashboard's signing
4+
//! keys page does.
35
4-
use super::CliError;
5-
use crate::{AuditConfig, AuthConfig, KeyStore, Operator, PUBLIC_BASE_URL, TokenDigestKeys};
6+
use super::{CliError, Console};
7+
use crate::{
8+
AuditConfig, AuthConfig, KeyStore, PUBLIC_BASE_URL, TokenDigestKeys, admin::AdminOperation,
9+
};
610
use chrono::{DateTime, Utc};
711
use clap::Subcommand;
812
use piquel_common::{config::SecretReference, protocol::jwt::KeyId};
@@ -54,21 +58,39 @@ pub(super) enum KeysCommand {
5458
}
5559

5660
impl KeysCommand {
57-
/// Runs this command on `database`.
61+
/// The admin operation this command runs, if any. Checking token digest keys
62+
/// and printing the audit key's verifier read the deployment's configuration,
63+
/// which operators change outside auth, so neither is one.
64+
pub(super) const fn operation(&self) -> Option<AdminOperation> {
65+
Some(match self {
66+
Self::List => AdminOperation::ListSigningKeys,
67+
Self::Rotate { .. } => AdminOperation::RotateSigningKey,
68+
Self::Revoke { .. } => AdminOperation::RevokeSigningKey,
69+
Self::Import { .. } => AdminOperation::ImportSigningKey,
70+
Self::DigestUsage | Self::Audit => return None,
71+
})
72+
}
73+
74+
/// Runs this command on `database`, a signing key's as the operator at this
75+
/// terminal.
5876
pub(super) async fn run(self, database: Database) -> Result<(), CliError> {
5977
let store = || -> Result<KeyStore, CliError> {
6078
Ok(KeyStore::new(
6179
database.clone(),
6280
Arc::new(AuthConfig::key_encryption_key_from_environment()?),
6381
))
6482
};
83+
let console = || Console::new(database.clone());
6584
match self {
6685
Self::List => {
86+
let Console {
87+
service, operator, ..
88+
} = &console()?;
6789
let format = |at: Option<DateTime<Utc>>| {
6890
at.map_or_else(|| "-".to_owned(), |at| at.to_rfc3339())
6991
};
7092
println!("ID\tTYPE\tSTATE\tCREATED\tACTIVATED\tDEACTIVATED\tRETIRED");
71-
for key in database.signing_keys().list().await? {
93+
for key in service.list_signing_keys(operator).await? {
7294
println!(
7395
"{}\t{}\t{}\t{}\t{}\t{}\t{}",
7496
key.id,
@@ -82,14 +104,21 @@ impl KeysCommand {
82104
}
83105
}
84106
Self::Rotate { now } => {
85-
let id = store()?.rotate(&Operator::terminal()?, now).await?;
107+
let Console {
108+
service, operator, ..
109+
} = &console()?;
110+
let id = service.rotate_signing_key(operator, &store()?, now).await?;
86111
println!("{id}");
87112
}
88113
Self::Revoke { id } => {
89-
if let Some(replacement) = store()?.revoke(&Operator::terminal()?, &id).await? {
90-
eprintln!("Key {id} revoked; key {replacement} signs from now on.");
91-
} else {
92-
eprintln!("Key {id} revoked.");
114+
let Console {
115+
service, operator, ..
116+
} = &console()?;
117+
match service.revoke_signing_key(operator, &store()?, &id).await? {
118+
Some(replacement) => {
119+
eprintln!("Key {id} revoked; key {replacement} signs from now on.");
120+
}
121+
None => eprintln!("Key {id} revoked."),
93122
}
94123
}
95124
Self::DigestUsage => {
@@ -110,10 +139,13 @@ impl KeysCommand {
110139
println!("{}", config.verifier());
111140
}
112141
Self::Import { pem, id } => {
142+
let Console {
143+
service, operator, ..
144+
} = &console()?;
113145
let pem = pem.resolve().map_err(CliError::PemUnreadable)?;
114146
let key =
115147
Rs256Key::from_pem(id.as_str(), pem.utf8()?).map_err(CliError::InvalidPem)?;
116-
if store()?.import(&Operator::terminal()?, key).await? {
148+
if service.import_signing_key(operator, &store()?, key).await? {
117149
eprintln!("Key {id} imported; it signs from now on.");
118150
} else {
119151
eprintln!("Signing keys already exist; nothing was imported.");

0 commit comments

Comments
 (0)