mirror of
https://github.com/openziti/ziti.git
synced 2026-09-10 16:55:41 +00:00
b353d2d9b6
- rejects a remove or update request whose terminator is owned by a different router, on the fabric control channel handlers - drops ids the requesting router does not own from batch removals, keeping absent ids so a delete racing a not-yet-applied create is still ordered after it - adds unit tests for the ownership filter and for the single-terminator check - adds an end-to-end test that drives the fabric control channel from an enrolled router against a second router's terminator, covering single remove, batch remove, and re-weight, plus a control that a router can still remove its own
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package handler_ctrl
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel/v5"
|
|
"github.com/openziti/ziti/v2/common/handler_common"
|
|
"github.com/openziti/ziti/v2/common/pb/ctrl_pb"
|
|
"github.com/openziti/ziti/v2/controller/model"
|
|
"github.com/openziti/ziti/v2/controller/network"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type removeTerminatorHandler struct {
|
|
baseHandler
|
|
}
|
|
|
|
func newRemoveTerminatorHandler(network *network.Network, router *model.Router) *removeTerminatorHandler {
|
|
return &removeTerminatorHandler{
|
|
baseHandler: baseHandler{
|
|
router: router,
|
|
network: network,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (self *removeTerminatorHandler) ContentType() int32 {
|
|
return int32(ctrl_pb.ContentType_RemoveTerminatorRequestType)
|
|
}
|
|
|
|
func (self *removeTerminatorHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
request := &ctrl_pb.RemoveTerminatorRequest{}
|
|
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
|
log.WithError(err).Error("failed to unmarshal remove terminator message")
|
|
return
|
|
}
|
|
|
|
go self.handleRemoveTerminator(msg, ch, request)
|
|
}
|
|
|
|
func (self *removeTerminatorHandler) handleRemoveTerminator(msg *channel.Message, ch channel.Channel, request *ctrl_pb.RemoveTerminatorRequest) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
terminator, err := self.network.Terminator.Read(request.TerminatorId)
|
|
if err != nil {
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
return
|
|
}
|
|
|
|
if !self.ownsTerminator(terminator) {
|
|
log.
|
|
WithField("routerId", self.router.Id).
|
|
WithField("terminator", request.TerminatorId).
|
|
WithField("terminatorRouterId", terminator.Router).
|
|
Warn("router attempted to remove a terminator it does not own; rejected")
|
|
handler_common.SendFailure(msg, ch, "terminator not owned by requesting router")
|
|
return
|
|
}
|
|
|
|
if err := self.network.Terminator.Delete(request.TerminatorId, self.newChangeContext(ch, "fabric.remove.terminator")); err == nil {
|
|
log.
|
|
WithField("routerId", ch.Id()).
|
|
WithField("serviceId", terminator.Service).
|
|
WithField("terminator", request.TerminatorId).
|
|
Info("removed terminator")
|
|
handler_common.SendSuccess(msg, ch, "")
|
|
} else {
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
}
|
|
}
|