fix(adminui): #1050 Galaxy ack identity gets an explicit 'Empty password' option

A blank password box means 'keep the stored password' (#997 A-4) and is refused first time,
so an account whose password is genuinely empty could not be mapped. The /apikeys editor
now has an 'Empty password' checkbox (disables + clears the box) that calls the new
IApiKeyGalaxyAckIdentityService.SetWithEmptyPasswordAsync: writes an empty password secret
first, then the user, audited like any set. The driver already accepts an empty password.
This commit is contained in:
Joseph Doherty
2026-12-03 15:03:27 -05:00
parent 4a6dfe04b3
commit 65212dd471
5 changed files with 104 additions and 7 deletions
+4 -1
View File
@@ -591,7 +591,10 @@ without one and anonymous sessions use the Galaxy driver's `AlarmAck` fallback a
neither the ack is refused before it reaches the gateway. Deleting a key on `/apikeys` removes its
identity (if the Secrets store is down at that moment the list still refreshes and the error names the two
leftover secrets to remove by hand). Re-saving an existing identity with the password box **blank keeps the
stored password** (the editor never renders it back); a first-time save needs a password (#997 A-4/A-9). See [docs/drivers/Galaxy.md § Alarm acknowledge credential](drivers/Galaxy.md#alarm-acknowledge-credential).
stored password** (the editor never renders it back); a first-time save needs a password (#997 A-4/A-9). A Galaxy
account whose password is genuinely empty is stored with the editor's explicit **Empty password** checkbox
(`IApiKeyGalaxyAckIdentityService.SetWithEmptyPasswordAsync`, #1050) — it writes an empty password secret
(the driver sends an empty `operator_password`; an *absent* password secret is still a refusal). See [docs/drivers/Galaxy.md § Alarm acknowledge credential](drivers/Galaxy.md#alarm-acknowledge-credential).
### Anonymous is a normal principal
@@ -35,6 +35,19 @@ public interface IApiKeyGalaxyAckIdentityService
/// <returns>A task representing the operation.</returns>
Task SetAsync(string apiKeyId, string user, string? domain, string? password, string actor, CancellationToken ct);
/// <summary>
/// Sets (or replaces) a key's Galaxy ack identity with an EMPTY password (#1050). Galaxy accounts can have
/// empty passwords, but <see cref="SetAsync"/> reads a blank password as "keep the stored one" (and refuses it
/// first time), so storing an empty password needs this explicit call.
/// </summary>
/// <param name="apiKeyId">The public key id.</param>
/// <param name="user">Galaxy user; required.</param>
/// <param name="domain">Optional domain.</param>
/// <param name="actor">The admin performing the change, for audit.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>A task representing the operation.</returns>
Task SetWithEmptyPasswordAsync(string apiKeyId, string user, string? domain, string actor, CancellationToken ct);
/// <summary>Removes a key's Galaxy ack identity (no-op when none).</summary>
/// <param name="apiKeyId">The public key id.</param>
/// <param name="actor">The admin performing the change, for audit.</param>
@@ -97,8 +110,16 @@ public sealed class ApiKeyGalaxyAckIdentityService : IApiKeyGalaxyAckIdentitySer
}
/// <inheritdoc />
public async Task SetAsync(
public Task SetAsync(
string apiKeyId, string user, string? domain, string? password, string actor, CancellationToken ct)
=> SetCoreAsync(apiKeyId, user, domain, password, emptyPassword: false, actor, ct);
/// <inheritdoc />
public Task SetWithEmptyPasswordAsync(string apiKeyId, string user, string? domain, string actor, CancellationToken ct)
=> SetCoreAsync(apiKeyId, user, domain, password: null, emptyPassword: true, actor, ct);
private async Task SetCoreAsync(
string apiKeyId, string user, string? domain, string? password, bool emptyPassword, string actor, CancellationToken ct)
{
user = (user ?? string.Empty).Trim();
if (user.Length == 0) throw new ArgumentException("A Galaxy user is required.", nameof(user));
@@ -108,14 +129,23 @@ public sealed class ApiKeyGalaxyAckIdentityService : IApiKeyGalaxyAckIdentitySer
var userName = new SecretName(GalaxyAckIdentitySecrets.UserSecretName(apiKeyId));
var passwordName = new SecretName(GalaxyAckIdentitySecrets.PasswordSecretName(apiKeyId));
if (string.IsNullOrEmpty(password))
if (emptyPassword)
{
// #1050: the explicit "this account has an empty password" option. Written like any new password —
// password FIRST, so a concurrent ack never pairs the new user with a missing password.
await UpsertAsync(passwordName, string.Empty, $"Galaxy ack password (empty) for API key {apiKeyId}", actor, ct)
.ConfigureAwait(false);
}
else if (string.IsNullOrEmpty(password))
{
// The editor never renders a stored password back, so a blank box means "keep the current one" -
// overwriting it with an empty value would silently break every ack on this key (#997 A-4). With no
// existing identity there is nothing to keep, so a blank password is refused instead (as is a half-configured identity whose password secret is gone).
var existing = await _store.GetAsync(passwordName, ct).ConfigureAwait(false);
if (existing is null || existing.IsDeleted)
throw new ArgumentException("A password is required when setting a Galaxy ack identity.", nameof(password));
throw new ArgumentException(
"A password is required when setting a Galaxy ack identity (for an account whose password is empty, " +
"tick \"Empty password\").", nameof(password));
}
else
{
@@ -78,8 +78,13 @@
<div class="col-md-3">
<label class="form-label" for="ack-password">Password</label>
<input id="ack-password" type="password" class="form-control form-control-sm" @bind="_ackPassword"
placeholder="@(_ackIdentities.ContainsKey(_ackEditKeyId) ? "leave blank to keep the current password" : null)"
autocomplete="new-password" />
placeholder="@(_ackEmptyPassword ? "(empty password)" : _ackIdentities.ContainsKey(_ackEditKeyId) ? "leave blank to keep the current password" : null)"
disabled="@_ackEmptyPassword" autocomplete="new-password" />
<div class="form-check mt-1">
<input id="ack-empty-password" type="checkbox" class="form-check-input" @bind="_ackEmptyPassword" @bind:after="OnAckEmptyPasswordChanged" />
<label class="form-check-label" for="ack-empty-password">Empty password</label>
</div>
<div class="form-text">The account's password is genuinely empty (a blank box keeps the stored password).</div>
</div>
<div class="col-md-3 d-flex align-items-end gap-2">
<button class="btn btn-sm btn-primary" @onclick="SaveAckIdentityAsync" disabled="@_busy">Save</button>
@@ -191,6 +196,8 @@
private string _ackUser = "";
private string _ackDomain = "";
private string _ackPassword = "";
// #1050: explicit "the account's password is empty" — a blank box alone means "keep the stored password".
private bool _ackEmptyPassword;
private string _newName = "";
private string _newPrincipal = "";
private DateTime? _newExpires;
@@ -320,6 +327,7 @@
{
_ackEditKeyId = apiKeyId;
_ackPassword = "";
_ackEmptyPassword = false;
if (_ackIdentities.TryGetValue(apiKeyId, out var current))
{
var slash = current.IndexOf('\\');
@@ -339,6 +347,13 @@
_ackUser = "";
_ackDomain = "";
_ackPassword = "";
_ackEmptyPassword = false;
}
// A typed password and "Empty password" are mutually exclusive: ticking the box discards what was typed.
private void OnAckEmptyPasswordChanged()
{
if (_ackEmptyPassword) _ackPassword = "";
}
private async Task SaveAckIdentityAsync()
@@ -348,7 +363,10 @@
_error = null;
try
{
await AckIdentities.SetAsync(id, _ackUser, _ackDomain, _ackPassword, await ActorAsync(), default);
if (_ackEmptyPassword)
await AckIdentities.SetWithEmptyPasswordAsync(id, _ackUser, _ackDomain, await ActorAsync(), default);
else
await AckIdentities.SetAsync(id, _ackUser, _ackDomain, _ackPassword, await ActorAsync(), default);
CloseAckEditor();
await ReloadAsync();
}
@@ -124,6 +124,49 @@ public sealed class ApiKeyGalaxyAckIdentityServiceTests
_store.Rows.ShouldBeEmpty();
}
/// <summary>
/// #1050: Galaxy accounts can have empty passwords, and a blank box means "keep", so storing an EMPTY password
/// needs its own explicit option — first-time (where blank is refused) and over an existing password.
/// </summary>
[Fact]
public async Task SetWithEmptyPassword_stores_an_empty_password_first_time()
{
var ct = TestContext.Current.CancellationToken;
await Service().SetWithEmptyPasswordAsync(KeyId, "alice", "CORP", "admin", ct);
_cipher.Decrypt(_store.Rows[GalaxyAckIdentitySecrets.PasswordSecretName(KeyId)]).ShouldBe(string.Empty);
_cipher.Decrypt(_store.Rows[GalaxyAckIdentitySecrets.UserSecretName(KeyId)]).ShouldBe("CORP\\alice");
_store.UpsertOrder.ShouldBe([GalaxyAckIdentitySecrets.PasswordSecretName(KeyId), GalaxyAckIdentitySecrets.UserSecretName(KeyId)]);
_invalidator.Invalidated.ShouldContain(GalaxyAckIdentitySecrets.PasswordSecretName(KeyId));
_audit.Events.ShouldHaveSingleItem().Action.ShouldBe("apikey.galaxy-ack-identity.set");
}
[Fact]
public async Task SetWithEmptyPassword_replaces_a_stored_password_and_a_later_blank_keeps_it_empty()
{
var svc = Service();
var ct = TestContext.Current.CancellationToken;
await svc.SetAsync(KeyId, "alice", "CORP", Password, "admin", ct);
await svc.SetWithEmptyPasswordAsync(KeyId, "alice", "CORP", "admin", ct);
_cipher.Decrypt(_store.Rows[GalaxyAckIdentitySecrets.PasswordSecretName(KeyId)]).ShouldBe(string.Empty);
// A later edit with a blank box keeps the (empty) password rather than refusing — it exists.
await svc.SetAsync(KeyId, "alice", "NEWDOM", null, "admin", ct);
_cipher.Decrypt(_store.Rows[GalaxyAckIdentitySecrets.PasswordSecretName(KeyId)]).ShouldBe(string.Empty);
_cipher.Decrypt(_store.Rows[GalaxyAckIdentitySecrets.UserSecretName(KeyId)]).ShouldBe("NEWDOM\\alice");
}
[Theory]
[InlineData("")]
[InlineData("CORP\\alice")]
public async Task SetWithEmptyPassword_validates_the_user_like_SetAsync(string user)
{
await Should.ThrowAsync<ArgumentException>(() => Service().SetWithEmptyPasswordAsync(KeyId, user, null, "admin", default));
_store.Rows.ShouldBeEmpty();
}
[Fact]
public async Task Set_rejects_a_malformed_key_id()
{
@@ -108,6 +108,9 @@ public sealed class ApiKeysDeleteTests : BunitContext
public Task SetAsync(string apiKeyId, string user, string? domain, string? password, string actor, CancellationToken ct) =>
throw new NotSupportedException();
public Task SetWithEmptyPasswordAsync(string apiKeyId, string user, string? domain, string actor, CancellationToken ct) =>
throw new NotSupportedException();
public Task ClearAsync(string apiKeyId, string actor, CancellationToken ct)
{
ClearCalls++;