A node may move a port a module publishes as a mapping's machine side
A module publishing `2222:22` — the machine's own ssh daemon holds 22, so the module takes 2222 and says so in `listens` — could not be moved. The setting was read against the last segment of each mapping alone, so the number the module uses everywhere else was refused as a port it does not publish, and the node's every push failed for as long as the setting was stored. The one key that was accepted, the container's own port, was then read only when the container's mapping was rewritten: the mapping moved and the ports map, the filter, the adopted node's openings, its guard and what a consumer is told all stayed on the number the software had left. Either end of a mapping now names it, and a given port comes back under both, so every reader finds the same number under the key it holds. Ambiguity is refused where it is real — one number naming two different mappings, or the two ends of one mapping given two different numbers.
This commit is contained in:
@@ -272,3 +272,82 @@ func TestTheGuardIsSentForTakenModulesOnly(t *testing.T) {
|
||||
}
|
||||
t.Fatal("a taken store is not guarded")
|
||||
}
|
||||
|
||||
// novox/hq ADR 0038 and 0100: a module may publish a port the long way — `2222:22`, because the
|
||||
// machine's own ssh daemon holds 22 — and say it listens on the machine side of that mapping,
|
||||
// which is the number anything reaching it dials. A node moves that port by naming it, and the
|
||||
// number has to reach everything derived from it at once: what the runtime is handed, what an
|
||||
// adopted node is told to open, what its guard refuses, and what a consumer elsewhere dials.
|
||||
//
|
||||
// It reached none of them. The setting was refused outright for naming the machine side — so a
|
||||
// module's port could not be put back where the machine it replaces had it, and, worse, the
|
||||
// node's every push failed for as long as the setting existed.
|
||||
func TestTheMachineSideOfAMappingIsMovedEverywhereTheNumberIsUsed(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
register(t, open, catalogue.Manifest{Module: "forge", Version: "1",
|
||||
Provides: []catalogue.Offer{{Name: "git-over-ssh", Scope: catalogue.ScopeMesh}},
|
||||
Serves: map[string]map[string]any{"git-over-ssh": {"port": 2222}},
|
||||
Listens: []catalogue.Listening{{Port: 2222, From: catalogue.FromMesh}},
|
||||
Resources: []map[string]any{{"id": "server", "type": "container", "name": "forge",
|
||||
"ports": []any{"2222:22"},
|
||||
"image": "registry.example/forge@sha256:" + strings.Repeat("c", 64)}}})
|
||||
register(t, open, catalogue.Manifest{Module: "app", Version: "1",
|
||||
Requires: []string{"git-over-ssh"}})
|
||||
if err := open.inventory.SetAdopted(ctx, "anchor", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := assign(ctx, open, "anchor", "forge"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := assign(ctx, open, "laptop", "app"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := open.inventory.Take(ctx, "anchor", "forge"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := open.inventory.SetSettings(ctx, "anchor", "forge",
|
||||
map[string]any{catalogue.PortsSetting: map[string]any{"2222": 222}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resources := composed(t, open, "anchor").Resources
|
||||
var container, opening map[string]any
|
||||
for _, r := range resources {
|
||||
switch r["id"] {
|
||||
case "forge.server":
|
||||
container = r
|
||||
case catalogue.OpeningID("tcp", 222, catalogue.PathForwarded):
|
||||
opening = r
|
||||
}
|
||||
if id, _ := r["id"].(string); strings.HasPrefix(id, "adoption.opening-tcp-2222-") {
|
||||
t.Errorf("the adopted node is told to open the port the forge was moved off: %s", id)
|
||||
}
|
||||
}
|
||||
if container == nil || !reflect.DeepEqual(container["ports"], []any{"222:22"}) {
|
||||
t.Fatalf("the forge's container publishes %v", container["ports"])
|
||||
}
|
||||
if opening == nil || opening["to"] != 22 || opening["from"] != catalogue.OpeningFromMesh {
|
||||
t.Fatalf("no opening for the port this node gave the forge: %v", opening)
|
||||
}
|
||||
for _, r := range resources {
|
||||
if r["id"] == catalogue.GuardID() && r["content"] != catalogue.AsGuard([]int{222}) {
|
||||
t.Fatalf("the guard does not refuse the port the forge is on:\n%s", r["content"])
|
||||
}
|
||||
}
|
||||
|
||||
// And the consumer on the other machine dials the same number.
|
||||
plan, _, err := planFor(ctx, open, "laptop")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var told any
|
||||
for _, n := range plan.Needs {
|
||||
if n.Name == "git-over-ssh" {
|
||||
told = n.Serves["port"]
|
||||
}
|
||||
}
|
||||
if told != 222 {
|
||||
t.Fatalf("the consumer is told the forge answers on %v", told)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user