Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RocketMQ ACL 权限控制使用与 Algorithm HmacSHA1 not available 的解决 #66

Open
Shellbye opened this issue Aug 9, 2019 · 0 comments

Comments

@Shellbye
Copy link
Owner

Shellbye commented Aug 9, 2019

RocketMQ默认是不带有任何认证的,部署在公网的话是不安全的,以下是一些我在尝试添加认证时的一些笔记

Broker端配置

首先需要在 conf/broker.conf里面打开acl的配置,如下

aclEnable=true

然后在conf/plain_acl.yml进行相应的配置,如下

globalWhiteRemoteAddresses:

accounts:
- accessKey: RocketMQ
  secretKey: 12345678
  whiteRemoteAddress:
  admin: false
  defaultTopicPerm: DENY
  defaultGroupPerm: SUB
  topicPerms:
  - topicA=DENY
  - topicB=PUB|SUB
  - topicC=SUB
  groupPerms:
  # the group should convert to retry topic
  - groupA=DENY
  - groupB=PUB|SUB
  - groupC=SUB

- accessKey: rocketmq2
  secretKey: 12345678
  whiteRemoteAddress: 192.168.1.*
  # if it is admin, it could access all resources
  admin: true

一个BUG

理论上讲,或者按照大多数的教程,配置到这里就算是完成了,但是如果你就到此为止的话,接下来是生产或者消费时(具体代码见后),会报如下错误:

Caused by: org.apache.rocketmq.client.exception.MQBrokerException: CODE: 1  
DESC: org.apache.rocketmq.acl.common.AclException: [10015:signature-failed] 
unable to calculate a request signature. error=[10015:signature-failed] 
unable to calculate a request signature. error=Algorithm HmacSHA1 not available, 
org.apache.rocketmq.acl.common.AclSigner.signAndBase64Encode(AclSigner.java:84)

错误信息比较长,但是核心部分是Algorithm HmacSHA1 not available,我起初以为是客户端的问题,后来debug了一下才发现不是客户端的问题,是服务端少了一个包,在网上简单的搜索了之后发现是少了叫sunjce_provider.jar的包,一般这个包都在$JAVA_HOME/jre/lib/ext目录下,所以解决办法就是把这个包拷贝一个到服务端的distribution/target/apache-rocketmq/lib中。

客户端使用

服务端配置好之后,客户端使用就比较轻松了,相比常规的代码,需要要添加相应的参数就可以了

DefaultMQProducer producer = new DefaultMQProducer("SyncProducer",
                new AclClientRPCHook(new SessionCredentials("RocketMQ", "12345678")));

参考

  1. https://blog.csdn.net/prestigeding/article/details/94317946
  2. https://www.cnblogs.com/jessezeng/p/6011666.html
  3. https://blog.csdn.net/fuqinglinbin/article/details/97389061
@Shellbye Shellbye changed the title RocketMQ ACL 权限控制使用 RocketMQ ACL 权限控制使用与 Algorithm HmacSHA1 not available 的解决 Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant