A host accepts an explicitly-empty declaration (hq 127)
The empty-resources guard refused every empty body as a likely mistake, with no way to say emptiness was meant — so the control plane could never tell a node to drop its last resource. The envelope gains owns_nothing: with it, an empty declaration is applied (the node drops what the mesh owned); without it, empty is still refused, so a truncated or mis-composed body cannot silently strip a machine. One test, both directions.
This commit is contained in:
@@ -1142,10 +1142,17 @@ func ParseTrusted(raw []byte) (*Declaration, error) { return parse(raw, true) }
|
||||
// first pass takes the envelope and each resource's bytes; the second decodes each one into
|
||||
// the struct for its kind, strictly.
|
||||
type envelope struct {
|
||||
Version int `json:"declaration"`
|
||||
For string `json:"for,omitempty"`
|
||||
Adoption *Adoption `json:"adoption,omitempty"`
|
||||
Resources []json.RawMessage `json:"resources"`
|
||||
Version int `json:"declaration"`
|
||||
For string `json:"for,omitempty"`
|
||||
Adoption *Adoption `json:"adoption,omitempty"`
|
||||
// OwnsNothing is the control plane saying, explicitly, that this node's declaration is empty
|
||||
// on purpose — it owns nothing the mesh put there (novox/hq issue 127). Without it an empty
|
||||
// resources list is refused as a likely mistake; with it the node applies the empty
|
||||
// declaration and drops what it last held. The two are distinguished because a truncated or
|
||||
// mis-composed body arrives as empty too, and a host that could not tell them apart would let
|
||||
// a bug quietly strip a machine.
|
||||
OwnsNothing bool `json:"owns_nothing,omitempty"`
|
||||
Resources []json.RawMessage `json:"resources"`
|
||||
}
|
||||
|
||||
func parse(raw []byte, allowActions bool) (*Declaration, error) {
|
||||
@@ -1165,7 +1172,7 @@ func parse(raw []byte, allowActions bool) (*Declaration, error) {
|
||||
d := &Declaration{Version: env.Version, For: env.For, Adoption: env.Adoption}
|
||||
var problems []string
|
||||
|
||||
if len(env.Resources) == 0 {
|
||||
if len(env.Resources) == 0 && !env.OwnsNothing {
|
||||
problems = append(problems, "no resources. An empty declaration is a mistake, not a "+
|
||||
"machine with nothing on it — say so with an explicit empty list if that is meant")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user