【RabbitMQ doc】rabbitmq的访问控制

Access Control (Authentication, Authorisation) in RabbitMQ

 

 

本文档描述了访问控制的认证和授权机制。身份验证后端不应和AMQP 0-9-1中的认证机制混淆。

术语和定义

通常人们会混淆认证和授权。这在RabbitMQ中是分开的,对其并不适用。为了简化描述,我们定义认证是“识别用户是谁”,定义授权为“确定用户可以做什么,不能做什么”

默认虚拟主机和用户

服务端开始运行后,如果检测到数据库未进行初始化或者已经被删除,它会使用以下资源初始化一个新的数据库:

  • 名称为/的虚拟主机
  • 密码为guest的guest用户,且对/虚拟主机拥有所有权限

建议删除guest用户,或者修改密码,尤其在broker可以公开访问的情况下。

“guest”用户仅允许localhost连接

默认情况下,guest用户不允许远程连接,仅可以使用lookback接口连接。其它用户没有此限制。

这是由配置文件中的lookback_users条目控制的。

如果你希望guest用户远程可以访问,需要将配置条目lookback_users设置为[]。完整的如下:

[{rabbit, [{loopback_users, []}]}].

权限控制作用原理

RabbitMQ客户端连接到一个服务端的时候,在它的操作指令中指定了一个虚拟主机。服务端首先检查是否有访问该虚拟主机的权限,没有权限的会拒绝连接。

对于exchanges和queues等资源,位于某个虚拟主机内;不同虚拟主机内即便名称相同也代表不同的资源。当特定操作在资源上执行时第二级访问控制开始生效。

RabbitMQ在某个资源上区分了配置、写和读操作。

配置操作创建或者销毁资源,或者更改资源的行为。写操作将消息注入进资源之中。读操作从资源中获取消息。

要执行特定操作用户必须授予合适的权限。下表表明要执行所有的AMQP命令需要什么资源。

AMQP 0-9-1 Operation configurewriteread
exchange.declare(passive=false)exchange  
exchange.declare(passive=true)   
exchange.declare(with AE)exchangeexchange (AE)exchange
exchange.delete exchange  
queue.declare(passive=false)queue  
queue.declare(passive=true)   
queue.declare(with DLX)queueexchange (DLX)queue
queue.delete queue  
exchange.bind  exchange (destination)exchange (source)
exchange.unbind  exchange (destination)exchange (source)
queue.bind  queueexchange
queue.unbind  queueexchange
basic.publish  exchange 
basic.get   queue
basic.consume   queue
queue.purge   queue

 

Permissions are expressed as a triple of regular expressions - one each for configure, write and read - on per-vhost basis. The user is granted the respective permission for operations on all resources with names matching the regular expressions. (Note: For convenience RabbitMQ maps AMQP's default exchange's blank name to 'amq.default' when performing permission checks.)

The regular expression '^$', i.e. matching nothing but the empty string, covers all resources and effectively stops the user from performing any operation. Standard AMQP resource names are prefixed with amq. and server generated names are prefixed with amq.gen. For example, '^(amq\.gen.*|amq\.default)$' gives a user access to server-generated names and the default exchange. The empty string, '' is a synonym for '^$'and restricts permissions in the exact same way.

 

https://www.rabbitmq.com/access-control.html

转载于:https://my.oschina.net/u/259976/blog/740940

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值