根據預設,Cassandra 安裝時不會啟用驗證功能。這表示任何人都能存取 Cassandra。您可以在安裝 Edge 後啟用驗證功能,也可以在安裝過程中啟用。
您可以使用 Cassandra CREATE/ALTER/DROP ROLES 陳述式新增、移除及修改角色。如要瞭解詳情,請參考下列資源:
一般注意事項
- 啟用 Cassandra 驗證後,Cassandra 會自動建立預設超級使用者 cassandra (密碼為 cassandra)。這是廣為人知的超級使用者,不應將這個使用者用於實際工作環境。此外,透過這個超級使用者進行驗證時,必須達到多數一致性。因此,透過這位使用者驗證的所有 Cassandra 連線都需要更嚴格的一致性,導致效能較慢且容錯能力較低。
- 一般工作流程包括在 Cassandra 中啟用驗證,同時透過設定檔傳遞自訂使用者名稱和密碼。這樣會建立自訂使用者和密碼,您可以安全地用於自己的需求,而且透過這類使用者進行驗證時,不會受到群體一致性限制。
- 請注意,即使您建立了自訂使用者,Cassandra 仍會建立預設的 cassandra 超級使用者,而且可以透過超級使用者存取 Cassandra 叢集。在 Apigee 中成功啟用 Cassandra 驗證後,通常應使用 ALTER ROLE 指令,將這個 cassandra 使用者的密碼變更為預設 cassandra 以外的值。請記下這組密碼,以供日後參考。
- 請勿變更 edge-* 元件用於驗證的角色密碼,否則服務會立即中斷。您應該建立全新的使用者,修改 edge-* 元件以使用新使用者,完成後再使用 DROP ROLE 指令刪除舊使用者。
- 如要變更 edge-* 元件用於 Cassandra 驗證的角色,請按照下列步驟操作:
- 按照「啟用驗證」一節中的步驟建立新使用者。請注意,如果叢集已啟用驗證功能,且您已變更 cassandra 使用者的密碼,則必須透過
CASS_EXISTING_USERNAME和CASS_EXISTING_PASSWORD傳遞現有使用者的使用者名稱/密碼組合。 - 完成後,請透過 cqlsh 驗證是否能透過新舊使用者連線至 Cassandra。
- 按照「更新連線至 Cassandra 的 Edge 元件」一文中的操作說明,將所有 edge-* 元件指向新建立的使用者,以便連線至 Cassandra。
- 最後,當所有元件都使用新使用者與 Cassandra 通訊時,您可以使用
DROP ROLE指令刪除舊使用者。請注意,預設的 cassandra 角色不應捨棄。您可以捨棄任何自訂角色,只要 edge-* 元件並未使用這些角色與 Cassandra 通訊。
- 按照「啟用驗證」一節中的步驟建立新使用者。請注意,如果叢集已啟用驗證功能,且您已變更 cassandra 使用者的密碼,則必須透過
- 請務必在用於安裝或升級 Edge 元件的設定檔中,更新可用的 Cassandra 使用者名稱和密碼。這可消除或盡量減少邊緣作業期間的中斷情形。
在安裝期間啟用 Cassandra 驗證
您可以在安裝時啟用 Cassandra 驗證。
如要在安裝時啟用 Cassandra 驗證,請在所有 Cassandra 節點的設定檔中加入 CASS_AUTH 屬性:
CASS_AUTH=y # The default value is n.
下列 Edge 元件會存取 Cassandra:
- 管理伺服器
- 訊息處理器
- 路由器
- Qpid 伺服器
- Postgres 伺服器
安裝這些元件時,您必須在設定檔中設定使用者名稱和密碼:
CASS_USERNAME=cassandra_username CASS_PASSWORD=cassandra_password
安裝 Cassandra 後,您可以變更 Cassandra 憑證。不過,如果您已安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,也必須更新這些元件,才能使用新憑證。
如要在安裝 Cassandra 後變更 Cassandra 憑證,請按照下列步驟操作:
- 使用
cqlsh工具和預設憑證登入任一 Cassandra 節點。您只需要變更一個節點的密碼,系統就會將密碼廣播至環中的所有 Cassandra 節點:/opt/apigee/apigee-cassandra/bin/cqlsh cassIP 9042 -u cassandra_username -p cassandra_password
其中:
- cassIP 是 Cassandra 節點的 IP 位址。
- 9042 是預設的 Cassandra 通訊埠。
- 在 cqlsh> 提示中執行下列指令,更新密碼:
ALTER ROLE <username> WITH PASSWORD='
'; - 退出
cqlsh工具,如以下範例所示:exit
- 如果您尚未安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,請在設定檔中設定下列屬性,然後安裝這些元件:
CASS_USERNAME=cassandra_username CASS_PASSWORD=new_cassandra_password
- 如果您已安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,請參閱「重設 Edge 密碼」,瞭解如何更新這些元件以使用新密碼。
在安裝後啟用 Cassandra 驗證
如要在安裝後啟用驗證功能,請按照下列步驟操作:
- 使用 Cassandra 使用者名稱和密碼, 更新所有連線至 Cassandra 的 Edge 元件。
- 在所有 Cassandra 節點上啟用驗證,並在任一節點上設定 Cassandra 使用者名稱和密碼。您只需要變更一個 Cassandra 節點上的憑證,系統就會將憑證廣播至環中的所有 Cassandra 節點。
更新連線至 Cassandra 的 Edge 元件
請按照下列程序,使用新憑證更新所有與 Cassandra 通訊的 Edge 元件。請注意,您必須先執行這個步驟,才能實際更新 Cassandra 憑證:
- 在管理伺服器節點上,執行下列指令:
/opt/apigee/apigee-service/bin/apigee-service edge-management-server store_cassandra_credentials -u cassandra_username -p cassandra_password
您也可以選擇將包含新使用者名稱和密碼的檔案傳遞至指令:
apigee-service edge-management-server store_cassandra_credentials -f configFile
其中 configFile 包含下列內容:
CASS_USERNAME=cassandra_username # Default is cassandra CASS_PASSWORD='cassandra_password' # Default is cassandra; wrap in single quotes if it includes special chars
這項指令會自動重新啟動管理伺服器。
- 針對下列各項服務,重複執行步驟 1:
- 所有訊息處理器
- 所有路由器
- 所有 Qpid 伺服器 (edge-qpid-server)
- Postgres 伺服器 (edge-postgres-server)
為每項服務重複執行步驟 1 時,請將上述指令中的
edge-management-server替換為適當的服務名稱。舉例來說,執行 Router 服務的步驟時,請使用下列指令:/opt/apigee/apigee-service/bin/apigee-service edge-router store_cassandra_credentials -u cassandra -p cassandra
啟用驗證機制
請按照下列程序啟用 Cassandra 驗證,並設定使用者名稱和密碼:
- 建立靜音設定檔,並加入以下內容:
# Specify IP address or DNS name of cassandra node IP1=192.168.1.1 IP2=192.168.1.2 IP3=192.168.1.3 # Must resolve to IP address or DNS name of host HOSTIP=$(hostname -i) # Set to ‘y’ to enable Cassandra authentication. CASS_AUTH=y # Possible values are ‘y/n’ # Cassandra username. If it does not exist, this user would be created as a SUPERUSER CASS_USERNAME=cassandra_username # Default value is cassandra - don't use for production # Cassandra Password. If CASS_USERNAME does not exist, create SUPERUSER with this as password CASS_PASSWORD=cassandra_password # Default value is cassandra - don't use for production # Space-separated IP/DNS names of the Cassandra hosts CASS_HOSTS="$IP1:1,1 $IP2:1,1 $IP3:1,1" # Username of an existing C* user. Only needed if you have disabled or changed details of the default cassandra user(‘cassandra’) CASS_EXISTING_USERNAME=existing_cassandra_username # Password of an existing C* user. Only needed if you have disabled or change password of the default cassandra user(‘cassandra’) CASS_EXISTING_PASSWORD=existing_cassandra_password # Cassandra port CASS_PORT=9042 # The default port is 9042.
登入第一個 Cassandra 節點,然後執行下列指令:
apigee-service apigee-cassandra enable_cassandra_authentication -f CONFIG
您可以選擇將屬性做為指令引數傳遞至指令碼,如以下範例所示:
CASS_AUTH=y HOSTIP=$(hostname -i) CASS_PORT=9042 CASS_EXISTING_USERNAME=existing_cassandra_username CASS_EXISTING_PASSWORD=existing_cassandra_password CASS_USERNAME=cassandra_username CASS_PASSWORD=cassandra_password CASS_HOSTS="192.168.1.1:1,1 192.168.1.2:1,1 192.168.1.3:1,1" apigee-service apigee-cassandra enable_cassandra_authentication
注意:
- 如果是預設的 Cassandra 憑證,上述指令會啟用 Cassandra 驗證並重新啟動 Cassandra。
- 如果不是預設憑證,指令也會變更複製係數、建立超級使用者,並對
system_auth keyspace執行修復作業。
- 在所有 Cassandra 節點上重複執行步驟 1 和 2。