From 93d09f127ac065d6aaed151ed27cff35280d02e5 Mon Sep 17 00:00:00 2001 From: Tam Mach Date: Sat, 16 Jul 2022 14:33:18 +1000 Subject: [PATCH] clustermesh: Validate cluster-id value as per requirement This commit is to make sure that cluster-id is numeric and within range of 1-255. https://docs.cilium.io/en/stable/gettingstarted/clustermesh/clustermesh/#gs-clustermesh Fixes: #143 Signed-off-by: Tam Mach --- cli/clustermesh/clustermesh.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/clustermesh/clustermesh.go b/cli/clustermesh/clustermesh.go index 418e5f0ddb025..7b19fdc86a524 100644 --- a/cli/clustermesh/clustermesh.go +++ b/cli/clustermesh/clustermesh.go @@ -905,6 +905,14 @@ func (k *K8sClusterMesh) Connect(ctx context.Context) error { aiLocal.ClusterName, aiLocal.ClusterID) } + cid, err := strconv.Atoi(aiRemote.ClusterID) + if err != nil { + return fmt.Errorf("remote cluster has non-numeric cluster ID %s. Only numeric values 1-255 are allowed", aiRemote.ClusterID) + } + if cid < 1 || cid > 255 { + return fmt.Errorf("remote cluster has cluster ID %d out of acceptable range (1-255)", cid) + } + if aiRemote.ClusterName == aiLocal.ClusterName { return fmt.Errorf("remote and local cluster have the same, non-unique name: %s", aiLocal.ClusterName) }