Let a shared vault arrive, a bucket be found, and a vault be deleted

Three things a user reported, one of which was a real bug and one of which was
not the bug it looked like.

**A vault shared with somebody never reached their machine.** The grant was
correct at both ends: the sharing client verified the recipient's key against the
key log and wrapped every generation to it, the server stored it, and /me would
have returned it. Nothing asked. VaultSession.RefreshVaultsAsync — the method
whose own summary says it is "called after a share and on a periodic pass" — had
no caller anywhere in the application, so the vault list was whatever the last
browser sign-in cached. A restart did not help: an offline unlock reads that same
cache. The vault appeared only if the recipient happened to sign in through the
browser again, which is why this looked like sharing being broken rather than
like a list that was never re-read.

So every synchronisation pass now re-reads it, before it syncs. SyncOnceAsync
takes the whole server rather than its sync half for that reason, and the order
matters: a vault admitted by the refresh is one that same pass then pulls, where
the other order would show a newly shared vault as an empty one until the minute
after. The shell is told only when the set actually changed — it rebuilds the tab
strip's vault menu from the session's list, and doing that on every quiet pass
would rebuild a menu once a minute for nothing.

The test needed the fake server to be able to do something no test here had
needed before: hand this account a vault it did not make. ShareVaultWithMe wraps
a real key to the encryption key this account enrolled, so the keyring opens it
exactly as it opens a real colleague's — a helper that filled the field with
bytes would let a vault appear in the list and never prove it could be read.

**Adding an S3 bucket on the desktop works, and could not be found.** The report
was that it is not possible; driving the real XAML headlessly says otherwise —
Keychain, + BUCKET, and the editor saves. What is true is that S3 is where
somebody goes looking, and from there SELECT BUCKET opened a combo box with
nothing in it and no sentence anywhere saying that a bucket is a keychain item.
From where the user was standing that is indistinguishable from an application
with no way to add one.

The empty state now says what a bucket is and offers a button that lands on the
keychain with the editor already open — navigating to the screen and leaving
+ BUCKET to be found among five buttons would be most of the same problem. The
phone gets the sentence and no button: its keychain screen reads and deletes and
edits nothing, so there is no editor to send anybody to, and naming the machine
that has one beats an empty control that reads as a screen still loading.

The keychain screen's layout test grew the two categories it never covered.
Tags and buckets arrived after it was written, and the header strip it measures
is one that has overflowed twice before.

**A vault can now be deleted.** DELETE /api/v1/vaults/{id}, gated on Admin —
the line the rename already drew, for a stronger version of its reason, since
this takes the vault from everybody in it at once. The row is soft-deleted and
every grant to it withdrawn in one write; VaultAccessService filters on the stamp
at both ends, so from that moment the vault is absent from every member's /me and
every call naming it answers 404. Their clients notice on the pass described
above.

The team behind it is archived when it owned nothing else, which is the mirror of
renaming it: a vault made from the vaults screen gets a team named after it that
nobody was ever shown, and leaving that behind would leave a membership list no
screen has a row for. That is a second call rather than one transaction —
archiving is TeamService's, it refuses while a team owns vaults, and it can only
tell that this one no longer does once the deletion is committed. A crash between
the two leaves an empty team: invisible, archivable afterwards, harmless, and a
better failure than a vault that could not be deleted because tidying up after it
did not work.

Two refusals worth stating. The personal vault cannot be deleted at either end:
it is created by enrollment, everything filed nowhere else lives in it, and no
call would make another. And the items are kept — ciphertext behind a vault
nothing will resolve, so deleting them buys no confidentiality while destroying
what an operator undoing a mistake would need.

The client drops the key from the keyring and the row from the cache rather than
waiting for a refresh, so the list is right immediately; the items stay, as they
stay for a vault whose grant was withdrawn, because a copy is on every other
member's machine too and removing these rows would be the client pretending to a
reach it does not have. The confirmation says that out loud before it is
answered. It is the one sentence this screen must not leave implied: deletion is
no more retroactive than revocation is. See ADR 0001.

Desktop only, deliberately. The Android vaults screen offers no rename and no
hand-over either, so adding delete alone there would be the one destructive vault
operation on a screen with no other.

Three places asserted that a vault can never be deleted — TeamService's refusal
message, the TeamNotEmpty problem code, and ADR 0009 — and each now names the
route instead.
This commit is contained in:
2026-08-04 15:34:40 +02:00
parent a0568d4c35
commit e9cea2ccbc
26 changed files with 1181 additions and 41 deletions
@@ -233,16 +233,38 @@ internal sealed record VaultInvitationRowViewModel(TeamInvitationSummary Invitat
/// than read from the selection at confirm time — otherwise selecting a different row between arming
/// and confirming would apply the answer to something else.
/// </remarks>
/// <param name="Kind">Which operation the answer applies to.</param>
/// <param name="TeamId">The membership list the action is aimed at.</param>
/// <param name="MemberId">The member it is aimed at.</param>
/// <param name="MemberId">The member it is aimed at, or empty where it is not aimed at one.</param>
/// <param name="VaultId">The vault it is aimed at.</param>
/// <param name="Question">What is being asked.</param>
/// <param name="Consequence">What will actually happen, stated honestly.</param>
internal sealed record VaultActionRequest(
VaultActionKind Kind,
Guid TeamId,
Guid MemberId,
Guid VaultId,
string Question,
string Consequence);
/// <summary>Which destructive operation a confirmation is standing in front of.</summary>
/// <remarks>
/// Carried on the request rather than inferred from which fields are set. There were two of these the
/// moment deletion existed, and a confirm handler that guessed from a member id being empty would be one
/// refactor away from carrying out the wrong one of the two.
/// </remarks>
internal enum VaultActionKind
{
/// <summary>Not a legal value.</summary>
Unspecified = 0,
/// <summary>Hand the vault's membership list to somebody else.</summary>
HandOver = 1,
/// <summary>Delete the vault.</summary>
Delete = 2,
}
/// <summary>
/// The vaults screen: which vaults there are, who is in each, and who holds a key to it.
/// </summary>
@@ -414,6 +436,16 @@ internal sealed partial class VaultsViewModel(
/// <summary>Whether the selected vault is the personal one.</summary>
internal bool SelectedIsPersonal => SelectedVault?.IsPersonal == true;
/// <summary>
/// Whether the selected vault is one this account may delete.
/// </summary>
/// <remarks>
/// Narrower than <see cref="CanAdministerSelected"/> by exactly the personal vault, which cannot be
/// deleted by anybody: it is where everything filed nowhere else lives and nothing can make another.
/// The server refuses one too, so a button offered here would be a button that leads to a refusal.
/// </remarks>
internal bool CanDeleteSelected => SelectedVault is { IsPersonal: false, CanAdminister: true };
/// <summary>Whether there is anything to show beside the vault list.</summary>
internal bool HasSelection => SelectedVault is not null;
@@ -1230,13 +1262,70 @@ internal sealed partial class VaultsViewModel(
}
PendingAction = new VaultActionRequest(
VaultActionKind.HandOver,
teamId,
member.UserId,
vault.VaultId,
$"Hand '{vault.Name}' to {member.Name}?",
"They become its owner and you become an admin. You will not be able to take it back "
+ "yourself — only the new owner can hand it on. Your key to it is untouched.");
}
/// <summary>
/// Arms the deletion confirmation for the selected vault.
/// </summary>
/// <remarks>
/// <para>
/// The consequence is spelled out at length rather than summarised, and every sentence in it is one
/// somebody could otherwise be surprised by afterwards. The last is the one this product must never
/// leave implied: deleting a vault does not reach the machines it has already synced to. That is the
/// same limit revocation has, for the same reason, and it is written down in ADR 0001.
/// </para>
/// <para>
/// The personal vault is refused here as well as by the server. A button that reached a refusal would
/// be teaching somebody to try things and read errors, and the reason is a fact this screen knows.
/// </para>
/// </remarks>
[RelayCommand]
private void DeleteVault()
{
if (SelectedVault is not { } vault)
{
return;
}
if (vault.IsPersonal)
{
Status = "Your personal vault cannot be deleted. It is where everything filed nowhere else "
+ "lives, and there is no way to make another.";
return;
}
if (vault.TeamId is not { } teamId)
{
return;
}
var others = Members.Count(member => !member.IsSelf);
var shared = others > 0
? string.Create(
CultureInfo.CurrentCulture,
$" {others} other member(s) lose it at the same moment, without being asked.")
: string.Empty;
PendingAction = new VaultActionRequest(
VaultActionKind.Delete,
teamId,
Guid.Empty,
vault.VaultId,
$"Delete '{vault.Name}'?",
$"Everything in it goes: its hosts, keys, passwords, snippets and buckets stop being readable "
+ $"by anybody, including you, and nothing here can undo it.{shared} What it cannot do is "
+ "reach a machine that has already synced this vault — a copy pulled yesterday is still "
+ "there. Rotate the credentials that mattered.");
}
/// <summary>Cancels an armed action.</summary>
[RelayCommand]
private void CancelAction() => PendingAction = null;
@@ -1258,22 +1347,71 @@ internal sealed partial class VaultsViewModel(
PendingAction = null;
await RunAsync(async () =>
await RunAsync(() => request.Kind switch
{
await server.Teams
.TransferTeamOwnershipAsync(
request.TeamId,
new TransferTeamOwnershipRequest(request.MemberId),
cancellationToken)
.ConfigureAwait(true);
await ReloadAsync(cancellationToken).ConfigureAwait(true);
Status = "Handed over. You are an admin of this vault now, and only its new owner can hand "
+ "it on again.";
VaultActionKind.Delete => DeleteAsync(server, request, cancellationToken),
_ => HandOverAsync(server, request, cancellationToken),
}).ConfigureAwait(true);
}
private async Task HandOverAsync(
IVaultServer server,
VaultActionRequest request,
CancellationToken cancellationToken)
{
await server.Teams
.TransferTeamOwnershipAsync(
request.TeamId,
new TransferTeamOwnershipRequest(request.MemberId),
cancellationToken)
.ConfigureAwait(true);
await ReloadAsync(cancellationToken).ConfigureAwait(true);
Status = "Handed over. You are an admin of this vault now, and only its new owner can hand "
+ "it on again.";
}
/// <summary>
/// Deletes the vault the confirmation was armed for.
/// </summary>
/// <remarks>
/// <para>
/// The name is read before the call, because afterwards there is no row to read it from and the
/// sentence this ends with is about a vault that no longer exists.
/// </para>
/// <para>
/// The rest of the shell is told, as a rename tells it: the tab strip's vault menu, the file-this-into
/// picker and every host list are built from the session's vault list, and all of them are a vault out
/// of date the moment one goes.
/// </para>
/// </remarks>
private async Task DeleteAsync(
IVaultServer server,
VaultActionRequest request,
CancellationToken cancellationToken)
{
if (session() is not { } open)
{
Status = "Unlock your keychain first: deleting a vault gives up this machine's key to it.";
return;
}
var name = Vaults.FirstOrDefault(row => row.VaultId == request.VaultId)?.Name ?? "That vault";
var deleted = await open
.DeleteVaultAsync(server.Grants, request.VaultId, cancellationToken)
.ConfigureAwait(true);
await ReloadAsync(cancellationToken).ConfigureAwait(true);
await NotifyVaultsChangedAsync(cancellationToken).ConfigureAwait(true);
Status = deleted
? $"Deleted '{name}'. Everybody's key to it is withdrawn. What anybody had already synced is "
+ "still on their machine — rotate the credentials that mattered."
: $"'{name}' was already gone. Somebody else deleted it, or your access to it ended.";
}
/// <summary>
/// Removes somebody, revoking their grants and rotating the vaults they could read.
/// </summary>
@@ -1629,6 +1767,7 @@ internal sealed partial class VaultsViewModel(
OnPropertyChanged(nameof(OwnsSelected));
OnPropertyChanged(nameof(SelectedIsShared));
OnPropertyChanged(nameof(SelectedIsPersonal));
OnPropertyChanged(nameof(CanDeleteSelected));
OnPropertyChanged(nameof(HasInvitations));
OnPropertyChanged(nameof(SharedMembershipWarning));
OnPropertyChanged(nameof(HasSharedMembershipWarning));