apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.4k stars 26.42k forks source link

2.7.8 Redis元数据中心无法获取密码 #6534

Closed spilledyear closed 3 years ago

spilledyear commented 4 years ago

Environment

项目使用的是redis元数据中心,配置了密码,发现启动的时候元数据没有上报。

经调试发现,RedisMetadataReport 构造函数里面没有解析 password , 奇怪的是 2.7.4.1 里面也有解析,是不是漏掉了?发现那2.7.7版本也没有

解决方法

在 RedisMetadataReport 构造函数加上

password = url.getParameter(PASSWORD_KEY, "");
tomatofrommars commented 4 years ago

It depends. Precondition: redis-server auth enabled.

    <!-- Good -->
    <dubbo:metadata-report address="redis://username:redis@127.0.0.1:6379"/>
    <!-- Bad -->
    <dubbo:metadata-report address="redis://127.0.0.1:6379" username="username" password="redis"/>

The bad one throws:

redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
    at redis.clients.jedis.Protocol.processError(Protocol.java:127)
    at redis.clients.jedis.Protocol.process(Protocol.java:161)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.Jedis.set(Jedis.java:121)
        ...

It seems MetadataReportConfig#toUrl didn't set the username&password to the proper field of the url. Therefore the constructor of RedisMetadataReport gets no password with url.getPassword(), which hides in url.getParameter("password").

Replace implementation of MetadataReportConfig#toUrl with method UrlUtils.parseURL(address, map) from same situation in ConfigCenterConfig#toUrl should resolve this problem.

https://github.com/apache/dubbo/blob/043da6850b81dd03d5879b19f1c2a52b05426272/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java#L89-L108

https://github.com/apache/dubbo/blob/043da6850b81dd03d5879b19f1c2a52b05426272/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java#L64-L77

tswstarplanet commented 4 years ago

I will add a redis client module to handle the interact with redis server, meanwhile solve the problem

cvictory commented 4 years ago

@tswstarplanet Do you have time to work on this?

zdtdtel commented 3 years ago

@spilledyear 在配置 redis 作为 Dubbo 项目的元数据中心时, 我也遇到了同样的问题, 报错如下

redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.

我的项目环境是

解决方法如下:

在配置文件里用下面这种格式

dubbo.metadata-report.address=redis://username:password@192.168.171.213:6379

或者

<dubbo:metadata-report address="redis://username:password@192.168.171.213:6379"/>

根据报错 debug 到 org.apache.dubbo.common.URL 这个类里

debug1

icankeep commented 3 years ago

Related issue: #6715 the issue has been solved by #7474

icankeep commented 3 years ago

&READY TO CLOSE&