From beefcf8dc241968ea7bc50cbb0e3dd24d4444687 Mon Sep 17 00:00:00 2001 From: Ilya Yakelzon Date: Thu, 24 Sep 2026 12:32:23 +0200 Subject: [PATCH 1/3] Decouple adapter runtime_version from the package build version The descriptor advertised the build version as runtime_version and artifacts must require it exactly, so the v0.0.4 -> v0.0.5 upgrade quarantined every box's persisted state and failed every prepare with adapter_failure even though v0.0.5 did not change strategy interpretation. adapter.RuntimeVersionGeneva (0.0.4) is now the engine compatibility version used for the descriptor, steering.Config.RuntimeVersion and artifact checks. It is bumped only when grammar, engine semantics or action behavior change. The package version stays on /healthz, logs and telemetry. --- README.md | 8 +- cmd/geneva-server/run_linux.go | 61 +++++---- .../runtime_version_linux_test.go | 116 ++++++++++++++++++ docs/adapter-v1.md | 14 ++- internal/adapter/types.go | 9 ++ internal/steering/controller.go | 7 +- internal/steering/lifecycle_test.go | 4 +- 7 files changed, 186 insertions(+), 33 deletions(-) create mode 100644 cmd/geneva-server/runtime_version_linux_test.go diff --git a/README.md b/README.md index 83f9eab..a4d2443 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ box. Everything else is exported as metrics (below). | --------------- | --------- | ----------------------------------------------------------- | | `GET /healthz` | both | liveness + mode, engine/verdict/inbound-TCP stats | | `GET /canary` | eval only | per-market captured field-value pool | -| `GET /v1/adapter/descriptor` | both | numeric protocol/schema versions and bounded capabilities | +| `GET /v1/adapter/descriptor` | both | numeric protocol/schema versions, engine compatibility `runtime_version`, and bounded capabilities | | `POST /v1/adapter/verify` | both | validate an artifact and immutable identity without mutation | | `POST /v1/adapter/prepare` | both | persist an identity-bound deployment (256 KiB decoded artifact limit) | | `POST /v1/adapter/activate-for-new-connections` | both | assign future SYNs to a prepared artifact after union staging | @@ -145,6 +145,12 @@ relevant conntracks and SYNs arriving during the sweep before flipping assignment, so a pre-activation half-open SYN retransmission cannot cross the boundary. +The descriptor's `runtime_version` is the engine compatibility version +(`adapter.RuntimeVersionGeneva`), independent of the package version that +`/healthz` reports. It is bumped only when strategy interpretation changes +(grammar, engine semantics, action behavior); see +[docs/adapter-v1.md](docs/adapter-v1.md). + State v2 retains the artifact's exact protocol, schema, and required runtime metadata and revalidates it against the installed descriptor before restart activation. Corrupt, incompatible, or metadata-less v1 state is durably diff --git a/cmd/geneva-server/run_linux.go b/cmd/geneva-server/run_linux.go index 9c6ab91..3f80b8f 100644 --- a/cmd/geneva-server/run_linux.go +++ b/cmd/geneva-server/run_linux.go @@ -14,6 +14,7 @@ import ( "syscall" "time" + "github.com/getlantern/geneva-server/internal/adapter" "github.com/getlantern/geneva-server/internal/canary" "github.com/getlantern/geneva-server/internal/censor" "github.com/getlantern/geneva-server/internal/control" @@ -83,32 +84,10 @@ func runServer(o *runCmd) (runResult error) { // packets the strategy's triggers can match, and nothing at all when the // strategy can match nothing — which is what keeps an unassigned eval box // and a rolled-back prod box off the data path entirely. - ctrl := steering.New(eng, steering.Config{ - Mode: o.Mode, - NFT: nftables.Config{ - Table: o.Table, - Port: o.Port, - OutQueue: o.OutQueue, - InQueue: o.InQueue, - BypassUID: uint32(o.ReinjectBypassUID), - NFTPath: o.NFTPath, - Censor: o.CensorCounters, - }, - EthtoolPath: o.EthtoolPath, - Iface: o.Iface, - - ObserveInbound: o.ObserveInbound, - StateFile: o.AdapterStateFile, - Connections: flowtrack.Counter{}, - MaxGenerations: o.MaxGenerations, - MaxScopedGenerations: o.MaxScopedGenerations, - MaxEveryPacketGenerations: o.MaxEveryPacketGenerations, - RuntimeVersion: version, - Fatal: func(err error) { - log.Error("fatal steering integrity failure", "err", err) - reportFatal(err) - }, - }, slogLogger{l: log}) + ctrl := steering.New(eng, steeringConfig(o, func(err error) { + log.Error("fatal steering integrity failure", "err", err) + reportFatal(err) + }), slogLogger{l: log}) // The inbound censor classifier runs in both modes: a prod box's IP gets // burned the same way a test box's does, and the fleet-wide burn rate is // what sizes the clean-IP budget for exploration. @@ -327,3 +306,33 @@ func runtimeExitError(runErr error, fatalCause <-chan error, serveErr <-chan err } return runErr } + +// steeringConfig maps the run flags onto the steering controller. The adapter +// runtime version is the engine compatibility version, not the package build +// version: artifacts pin it exactly, so tying it to the build would orphan +// every published artifact on each release. +func steeringConfig(o *runCmd, fatal func(error)) steering.Config { + return steering.Config{ + Mode: o.Mode, + NFT: nftables.Config{ + Table: o.Table, + Port: o.Port, + OutQueue: o.OutQueue, + InQueue: o.InQueue, + BypassUID: uint32(o.ReinjectBypassUID), + NFTPath: o.NFTPath, + Censor: o.CensorCounters, + }, + EthtoolPath: o.EthtoolPath, + Iface: o.Iface, + + ObserveInbound: o.ObserveInbound, + StateFile: o.AdapterStateFile, + Connections: flowtrack.Counter{}, + MaxGenerations: o.MaxGenerations, + MaxScopedGenerations: o.MaxScopedGenerations, + MaxEveryPacketGenerations: o.MaxEveryPacketGenerations, + RuntimeVersion: adapter.RuntimeVersionGeneva, + Fatal: fatal, + } +} diff --git a/cmd/geneva-server/runtime_version_linux_test.go b/cmd/geneva-server/runtime_version_linux_test.go new file mode 100644 index 0000000..86602c7 --- /dev/null +++ b/cmd/geneva-server/runtime_version_linux_test.go @@ -0,0 +1,116 @@ +//go:build linux + +package main + +import ( + "context" + "path/filepath" + "testing" + + "github.com/getlantern/geneva-server/internal/adapter" + "github.com/getlantern/geneva-server/internal/engine" + "github.com/getlantern/geneva-server/internal/steering" +) + +const testDNA = `[TCP:flags:S]-drop-| \/` + +type idleConnections struct{} + +func (idleConnections) Count(context.Context, uint32, uint16) (int, error) { return 0, nil } +func (idleConnections) Counts(context.Context, uint16) (map[uint32]int, error) { + return map[uint32]int{}, nil +} +func (idleConnections) Neutralize(context.Context, uint16) (int, error) { return 0, nil } + +// withBuildVersion runs the process as if it had been built as build. +func withBuildVersion(t *testing.T, build string) { + t.Helper() + prev := version + version = build + t.Cleanup(func() { version = prev }) +} + +func newTestController(t *testing.T, stateFile string) *steering.Controller { + t.Helper() + cfg := steeringConfig(&runCmd{}, func(err error) { t.Errorf("fatal: %v", err) }) + cfg.NoNFT = true + cfg.StateFile = stateFile + cfg.Connections = idleConnections{} + c := steering.New(engine.NewRegistry(), cfg, nil) + if err := c.Start(context.Background()); err != nil { + t.Fatal(err) + } + return c +} + +func engineArtifact(t *testing.T) adapter.Artifact { + t.Helper() + payload := []byte(testDNA) + a, err := adapter.NewArtifact(adapter.ArtifactMetadata{ + Technique: adapter.TechniqueGeneva, Revision: "r1", Digest: adapter.Digest(payload), Size: len(payload), + AdapterProtocol: adapter.Version1, RequiredRuntimeName: adapter.RuntimeNameGeneva, + RequiredRuntimeVersion: adapter.RuntimeVersionGeneva, SchemaVersion: adapter.SchemaVersionV1, + }, payload) + if err != nil { + t.Fatal(err) + } + return a +} + +func TestDescriptorRuntimeVersionIsEngineVersionRegardlessOfBuild(t *testing.T) { + for _, build := range []string{"dev", "0.0.4", "0.0.5", "9.9.9-rc1"} { + t.Run(build, func(t *testing.T) { + withBuildVersion(t, build) + c := newTestController(t, filepath.Join(t.TempDir(), "adapter.json")) + if got := c.Descriptor().RuntimeVersion; got != adapter.RuntimeVersionGeneva { + t.Fatalf("descriptor runtime_version = %q under build %q, want %q", got, build, adapter.RuntimeVersionGeneva) + } + }) + } +} + +func TestEngineVersionArtifactPreparesUnderDifferentBuild(t *testing.T) { + withBuildVersion(t, "0.0.5-different-build") + ctx := context.Background() + c := newTestController(t, filepath.Join(t.TempDir(), "adapter.json")) + artifact := engineArtifact(t) + if err := c.Prepare(ctx, artifact); err != nil { + t.Fatalf("prepare artifact requiring %q: %v", adapter.RuntimeVersionGeneva, err) + } + if err := c.Verify(ctx, artifact); err != nil { + t.Fatal(err) + } + if err := c.ActivateForNewConnections(ctx, artifact); err != nil { + t.Fatal(err) + } +} + +func TestPersistedStateSurvivesBuildUpgradeWithSameEngineVersion(t *testing.T) { + ctx := context.Background() + state := filepath.Join(t.TempDir(), "adapter.json") + artifact := engineArtifact(t) + + withBuildVersion(t, "0.0.4") + before := newTestController(t, state) + if err := before.Prepare(ctx, artifact); err != nil { + t.Fatal(err) + } + if err := before.Verify(ctx, artifact); err != nil { + t.Fatal(err) + } + if err := before.ActivateForNewConnections(ctx, artifact); err != nil { + t.Fatal(err) + } + active := before.State().ActiveNew + + version = "0.0.5" + after := newTestController(t, state) + st := after.State() + if st.Unsafe || st.IntegrityFailure != "" || st.ActiveNew != active { + t.Fatalf("restored state after build upgrade = %+v, want active generation %d", st, active) + } + quarantined, err := filepath.Glob(state + ".quarantine-*") + if err != nil || len(quarantined) != 0 { + t.Fatalf("quarantined state = %v, %v", quarantined, err) + } +} diff --git a/docs/adapter-v1.md b/docs/adapter-v1.md index 6273aa0..765c923 100644 --- a/docs/adapter-v1.md +++ b/docs/adapter-v1.md @@ -11,12 +11,22 @@ equivalently protected management network. "adapter_protocol": 1, "technique": "geneva", "runtime_name": "geneva-engine", - "runtime_version": "", + "runtime_version": "0.0.4", "schema_versions": [1], "max_live_generations": 3 } ``` +`runtime_version` is the Geneva engine compatibility version +(`adapter.RuntimeVersionGeneva`), not the geneva-server package version, which +`/healthz` reports as `version`. Artifacts must require it exactly. It changes +only when the same DNA could behave differently: a grammar change, different +engine semantics, or different action behavior. A release that leaves strategy +interpretation unchanged keeps it, so published artifacts and persisted state +stay valid across the upgrade. Bumping it deliberately invalidates every +artifact built for the previous value, and restart quarantines persisted state +that requires it. + The cap is configurable from 1 through the generic maximum of 32 and defaults to 3. The independent every-packet cap defaults to 2 so active/previous-known- good plus a challenger can coexist; operators may lower or raise it explicitly @@ -37,7 +47,7 @@ one-to-one mapping from artifact identity to conntrack generation. "size": 123, "adapter_protocol": 1, "required_runtime_name": "geneva-engine", - "required_runtime_version": "", + "required_runtime_version": "0.0.4", "schema_version": 1 }, "payload": "" diff --git a/internal/adapter/types.go b/internal/adapter/types.go index 0262f1c..9e14460 100644 --- a/internal/adapter/types.go +++ b/internal/adapter/types.go @@ -30,6 +30,15 @@ const ( MaxLiveGenerationBudget uint32 = 32 ) +// RuntimeVersionGeneva is the strategy-compatibility version of the Geneva +// engine. The descriptor advertises it as runtime_version and artifacts must +// require it exactly, so it is deliberately independent of the package build +// version: a release that leaves strategy interpretation unchanged keeps it, +// and every published artifact stays valid across the upgrade. Bump it only +// when the same DNA could behave differently: a grammar change, different +// engine semantics, or different action behavior. +const RuntimeVersionGeneva = "0.0.4" + type Descriptor struct { AdapterProtocol Version `json:"adapter_protocol"` Technique string `json:"technique"` diff --git a/internal/steering/controller.go b/internal/steering/controller.go index c4b2689..caa92ae 100644 --- a/internal/steering/controller.go +++ b/internal/steering/controller.go @@ -64,7 +64,10 @@ type Config struct { RestoreOffloads func(context.Context, string, *netdev.Original) error Fatal func(error) ConntrackTimeout time.Duration - RuntimeVersion string + // RuntimeVersion is the engine compatibility version the descriptor + // advertises and artifacts must require. It defaults to + // adapter.RuntimeVersionGeneva and is never the package build version. + RuntimeVersion string // Program is a test seam for asserting lifecycle transaction ordering. A // production controller leaves it nil and invokes nft directly. Program func(context.Context, nftables.Config, bool) error @@ -197,7 +200,7 @@ func New(eng *engine.Registry, cfg Config, log Logger) *Controller { cfg.ConntrackTimeout = 5 * time.Second } if cfg.RuntimeVersion == "" { - cfg.RuntimeVersion = "dev" + cfg.RuntimeVersion = adapter.RuntimeVersionGeneva } if cfg.CaptureOffloads == nil { cfg.CaptureOffloads = netdev.Capture diff --git a/internal/steering/lifecycle_test.go b/internal/steering/lifecycle_test.go index 9c6e0b0..f36018b 100644 --- a/internal/steering/lifecycle_test.go +++ b/internal/steering/lifecycle_test.go @@ -30,7 +30,7 @@ const ( ) func lifecycleArtifact(t *testing.T, revision, dna string) adapter.Artifact { - return lifecycleArtifactForRuntime(t, revision, dna, "dev") + return lifecycleArtifactForRuntime(t, revision, dna, adapter.RuntimeVersionGeneva) } func lifecycleArtifactForRuntime(t *testing.T, revision, dna, runtimeVersion string) adapter.Artifact { @@ -1136,7 +1136,7 @@ func TestQuarantineRemediatesThroughGenericT8ChampionSequence(t *testing.T) { } return state, &fakeConnections{counts: map[uint32]int{1: 1}} }, - runtime: "dev", + runtime: adapter.RuntimeVersionGeneva, }, { name: "incompatible state", From 3e746621e2be632fe048bbdb927320cfc45136bd Mon Sep 17 00:00:00 2001 From: Ilya Yakelzon Date: Thu, 24 Sep 2026 12:37:01 +0200 Subject: [PATCH 2/3] Read runtime_version from the descriptor in the docker harnesses e2e/run.sh and bench/run.sh hard-coded required_runtime_version "dev", which no longer matches the engine compatibility version the descriptor advertises. --- bench/run.sh | 5 +++-- e2e/run.sh | 7 ++++--- scripts/harness-lib.sh | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bench/run.sh b/bench/run.sh index ba9cce2..4e323f3 100755 --- a/bench/run.sh +++ b/bench/run.sh @@ -93,7 +93,7 @@ measure() { # put installs a strategy through the versioned adapter lifecycle on a running sidecar. put() { - local dna="$1" digest payload body + local dna="$1" digest payload body runtime if [[ -z "$dna" ]]; then printf '%s' "$active_identity" | "${COMPOSE[@]}" exec -T client curl -fsS -X POST --data-binary @- http://server:8092/v1/adapter/deactivate-for-new-connections >/dev/null active_identity='' @@ -101,7 +101,8 @@ put() { fi digest=$(printf '%s' "$dna" | sha256sum | awk '{print $1}') payload=$(printf '%s' "$dna" | base64 -w0) - body=$(printf '{"metadata":{"technique":"geneva","revision":"bench-%s","content_sha256":"%s","size":%d,"adapter_protocol":1,"required_runtime_name":"geneva-engine","required_runtime_version":"dev","schema_version":1},"payload":"%s"}' "$digest" "$digest" "${#dna}" "$payload") + runtime=$(runtime_version client) + body=$(printf '{"metadata":{"technique":"geneva","revision":"bench-%s","content_sha256":"%s","size":%d,"adapter_protocol":1,"required_runtime_name":"geneva-engine","required_runtime_version":"%s","schema_version":1},"payload":"%s"}' "$digest" "$digest" "${#dna}" "$runtime" "$payload") printf '%s' "$body" | "${COMPOSE[@]}" exec -T client curl -fsS -X POST --data-binary @- http://server:8092/v1/adapter/prepare >/dev/null printf '%s' "$body" | "${COMPOSE[@]}" exec -T client curl -fsS -X POST --data-binary @- http://server:8092/v1/adapter/activate-for-new-connections >/dev/null active_identity=$(printf '%s' "$body" | jq -c '.metadata | {technique, revision, digest: .content_sha256}') diff --git a/e2e/run.sh b/e2e/run.sh index 4b16c2e..389e7fb 100755 --- a/e2e/run.sh +++ b/e2e/run.sh @@ -19,11 +19,12 @@ source ../scripts/harness-lib.sh active_identity='' artifact_json() { - local dna="$1" digest payload + local dna="$1" digest payload runtime digest=$(printf '%s' "$dna" | sha256sum | awk '{print $1}') payload=$(printf '%s' "$dna" | base64 -w0) - printf '{"metadata":{"technique":"geneva","revision":"e2e-%s","content_sha256":"%s","size":%d,"adapter_protocol":1,"required_runtime_name":"geneva-engine","required_runtime_version":"dev","schema_version":1},"payload":"%s"}' \ - "$digest" "$digest" "${#dna}" "$payload" + runtime=$(runtime_version tester) + printf '{"metadata":{"technique":"geneva","revision":"e2e-%s","content_sha256":"%s","size":%d,"adapter_protocol":1,"required_runtime_name":"geneva-engine","required_runtime_version":"%s","schema_version":1},"payload":"%s"}' \ + "$digest" "$digest" "${#dna}" "$runtime" "$payload" } activate_strategy() { diff --git a/scripts/harness-lib.sh b/scripts/harness-lib.sh index d1d66e2..4b4ada6 100644 --- a/scripts/harness-lib.sh +++ b/scripts/harness-lib.sh @@ -26,3 +26,9 @@ wait_healthy() { done return 1 } + +# runtime_version prints the engine compatibility version the +# sidecar descriptor advertises, which every artifact must require exactly. +runtime_version() { + "${COMPOSE[@]}" exec -T "$1" curl -fsS http://server:8092/v1/adapter/descriptor | jq -er .runtime_version +} From d8abfc89a1a870aadd9384916d31b24e9daa00f9 Mon Sep 17 00:00:00 2001 From: Ilya Yakelzon Date: Thu, 24 Sep 2026 12:39:19 +0200 Subject: [PATCH 3/3] e2e: poll /healthz until the kernel counter reading reflects the transfer The sidecar caches counter reads for 2s, so the inbound step could see a reading taken before the transfer and fail with zero SYNs. --- e2e/run.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/e2e/run.sh b/e2e/run.sh index 389e7fb..c45d8fa 100755 --- a/e2e/run.sh +++ b/e2e/run.sh @@ -76,7 +76,13 @@ fails=$(echo "$health" | jq '.verdicts.inject_fails') # counters that classify what arrives in the kernel, which is the only reason # this signal survives steering being scoped to the strategy. step "Inbound TCP classification from kernel counters (the censor-reachability signal)" -health=$("${COMPOSE[@]}" exec -T tester curl -fsS http://server:8092/healthz) +# The sidecar caches counter reads for censorReadInterval (2s), so the first +# /healthz after the transfer can still carry a pre-transfer reading. +for _ in $(seq 1 10); do + health=$("${COMPOSE[@]}" exec -T tester curl -fsS http://server:8092/healthz) + [[ "$(echo "$health" | jq '.inbound_tcp.events.syn > 0 and .inbound_tcp.events.data > 0')" == true ]] && break + sleep 1 +done echo "$health" | jq '.inbound_tcp' syn=$(echo "$health" | jq '.inbound_tcp.events.syn') data=$(echo "$health" | jq '.inbound_tcp.events.data')