Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion scripts/rolling-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ ADMIN_ALLOW_INSECURE_DEV_COOKIE="${ADMIN_ALLOW_INSECURE_DEV_COOKIE:-false}"
# state); it just produces no callers without --adminEnabled.
KEYVIZ_ENABLED="${KEYVIZ_ENABLED:-false}"
KEYVIZ_FANOUT_NODES="${KEYVIZ_FANOUT_NODES:-}"
# Sub-range (hot-key) buckets per route. Empty omits the flag (binary
# default 1 = route-level). A positive integer (e.g. 64) divides each
# route into that many order-preserving sub-ranges so the heatmap shows
# hot sub-ranges, including for the unbounded single-route / tail case.
KEYVIZ_KEY_BUCKETS_PER_ROUTE="${KEYVIZ_KEY_BUCKETS_PER_ROUTE:-}"

# Validate the three boolean ADMIN_* flags must be the literal "true"
# or "false" — they are forwarded to the remote shell unquoted (no
Expand All @@ -265,6 +270,15 @@ for _bool_var in ADMIN_ENABLED ADMIN_ALLOW_PLAINTEXT_NON_LOOPBACK ADMIN_ALLOW_IN
done
unset _bool_var

# KeyViz sub-range buckets: empty (omit the flag) or a positive integer.
# Validate before it reaches the SSH heredoc / the binary's flag parser
# so an operator typo fails here with a clear message rather than as a
# container crash-loop on an unparseable --keyvizKeyBucketsPerRoute.
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^[1-9][0-9]*$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or a positive integer, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi
Comment on lines +277 to +280
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current validation checks if KEYVIZ_KEY_BUCKETS_PER_ROUTE is a positive integer, but it does not enforce the maximum limit of 256 (defined as MaxKeyBucketsPerRoute in keyviz/sampler.go).

If an operator configures a value larger than 256, it will be silently clamped by the Go binary. More importantly, if they enter an extremely large number that overflows a standard integer, the Go flag parser will fail to parse it, leading to a container crash-loop. This defeats the purpose of pre-validating the flag in this script.

We can use a precise regular expression to restrict the value to the valid range of 1 to 256 inclusive, which is also completely immune to integer overflow.

Suggested change
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^[1-9][0-9]*$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or a positive integer, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi
if [[ -n "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" && ! "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" =~ ^([1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-6])$ ]]; then
echo "rolling-update: KEYVIZ_KEY_BUCKETS_PER_ROUTE must be empty or an integer between 1 and 256, got '$KEYVIZ_KEY_BUCKETS_PER_ROUTE'" >&2
exit 1
fi


# Container OOM defenses. See usage() for rationale. Empty string disables.
DEFAULT_EXTRA_ENV="${DEFAULT_EXTRA_ENV-GOMEMLIMIT=1800MiB}"
CONTAINER_MEMORY_LIMIT="${CONTAINER_MEMORY_LIMIT-2500m}"
Expand Down Expand Up @@ -617,6 +631,7 @@ update_one_node() {
ADMIN_ALLOW_INSECURE_DEV_COOKIE="$ADMIN_ALLOW_INSECURE_DEV_COOKIE" \
KEYVIZ_ENABLED="$KEYVIZ_ENABLED" \
KEYVIZ_FANOUT_NODES="$KEYVIZ_FANOUT_NODES_Q" \
KEYVIZ_KEY_BUCKETS_PER_ROUTE="$KEYVIZ_KEY_BUCKETS_PER_ROUTE_Q" \
bash -s <<'REMOTE'
set -euo pipefail

Expand Down Expand Up @@ -1022,6 +1037,11 @@ build_keyviz_flags() {
if [[ -n "$fanout_nodes" ]]; then
_flags+=(--keyvizFanoutNodes "$fanout_nodes")
fi

local key_buckets="${KEYVIZ_KEY_BUCKETS_PER_ROUTE:-}"
if [[ -n "$key_buckets" ]]; then
_flags+=(--keyvizKeyBucketsPerRoute "$key_buckets")
fi
}

# build_admin_flags emits the --admin* flag list and bind-mount list
Expand Down Expand Up @@ -1230,7 +1250,7 @@ config_fp() {
"$ADMIN_SESSION_SIGNING_KEY_FILE" "$ADMIN_SESSION_SIGNING_KEY_PREVIOUS_FILE" \
"$ADMIN_TLS_CERT_FILE" "$ADMIN_TLS_KEY_FILE" \
"$ADMIN_ALLOW_PLAINTEXT_NON_LOOPBACK" "$ADMIN_ALLOW_INSECURE_DEV_COOKIE" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" \
"$KEYVIZ_ENABLED" "$KEYVIZ_FANOUT_NODES" "$KEYVIZ_KEY_BUCKETS_PER_ROUTE" \
| sha256sum | cut -d' ' -f1
}
DEPLOY_CONFIG_FP_LABEL="elastickv.deploy.config-fp"
Expand Down Expand Up @@ -1446,6 +1466,7 @@ ADMIN_TLS_KEY_FILE_Q="$(printf '%q' "$ADMIN_TLS_KEY_FILE")"
# survive an unquoted env pass but pre-quoting keeps the pattern
# uniform with the ADMIN_* set above.
KEYVIZ_FANOUT_NODES_Q="$(printf '%q' "$KEYVIZ_FANOUT_NODES")"
KEYVIZ_KEY_BUCKETS_PER_ROUTE_Q="$(printf '%q' "$KEYVIZ_KEY_BUCKETS_PER_ROUTE")"

echo "[rolling-update] target image: $IMAGE"
for node_id in "${ROLLING_NODE_IDS[@]}"; do
Expand Down
Loading