本文檔描述了訪問控制的認證和受權機制。身份驗證後端不該和AMQP 0-9-1中的認證機制混淆。html
一般人們會混淆認證和受權。這在RabbitMQ中是分開的,對其並不適用。爲了簡化描述,咱們定義認證是「識別用戶是誰」,定義受權爲「肯定用戶能夠作什麼,不能作什麼」數據庫
服務端開始運行後,若是檢測到數據庫未進行初始化或者已經被刪除,它會使用如下資源初始化一個新的數據庫:express
建議刪除guest用戶,或者修改密碼,尤爲在broker能夠公開訪問的狀況下。後端
默認狀況下,guest用戶不容許遠程鏈接,僅可使用lookback接口鏈接。其它用戶沒有此限制。oop
這是由配置文件中的lookback_users條目控制的。spa
若是你但願guest用戶遠程能夠訪問,須要將配置條目lookback_users設置爲[]。完整的以下:rest
[{rabbit, [{loopback_users, []}]}].
RabbitMQ客戶端鏈接到一個服務端的時候,在它的操做指令中指定了一個虛擬主機。服務端首先檢查是否有訪問該虛擬主機的權限,沒有權限的會拒絕鏈接。code
對於exchanges和queues等資源,位於某個虛擬主機內;不一樣虛擬主機內即使名稱相同也表明不一樣的資源。當特定操做在資源上執行時第二級訪問控制開始生效。orm
RabbitMQ在某個資源上區分了配置、寫和讀操做。server
配置操做建立或者銷燬資源,或者更改資源的行爲。寫操做將消息注入進資源之中。讀操做從資源中獲取消息。
要執行特定操做用戶必須授予合適的權限。下表代表要執行全部的AMQP命令須要什麼資源。
AMQP 0-9-1 Operation | configure | write | read | |
---|---|---|---|---|
exchange.declare | (passive=false) | exchange | ||
exchange.declare | (passive=true) | |||
exchange.declare | (with AE) | exchange | exchange (AE) | exchange |
exchange.delete | exchange | |||
queue.declare | (passive=false) | queue | ||
queue.declare | (passive=true) | |||
queue.declare | (with DLX) | queue | exchange (DLX) | queue |
queue.delete | queue | |||
exchange.bind | exchange (destination) | exchange (source) | ||
exchange.unbind | exchange (destination) | exchange (source) | ||
queue.bind | queue | exchange | ||
queue.unbind | queue | exchange | ||
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.