Skip to content

Commit

Permalink
clustermesh: Validate cluster-id value as per requirement
Browse files Browse the repository at this point in the history
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

Co-authored-by: Tobias Klauser <tobias.klauser@gmail.com>
Signed-off-by: Tam Mach <tam.mach@cilium.io>
  • Loading branch information
sayboras and tklauser committed Jul 20, 2022
1 parent 8b805d6 commit a4c498e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,15 @@ func (k *K8sClusterMesh) Connect(ctx context.Context) error {
aiLocal.ClusterName, aiLocal.ClusterID)
}

cid, err := strconv.Atoi(aiRemote.ClusterID)
if err != nil {
return fmt.Errorf("local cluster has non-numeric cluster ID %s. Only numeric values 1-255 are allowed", aiRemote.ClusterID)
}
if cid > 255 || cid < 1 {
return fmt.Errorf("remote cluster has the cluster ID out of acceptable range (e.g. 1-255) (cluster ID: %d)",
cid)
}

if aiRemote.ClusterName == aiLocal.ClusterName {
return fmt.Errorf("remote and local cluster have the same, non-unique name: %s", aiLocal.ClusterName)
}
Expand Down

0 comments on commit a4c498e

Please sign in to comment.