随笔 - 746  文章 - 0  评论 - 39  阅读 - 79万

Mysql:canal-deployer:如何阻断canal-client对deployer上的filter过滤条件订阅修改:https://github.com/alibaba/canal/blob/master/protocol/src/main/java/com/alibaba/otter/canal/protocol/ClientIdentity.java

 

也算是安全管理上的一个控制点:

本来,允许客户端去根据自己的实际需求去服务端订阅自己关心的数据流,是很好的。

but,但是,服务端的黑白名单过滤,尤其是白名单的filter条件会被客户端的最新订阅的过滤条件给覆盖!!!

这算是bug吗? 上游服务端怎么显得那么没地位呢!!!???

 

#==========================================================================================

另外,还有一个问题:canal的服务端depoyer 和客户端client(使用客户端库自己开发的、或者是adapter匹配的等等)

通常会由同一个安全域内的组织去部署,如此,除了业务层面的便利,数据安全上确漏洞百出!

 

#==========================================================================================

 基于以上原因:
分开安全域去部署服务端deployer和客户端client;并且阻断客户端的订阅中的过滤条件覆盖功能,以加固deployer的数据安全性。
经过代码分析,我们只要简单的修改: ./protocol/src/main/java/com/alibaba/otter/canal/protocol/ClientIdentity.java
屏蔽其中的filter参数设置。以1.1.7源代码为例,如下:
 
复制代码
  1 package com.alibaba.otter.canal.protocol;
  2 
  3 import java.io.Serializable;
  4 
  5 import org.apache.commons.lang.StringUtils;
  6 import org.apache.commons.lang.builder.ToStringBuilder;
  7 
  8 import com.alibaba.otter.canal.common.utils.CanalToStringStyle;
  9 
 10 /**
 11  * @author zebin.xuzb @ 2012-6-20
 12  * @version 1.0.0
 13  */
 14 public class ClientIdentity implements Serializable {
 15 
 16     private static final long serialVersionUID = -8262100681930834834L;
 17     private String            destination;
 18     private short             clientId;
 19     private String            filter;
 20 
 21     public ClientIdentity(){
 22 
 23     }
 24 
 25     public ClientIdentity(String destination, short clientId){
 26         this.clientId = clientId;
 27         this.destination = destination;
 28     }
 29 
 30     public ClientIdentity(String destination, short clientId, String filter){
 31         this.clientId = clientId;
 32         this.destination = destination;
 33         this.filter = "";
 34     }
 35 
 36     public Boolean hasFilter() {
 37         if (filter == null) {
 38             return false;
 39         }
 40         return StringUtils.isNotBlank(filter);
 41     }
 42 
 43     // ======== setter =========
 44 
 45     public String getDestination() {
 46         return destination;
 47     }
 48 
 49     public short getClientId() {
 50         return clientId;
 51     }
 52 
 53     public void setClientId(short clientId) {
 54         this.clientId = clientId;
 55     }
 56 
 57     public void setDestination(String destination) {
 58         this.destination = destination;
 59     }
 60 
 61     public String getFilter() {
 62         return filter;
 63     }
 64 
 65     public void setFilter(String filter) {
 66         this.filter = "";
 67     }
 68 
 69     public String toString() {
 70         return ToStringBuilder.reflectionToString(this, CanalToStringStyle.DEFAULT_STYLE);
 71     }
 72 
 73     public int hashCode() {
 74         final int prime = 31;
 75         int result = 1;
 76         result = prime * result + clientId;
 77         result = prime * result + ((destination == null) ? 0 : destination.hashCode());
 78         return result;
 79     }
 80 
 81     public boolean equals(Object obj) {
 82         if (this == obj) {
 83             return true;
 84         }
 85         if (obj == null) {
 86             return false;
 87         }
 88         if (!(obj instanceof ClientIdentity)) {
 89             return false;
 90         }
 91         ClientIdentity other = (ClientIdentity) obj;
 92         if (clientId != other.clientId) {
 93             return false;
 94         }
 95         if (destination == null) {
 96             if (other.destination != null) {
 97                 return false;
 98             }
 99         } else if (!destination.equals(other.destination)) {
100             return false;
101         }
102         return true;
103     }
104 
105 }
复制代码

 

附件:源代码   class文件

 

 

 

 
 
posted on   jinzhenshui  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2010-04-24 破解ASA数据库的密码

点击右上角即可分享
微信分享提示