启用 Cassandra 身份验证

默认情况下,Cassandra 会在未启用身份验证的情况下安装。这意味着任何人都可以访问 Cassandra。您可以在安装 Edge 后启用身份验证,也可以在安装过程中启用身份验证。

您可以使用 Cassandra CREATE/ALTER/DROP USER 语句来添加、移除和修改用户。如需了解详情,请参阅 Cassandra SQL shell 命令

在安装期间启用 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 凭据,请执行以下操作:

  1. 使用 cqlsh 工具和默认凭据登录任何一个 Cassandra 节点。您只需在一个节点上更改密码,然后该节点会广播到环中的所有 Cassandra 节点:
    /opt/apigee/apigee-cassandra/bin/cqlsh cassIP 9042 -u cassandra_username -p cassandra_password

    其中:

    1. cassIP 是 Cassandra 节点的 IP 地址。
    2. 9042 是默认的 Cassandra 端口。
  2. cqlsh> 提示符处执行以下命令,以更新密码:
    ALTER USER cassandra_username/var> WITH PASSWORD 'new_cassandra_password';
  3. 退出 cqlsh 工具,如以下示例所示:
    exit
  4. 如果您尚未安装管理服务器、消息处理器、路由器、Qpid 服务器或 Postgres 服务器,请在配置文件中设置以下属性,然后安装这些组件:
    CASS_USERNAME=cassandra_username
    CASS_PASSWORD=new_cassandra_password
  5. 如果您已安装管理服务器、消息处理器、路由器、Qpid 服务器或 Postgres 服务器,请参阅重置边缘密码,了解更新这些组件以使用新密码的过程。

在安装后启用 Cassandra 身份验证

如需在安装后启用身份验证,请执行以下操作:

更新连接到 Cassandra 的 Edge 组件

按照以下步骤使用新凭据更新与 Cassandra 通信的所有 Edge 组件。请注意,在实际更新 Cassandra 凭据之前,请执行此步骤:

  1. 在 Management Server 节点上,运行以下命令:
    /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

    此命令会自动重启管理服务器。

  2. 针对以下每项服务,重复第 1 步:
    • 所有消息处理器
    • 所有路由器
    • 所有 Qpid 服务器 (edge-qpid-server)
    • Postgres 服务器 (edge-postgres-server)

    对每项服务重复第 1 步时,请将上述命令中的 edge-management-server 替换为相应的服务名称。例如,在针对路由器服务执行该步骤时,请使用以下命令:

    /opt/apigee/apigee-service/bin/apigee-service edge-router
      store_cassandra_credentials -u cassandra -p cassandra

启用身份验证

按照以下步骤启用 Cassandra 身份验证并设置用户名和密码:

  1. 使用如下所示的内容创建静默配置文件:
    # 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.
  2. 登录第一个 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 上运行修复。
  3. 对所有 Cassandra 节点重复执行第 1 步和第 2 步。