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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user