From a505f09c7f290166202e2d1475c4951118ddd342 Mon Sep 17 00:00:00 2001 From: Anshul Pundir Date: Wed, 6 Dec 2017 11:29:58 -0800 Subject: [PATCH] Validate/sanitize swarmkit spec name. Signed-off-by: Anshul Pundir Upstream-commit: 739c4cc6b2bab5c3e27656e0a95d858901ecf6b4 Component: engine --- components/engine/daemon/cluster/swarm.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/engine/daemon/cluster/swarm.go b/components/engine/daemon/cluster/swarm.go index 61223691bd..ec527ce59f 100644 --- a/components/engine/daemon/cluster/swarm.go +++ b/components/engine/daemon/cluster/swarm.go @@ -228,6 +228,13 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag return err } + // Validate spec name. + if spec.Annotations.Name == "" { + spec.Annotations.Name = "default" + } else if spec.Annotations.Name != "default" { + return validationError{errors.New(`swarm spec must be named "default"`)} + } + // In update, client should provide the complete spec of the swarm, including // Name and Labels. If a field is specified with 0 or nil, then the default value // will be used to swarmkit.