dc0a24f224
v2-ci / unit-tests (push) Failing after 1h8m43s
mxaccessgw 488649c+ acknowledges by AuthenticateUser as the operator and
writing <alarm>.AckMsg, so AcknowledgeAlarmRequest now needs a real Galaxy
operator_user + operator_domain + operator_password. The OPC UA data plane is
API-key/anonymous and carries no Galaxy password, so the driver resolves the
account per ack:
1. the session's API key's Galaxy ack identity, set on AdminUI /apikeys and
held ONLY in the encrypted Secrets store
(otopcua/apikeys/<keyId>/galaxy-ack-{user,password}); a key with a user but
no password secret is refused, never silently downgraded;
2. else the driver instance's AlarmAck fallback account (DriverConfig
FallbackUser/FallbackDomain/FallbackPasswordSecretRef; secret:/${secret:}/
env:/file:/dev: only — a literal is refused);
3. else DriverOperationRefusedException: nothing is sent, never an empty
operator_user. Refusals are excluded from the resilience retry/breaker.
- Pins ZB.MOM.WW.MxGateway.Client/Contracts 0.2.1 -> 0.3.0 (vendored into
nuget-packages/ from the Gitea feed, per the local-mxgw source mapping).
- The session ApiKeyId (not a secret) rides NativeAlarmAck ->
RouteNativeAlarmAck -> RouteAlarmAck -> AlarmAcknowledgeRequest; the password
is resolved in the driver and never travels through actor messages.
- The OPC UA principal + key id are appended to the AckMsg comment
("[OPC UA: <principal>, key <id>]") and logged, so a shared fallback
account does not lose who acknowledged.
- Password never logged: GalaxyAckCredential.ToString omits it, the
acknowledger scrubs it from every gateway message it echoes and withholds
any exception that echoes it; audit rows carry only the key id.
- AdminUI: /apikeys "Ack identity" editor (set/remove; delete-key clears it),
Galaxy driver form gains the fallback section.
- Synchronous OPC UA status for a refusal is follow-up #760 (the native ack
path is fire-and-forget after the Part 9 method returns).
Tests: request mapping (password populated), password absent from logs and
exception text (mutation-checked), key-mapped / fallback / refused paths at
resolver and driver level, breaker non-trip, key-id propagation through node
manager and DriverHostActor, AdminUI service + form round-trip.
Closes #749
70 lines
3.5 KiB
C#
70 lines
3.5 KiB
C#
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
|
|
|
/// <summary>
|
|
/// The Secrets-store naming convention for an API key's Galaxy alarm-ack identity (lmxopcua#749).
|
|
/// Shared by the AdminUI <c>/api-keys</c> page (writer) and the Galaxy driver (reader) so the two can
|
|
/// never disagree on a name.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Both halves live in the encrypted <c>ZB.MOM.WW.Secrets</c> store — nothing about the identity is
|
|
/// written to the config DB or the deployment artifact. The identity secret holds the Galaxy account
|
|
/// as <c>DOMAIN\user</c> or bare <c>user</c>; the password secret holds the password (may be empty —
|
|
/// Galaxy accounts can have empty passwords; an <i>absent</i> password secret is a refusal).
|
|
/// </para>
|
|
/// <para>
|
|
/// ⚠️ Secrets are node-local (optionally Akka-replicated within one mesh). The secret must exist on
|
|
/// the node that serves the OPC UA session and runs the Galaxy driver; on a split admin/driver
|
|
/// topology create it on the driver nodes too (their <c>/admin/secrets</c> page or the
|
|
/// <c>secret</c> CLI) under exactly these names.
|
|
/// </para>
|
|
/// </remarks>
|
|
public static class GalaxyAckIdentitySecrets
|
|
{
|
|
/// <summary>Common prefix for every per-key secret.</summary>
|
|
public const string Prefix = "otopcua/apikeys/";
|
|
|
|
/// <summary>Secret holding the key's Galaxy account (<c>DOMAIN\user</c> or <c>user</c>).</summary>
|
|
/// <param name="apiKeyId">The public API key id.</param>
|
|
/// <returns>The secret name.</returns>
|
|
public static string UserSecretName(string apiKeyId) => $"{Prefix}{Normalize(apiKeyId)}/galaxy-ack-user";
|
|
|
|
/// <summary>Secret holding the key's Galaxy account password.</summary>
|
|
/// <param name="apiKeyId">The public API key id.</param>
|
|
/// <returns>The secret name.</returns>
|
|
public static string PasswordSecretName(string apiKeyId) => $"{Prefix}{Normalize(apiKeyId)}/galaxy-ack-password";
|
|
|
|
/// <summary>Formats a user + optional domain as the identity secret value.</summary>
|
|
/// <param name="user">The Galaxy user name.</param>
|
|
/// <param name="domain">The optional domain.</param>
|
|
/// <returns><c>DOMAIN\user</c> or <c>user</c>.</returns>
|
|
public static string FormatIdentity(string user, string? domain) =>
|
|
string.IsNullOrWhiteSpace(domain) ? user.Trim() : $"{domain.Trim()}\\{user.Trim()}";
|
|
|
|
/// <summary>Splits an identity secret value into user + domain on the first backslash.</summary>
|
|
/// <param name="identity">The stored identity value.</param>
|
|
/// <returns>The user (trimmed) and the domain (empty when none).</returns>
|
|
public static (string User, string Domain) ParseIdentity(string identity)
|
|
{
|
|
var value = (identity ?? string.Empty).Trim();
|
|
var slash = value.IndexOf('\\');
|
|
return slash < 0
|
|
? (value, string.Empty)
|
|
: (value[(slash + 1)..].Trim(), value[..slash].Trim());
|
|
}
|
|
|
|
private static string Normalize(string apiKeyId)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(apiKeyId);
|
|
var id = apiKeyId.Trim().ToLowerInvariant();
|
|
foreach (var c in id)
|
|
{
|
|
// Key ids are lowercase hex (ApiKeySecret.Generate); refuse anything that could change the
|
|
// secret-name path shape (a '/', '..') rather than trusting the caller.
|
|
if (!char.IsAsciiLetterOrDigit(c))
|
|
throw new ArgumentException($"API key id '{apiKeyId}' is not a valid key id.", nameof(apiKeyId));
|
|
}
|
|
return id;
|
|
}
|
|
}
|