Skip to content

Commit 5b524ad

Browse files
committed
[tunnel] add UID-scoped CloseConnectionsByUID method
CloseConnectionsByName matches by TunnelNode name only, which causes cross-project collisions in multi-tenant environments where multiple projects have TunnelNodes with the same name. When any project's TunnelNode is deleted, all connections with that name across all projects are killed. Add CloseConnectionsByUID which scopes the close to a specific TunnelNode UID, avoiding cross-project interference.
1 parent 03c5ee8 commit 5b524ad

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/tunnel/server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ func (t *TunnelServer) CloseConnection(connID string) {
936936
}
937937

938938
// CloseConnectionsByName closes all active connections for the TunnelNode with the given name.
939+
// WARNING: In multi-tenant environments, multiple TunnelNodes across different
940+
// projects can share the same name. Prefer CloseConnectionsByUID to avoid
941+
// cross-project collisions.
939942
func (t *TunnelServer) CloseConnectionsByName(name string) {
940943
t.conns.ForEach(func(connID string, c *conn) bool {
941944
if c.obj.Name == name {
@@ -956,6 +959,24 @@ func (t *TunnelServer) CloseConnectionsByName(name string) {
956959
})
957960
}
958961

962+
// CloseConnectionsByUID closes all active connections for the TunnelNode with
963+
// the given UID. This is safe in multi-tenant environments where multiple
964+
// projects may have TunnelNodes with the same name but different UIDs.
965+
func (t *TunnelServer) CloseConnectionsByUID(uid string) {
966+
t.conns.ForEach(func(connID string, c *conn) bool {
967+
if string(c.obj.UID) == uid {
968+
slog.Info("Closing connection for removed TunnelNode",
969+
slog.String("connID", connID),
970+
slog.String("tunnelNode", c.obj.Name),
971+
slog.String("uid", uid),
972+
)
973+
c.cancel()
974+
}
975+
return true
976+
})
977+
t.tunnels.Del(uid)
978+
}
979+
959980
// ReconcileWithClient reconciles a TunnelNode using the provided client.
960981
// This method can be used by both standard reconcilers and multicluster reconcilers.
961982
func (t *TunnelServer) ReconcileWithClient(ctx context.Context, c client.Client, request reconcile.Request) (reconcile.Result, error) {

0 commit comments

Comments
 (0)