ActiveMQ Artemis用户密码认证失效 求排查配置遗漏点
我在ActiveMQ Artemis中使用如下plain格式的login.config进行配置,但无论使用错误凭证还是不提供凭证,登录认证均未生效。请问在设置有效认证时是否遗漏了某些配置?
activemq { org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule required debug=false reload=true org.apache.activemq.jaas.properties.user="artemis-users.properties" org.apache.activemq.jaas.properties.role="artemis-roles.properties"; };
broker.xml核心配置片段:
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd"> <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core "> <!-- 省略其他非核心配置 --> <security-settings> <security-setting match="#"> <permission type="createNonDurableQueue" roles="amq"/> <permission type="deleteNonDurableQueue" roles="amq"/> <permission type="createDurableQueue" roles="amq"/> <permission type="deleteDurableQueue" roles="amq"/> <permission type="createAddress" roles="amq"/> <permission type="deleteAddress" roles="amq"/> <permission type="consume" roles="amq"/> <permission type="browse" roles="amq"/> <permission type="send" roles="amq"/> <permission type="manage" roles="amq"/> </security-setting> </security-settings> <!-- 省略其他非核心配置 --> </core> </configuration>
bootstrap.xml配置:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <broker xmlns="http://activemq.org/schema"> <jaas-security domain="activemq"/> <server configuration="file:/ActiveMQ/aaq/etc//broker.xml"/> <web bind="http://localhost:8161" path="web"> <app url="activemq-branding" war="activemq-branding.war"/> <app url="artemis-plugin" war="artemis-plugin.war"/> <app url="console" war="console.war"/> </web> </broker>
你的配置存在几个关键问题,逐一修正即可生效:
1. 修正login.config中的登录模块类名
你用的org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule是旧版路径,正确类名需去掉spi层级,修改后:
activemq { org.apache.activemq.artemis.core.security.jaas.PropertiesLoginModule required debug=false reload=true org.apache.activemq.jaas.properties.user="artemis-users.properties" org.apache.activemq.jaas.properties.role="artemis-roles.properties"; };
2. 确保用户/角色文件配置正确
artemis-users.properties需存储用户名和加密密码(用artemis user add命令生成,格式为用户名=ENC(加密串)),示例:admin=ENC(xxxxxxx) test=ENC(yyyyyyy)artemis-roles.properties要把用户绑定到amq角色(对应broker.xml中权限配置的角色),示例:amq=admin,test
3. 让Broker识别JAAS配置文件
启动Broker时,必须通过JVM参数指定login.config的路径:
-Djava.security.auth.login.config=/你的配置目录/login.config
如果用artemis run启动,可修改etc/artemis.profile(Linux)或etc/artemis.cmd(Windows),把上述参数添加到启动命令里。
4. 强制协议 acceptor 要求认证
部分协议默认允许无凭证连接,需在每个acceptor配置中添加requireLogin=true参数,以AMQP为例:
<acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=true;requireLogin=true</acceptor>
对CORE、STOMP、MQTT等其他协议的acceptor也做同样修改。
5. 确认Broker启用了安全校验
检查broker.xml的<core>节点下,是否存在<security-enabled>false</security-enabled>,如果有则删除或改为<security-enabled>true</security-enabled>(默认是true,但手动修改会导致认证失效)。
完成以上修改后重启Broker,错误凭证或无凭证的连接会被拒绝,只有匹配用户/角色的请求才能正常操作。
内容的提问来源于stack exchange,提问作者Tony

