Skip to content

Agent Mesh

node: refuse a config schema this build cannot read

Antonio Ojea5b1e41696669
diff --git a/api/policy.go b/api/policy.go
index efe441bb..9c949eee 100644
--- a/api/policy.go
+++ b/api/policy.go
@@ -46,6 +46,20 @@ type NodeConfig struct {
Services []ServiceConfig `yaml:"services"`
}
+// NodeConfigVersionV1Alpha1 is the only node config schema this build understands.
+// A file omitting the version is read as this one, since it predates the check.
+const NodeConfigVersionV1Alpha1 = "v1alpha1"
+
+// SupportedNodeConfigVersions gates LoadNodeConfig. A node must refuse a schema
+// it does not know rather than parse it as this one: silently reinterpreting a
+// future config would silently reinterpret its attenuation rules. Adding a
+// version means adding it here and decoding it into the same internal type, so
+// the rest of the node stays version-agnostic.
+var SupportedNodeConfigVersions = map[string]bool{
+ "": true,
+ NodeConfigVersionV1Alpha1: true,
+}
+
type Attenuation struct {
Policies []string `yaml:"policies"`
Checks []string `yaml:"checks"`
diff --git a/internal/node/config.go b/internal/node/config.go
index 367cc1b8..4ac6860f 100644
--- a/internal/node/config.go
+++ b/internal/node/config.go
@@ -31,8 +31,15 @@ func LoadNodeConfig(path string) (*NodeConfigComplete, error) {
}
var config api.NodeConfig
- if err := yaml.Unmarshal(data, &config); err != nil {
- return nil, err
+ // Strict: a key this build does not recognise is either a typo or a newer
+ // schema, and under attenuation either one silently weakens the node.
+ if err := yaml.UnmarshalStrict(data, &config); err != nil {
+ return nil, fmt.Errorf("invalid node config %s: %w", path, err)
+ }
+
+ if !api.SupportedNodeConfigVersions[config.Version] {
+ return nil, fmt.Errorf("node config %s declares version %q, which this build does not support (supported: %s); upgrade sam-node",
+ path, config.Version, api.NodeConfigVersionV1Alpha1)
}
complete := &NodeConfigComplete{
diff --git a/internal/node/config_test.go b/internal/node/config_test.go
index f60ed1dc..67a707fa 100644
--- a/internal/node/config_test.go
+++ b/internal/node/config_test.go
@@ -201,6 +201,48 @@ version: "v1alpha1"
attenuation:
rules:
- "invalid rule syntax"
+`,
+ wantErr: true,
+ },
+ {
+ // A node must refuse a schema it cannot read rather than reinterpret it
+ // as v1alpha1, which would silently reinterpret its attenuation rules.
+ name: "Unsupported future config version",
+ yamlContent: `
+version: "v2"
+services:
+ - type: "mcp"
+ name: "db-reader"
+ target_url: "http://127.0.0.1:5001/mcp"
+`,
+ wantErr: true,
+ },
+ {
+ name: "Version omitted is read as the original schema",
+ yamlContent: `
+services:
+ - type: "mcp"
+ name: "db-reader"
+ target_url: "http://127.0.0.1:5001/mcp"
+`,
+ wantErr: false,
+ verify: func(t *testing.T, config *NodeConfigComplete) {
+ if len(config.Services) != 1 {
+ t.Fatalf("got %d services, want 1", len(config.Services))
+ }
+ },
+ },
+ {
+ // Dropping an unrecognised key under attenuation would quietly weaken
+ // the node, so an unknown key is an error rather than a no-op.
+ name: "Unknown key is rejected",
+ yamlContent: `
+version: "v1alpha1"
+attenuation:
+ policies:
+ - 'deny if user("bob");'
+ policiez:
+ - 'deny if user("alice");'
`,
wantErr: true,
},