From bcbe3637e70dab4e55d21802fe70d8c5320f7072 Mon Sep 17 00:00:00 2001 From: acpana <8968914+acpana@users.noreply.github.com> Date: Tue, 26 Jul 2022 14:38:35 -0700 Subject: [PATCH] wip: block PeerName registrations Signed-off-by: acpana <8968914+acpana@users.noreply.github.com> --- agent/consul/catalog_endpoint.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/agent/consul/catalog_endpoint.go b/agent/consul/catalog_endpoint.go index 6508ba220b..a6a812223d 100644 --- a/agent/consul/catalog_endpoint.go +++ b/agent/consul/catalog_endpoint.go @@ -74,9 +74,36 @@ type Catalog struct { logger hclog.Logger } +func hasPeerNameInRequest(req *structs.RegisterRequest) bool { + if req == nil { + return false + } + // nodes, services, checks + if req.PeerName != structs.DefaultPeerKeyword { + return true + } + if req.Service != nil && req.Service.PeerName != structs.DefaultPeerKeyword { + return true + } + if req.Check != nil && req.Check.PeerName != structs.DefaultPeerKeyword { + return true + } + for _, check := range req.Checks { + if check.PeerName != structs.DefaultPeerKeyword { + return true + } + } + + return false +} + // Register a service and/or check(s) in a node, creating the node if it doesn't exist. // It is valid to pass no service or checks to simply create the node itself. func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error { + if hasPeerNameInRequest(args) { + return fmt.Errorf("cannot register requests with PeerName in them") + } + if done, err := c.srv.ForwardRPC("Catalog.Register", args, reply); done { return err }