Public Access
Bind an SSH key to a host instead of picking one per connection
A host now names the key it authenticates with, or none, as a field in its encrypted payload — so the choice follows the host to every machine rather than being made again each time somebody connects. The per-connection "Use key" switch it replaces was a stopgap for not having this, and keeping both would have left two mechanisms answering one question. This is the first payload schema version bump, and it does not work the obvious way. A host is written at the *lowest* schema version that can represent it: one that binds a key is written at 2, one that does not is still written at 1, byte for byte as it was before the field existed. The version is what makes an older client refuse to edit an item, so stamping 2 unconditionally would mean upgrading a single machine and renaming a single host made that host uneditable on every machine that had not upgraded yet. Confining the cost to the hosts that actually use the field is the difference between a team noticing a bump and a team being blocked by one. HostSecretCodec states the rule so the next field added follows it, and a test pins the version-1 bytes against a literal rather than against the codec, because the claim is about history: every host already in every vault has to re-encode to what it encoded before, or the first sync after an upgrade would push the whole vault as changed. A binding is an item id, not a copy of the key — a second copy of a private key is one that goes stale — which means the reference can dangle when the key is deleted on another machine. Both places that meets are handled the same way, by refusing rather than falling back: - Connecting to a host whose key is gone is refused outright. A host somebody deliberately set up for key-only access must not quietly start offering a password. - Opening such a host in the editor keeps the binding, selected, labelled as missing. The quieter version of the same failure is someone editing the port and saving, silently converting the host to password authentication with nothing ever having said so. Two things this found by being falsified: - The merge was untested for the new field, and "just take the server's value" passed the entire suite — a local binding change would have been discarded with no conflict recorded. HostSecretMergeTests already had a test written for exactly this class of omission; it simply had not been extended. - Adding a nullable field exposed a defect in HostSecretMerge.Field: it short-circuited when the discarded value was null, so the formatter never ran for the one case where null is a value rather than an absence, and a field whose absence has a name could not report it. Now the formatter always runs, and "no key" appears in the conflict log where an empty string used to. Also fixes eight nullable warnings in SyncEndpointTests left by the server-side SSH key commit, which had omitted the null-forgiving operator the rest of that file uses. They were invisible until an unrelated change forced the project to recompile. The end-to-end slice now binds its host to its key, so a schema-version-2 payload goes through the real API, the real PostgreSQL and back out on a second machine. 745 tests green. Zero warnings, dotnet format clean.
This commit is contained in:
@@ -55,6 +55,7 @@ public sealed class HostSecretMergeTests
|
||||
JumpHostIds = JumpChain.Create([Bastion]),
|
||||
Options = HostOptions.Create([new HostOption("Compression", "yes")]),
|
||||
RelayEnabled = true,
|
||||
SshKeyId = DeployKey,
|
||||
};
|
||||
|
||||
var result = HostSecretMerge.Merge(ancestor, local, ancestor);
|
||||
@@ -63,6 +64,59 @@ public sealed class HostSecretMergeTests
|
||||
result.HasConflicts.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARemovedKeyBinding_IsNotResurrectedByTheOtherSide()
|
||||
{
|
||||
// The other direction, and the one a two-way diff gets wrong: null is a value here, not an absence.
|
||||
// A host deliberately put back on a password must not silently regain its key because the server's
|
||||
// copy still names one.
|
||||
var ancestor = Host(sshKeyId: DeployKey);
|
||||
var local = ancestor with { SshKeyId = null };
|
||||
|
||||
var result = HostSecretMerge.Merge(ancestor, local, ancestor);
|
||||
|
||||
result.Merged.SshKeyId.ShouldBeNull();
|
||||
result.HasConflicts.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoSidesBindingDifferentKeys_NamesBothIdsInTheConflict()
|
||||
{
|
||||
// An id is not a secret — it names a vault item rather than being the key — so both are shown. The
|
||||
// user cannot tell which of two keys was dropped otherwise.
|
||||
var other = Guid.Parse("0192f0c8-4444-7c3d-8e4f-5a6b7c8d9e04");
|
||||
|
||||
var ancestor = Host();
|
||||
var local = ancestor with { SshKeyId = DeployKey };
|
||||
var remote = ancestor with { SshKeyId = other };
|
||||
|
||||
var result = HostSecretMerge.Merge(ancestor, local, remote);
|
||||
|
||||
result.Merged.SshKeyId.ShouldBe(other);
|
||||
|
||||
var conflict = result.Conflicts.ShouldHaveSingleItem();
|
||||
conflict.Field.ShouldBe(nameof(HostSecret.SshKeyId));
|
||||
conflict.Kept.ShouldBe(other.ToString());
|
||||
conflict.Discarded.ShouldBe(DeployKey.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABindingClashingWithItsRemoval_SaysWhichSideHadNoKey()
|
||||
{
|
||||
// "no key" rather than a blank, for the same reason a clashing port is reported as a number: a
|
||||
// conflict entry whose discarded value is empty reads as a bug in the conflict log.
|
||||
var ancestor = Host(sshKeyId: DeployKey);
|
||||
var local = ancestor with { SshKeyId = null };
|
||||
var remote = ancestor with { SshKeyId = Relay };
|
||||
|
||||
var result = HostSecretMerge.Merge(ancestor, local, remote);
|
||||
|
||||
var conflict = result.Conflicts.ShouldHaveSingleItem();
|
||||
conflict.Field.ShouldBe(nameof(HostSecret.SshKeyId));
|
||||
conflict.Kept.ShouldBe(Relay.ToString());
|
||||
conflict.Discarded.ShouldBe("no key");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AClashingScalar_TakesRemoteAndNamesTheFieldItDiscarded()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user