@@ -890,6 +890,69 @@ scale_out_redis_cluster_shard() {
890890 return 0
891891}
892892
893+ sync_acl_for_redis_cluster_shard () {
894+ echo " Sync ACL rules for redis cluster shard..."
895+ set +ex
896+ redis_base_cmd=" redis-cli -p $SERVICE_PORT -a $REDIS_DEFAULT_PASSWORD "
897+ if [ -z " $REDIS_DEFAULT_PASSWORD " ]; then
898+ redis_base_cmd=" redis-cli -p $SERVICE_PORT "
899+ fi
900+ is_ok=false
901+ acl_list=" "
902+ # 1. get acl list from other pods
903+ for pod_name in $( echo " $KB_CLUSTER_POD_NAME_LIST " | tr ' ,' ' ' ) ; do
904+ pod_ip=$( parse_host_ip_from_built_in_envs " $pod_name " " $KB_CLUSTER_POD_NAME_LIST " " $KB_CLUSTER_POD_IP_LIST " )
905+ if is_empty " $pod_ip " ; then
906+ echo " Failed to get the host ip of the pod $pod_name "
907+ continue
908+ fi
909+
910+ cluster_info=$( get_cluster_info_with_retry " $pod_ip " " $SERVICE_PORT " )
911+ status=$?
912+ if [ $status -ne 0 ]; then
913+ continue
914+ fi
915+ cluster_state=$( echo " $cluster_info " | awk -F: ' /cluster_state/{print $2}' | tr -d ' [:space:]' )
916+ if is_empty " $cluster_state " || equals " $cluster_state " " ok" ; then
917+ acl_list=$( $redis_base_cmd -h " $pod_ip " ACL LIST)
918+ is_ok=true
919+ break
920+ fi
921+ done
922+
923+ if [ " $is_ok " = false ]; then
924+ echo " Failed to get ACL LIST from other shard pods" >&2
925+ exit 1
926+ fi
927+
928+ if [ -z " $acl_list " ]; then
929+ echo " No ACL rules found in other pods, skip synchronization" >&2
930+ return
931+ fi
932+ # 2. apply acl list to current shard pods
933+ set -e
934+ while IFS= read -r user_rule; do
935+ [[ -z " $user_rule " ]] && continue
936+
937+ if [[ " $user_rule " =~ ^user[[:space:]]+ ([^[:space:]]+) ]]; then
938+ username=" ${BASH_REMATCH[1]} "
939+ else
940+ # skip invalid user rule
941+ continue
942+ fi
943+
944+ if [[ " $username " == " default" ]]; then
945+ continue
946+ fi
947+ rule_part=" ${user_rule# user $username } "
948+ for pod_fqdn in $( echo " $CURRENT_SHARD_POD_FQDN_LIST " | tr ' ,' ' \n' ) ; do
949+ $redis_base_cmd -h $pod_fqdn ACL SETUSER " $username " $rule_part >&2
950+ $redis_base_cmd -h $pod_fqdn ACL save >&2
951+ done
952+ done <<< " $acl_list"
953+ set_xtrace_when_ut_mode_false
954+ }
955+
893956scale_in_redis_cluster_shard () {
894957 # check KB_CLUSTER_COMPONENT_IS_SCALING_IN env
895958 if is_empty " $KB_CLUSTER_COMPONENT_IS_SCALING_IN " ; then
@@ -971,6 +1034,7 @@ initialize_or_scale_out_redis_cluster() {
9711034 return 1
9721035 fi
9731036 else
1037+ sync_acl_for_redis_cluster_shard
9741038 echo " Redis Cluster already initialized, scaling out the shard..."
9751039 if scale_out_redis_cluster_shard; then
9761040 echo " Redis Cluster scale out shard successfully"
0 commit comments