Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions bench/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ 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=''
return
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}')
Expand Down
61 changes: 35 additions & 26 deletions cmd/geneva-server/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Comment thread
reflog marked this conversation as resolved.
Resolved
Fatal: fatal,
}
}
116 changes: 116 additions & 0 deletions cmd/geneva-server/runtime_version_linux_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 12 additions & 2 deletions docs/adapter-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ equivalently protected management network.
"adapter_protocol": 1,
"technique": "geneva",
"runtime_name": "geneva-engine",
"runtime_version": "<exact build 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
Expand All @@ -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": "<exact build version>",
"required_runtime_version": "0.0.4",
"schema_version": 1
},
"payload": "<base64 Geneva DNA>"
Expand Down
15 changes: 11 additions & 4 deletions e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -75,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')
Expand Down
9 changes: 9 additions & 0 deletions internal/adapter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 5 additions & 2 deletions internal/steering/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/steering/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions scripts/harness-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ wait_healthy() {
done
return 1
}

# runtime_version <container> 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
}
Loading