diff --git a/bitnami/clickhouse/22.3/debian-11/Dockerfile b/bitnami/clickhouse/22.3/debian-11/Dockerfile index 9ddfa9ace47f..774525ea6731 100644 --- a/bitnami/clickhouse/22.3/debian-11/Dockerfile +++ b/bitnami/clickhouse/22.3/debian-11/Dockerfile @@ -3,10 +3,10 @@ FROM docker.io/bitnami/minideb:bullseye ARG TARGETARCH LABEL org.opencontainers.image.base.name="docker.io/bitnami/minideb:bullseye" \ - org.opencontainers.image.created="2023-04-16T15:53:53Z" \ + org.opencontainers.image.created="2023-04-19T19:32:41Z" \ org.opencontainers.image.description="Application packaged by VMware, Inc" \ org.opencontainers.image.licenses="Apache-2.0" \ - org.opencontainers.image.ref.name="22.3.20-debian-11-r5" \ + org.opencontainers.image.ref.name="22.3.20-debian-11-r6" \ org.opencontainers.image.title="clickhouse" \ org.opencontainers.image.vendor="VMware, Inc." \ org.opencontainers.image.version="22.3.20" @@ -22,7 +22,6 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN install_packages ca-certificates curl procps xmlstarlet RUN mkdir -p /tmp/bitnami/pkg/cache/ && cd /tmp/bitnami/pkg/cache/ && \ COMPONENTS=( \ - "gosu-1.16.0-5-linux-${OS_ARCH}-debian-11" \ "clickhouse-22.3.20-0-linux-${OS_ARCH}-debian-11" \ ) && \ for COMPONENT in "${COMPONENTS[@]}"; do \ @@ -43,7 +42,7 @@ COPY rootfs / RUN /opt/bitnami/scripts/clickhouse/postunpack.sh ENV APP_VERSION="22.3.20" \ BITNAMI_APP_NAME="clickhouse" \ - PATH="/opt/bitnami/common/bin:/opt/bitnami/clickhouse/bin:$PATH" \ + PATH="/opt/bitnami/clickhouse/bin:/opt/bitnami/common/bin:$PATH" \ clickhouseCTL_API="3" EXPOSE 8123 9000 9004 9005 9009 diff --git a/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/.bitnami_components.json b/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/.bitnami_components.json index cdcb12222355..25eee5ed6c67 100644 --- a/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/.bitnami_components.json +++ b/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/.bitnami_components.json @@ -4,11 +4,5 @@ "distro": "debian-11", "type": "NAMI", "version": "22.3.20-0" - }, - "gosu": { - "arch": "amd64", - "distro": "debian-11", - "type": "NAMI", - "version": "1.16.0-5" } } \ No newline at end of file diff --git a/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/scripts/libos.sh b/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/scripts/libos.sh index 5e141d4ce3f1..e573899abacb 100644 --- a/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/scripts/libos.sh +++ b/bitnami/clickhouse/22.3/debian-11/prebuildfs/opt/bitnami/scripts/libos.sh @@ -553,3 +553,98 @@ get_root_disk_device_id() { get_root_disk_size() { fdisk -l "$(get_root_disk_device_id)" | grep 'Disk.*bytes' | sed -E 's/.*, ([0-9]+) bytes,.*/\1/' || true } + +######################## +# Run command as a specific user and group (optional) +# Arguments: +# $1 - USER(:GROUP) to switch to +# $2..$n - command to execute +# Returns: +# Exit code of the specified command +######################### +run_as_user() { + run_chroot "$@" +} + +######################## +# Execute command as a specific user and group (optional), +# replacing the current process image +# Arguments: +# $1 - USER(:GROUP) to switch to +# $2..$n - command to execute +# Returns: +# Exit code of the specified command +######################### +exec_as_user() { + run_chroot --replace-process "$@" +} + +######################## +# Run a command using chroot +# Arguments: +# $1 - USER(:GROUP) to switch to +# $2..$n - command to execute +# Flags: +# -r | --replace-process - Replace the current process image (optional) +# Returns: +# Exit code of the specified command +######################### +run_chroot() { + local userspec + local user + local homedir + local replace=false + local -r cwd="$(pwd)" + + # Parse and validate flags + while [[ "$#" -gt 0 ]]; do + case "$1" in + -r | --replace-process) + replace=true + ;; + --) + shift + break + ;; + -*) + stderr_print "unrecognized flag $1" + return 1 + ;; + *) + break + ;; + esac + shift + done + + # Parse and validate arguments + if [[ "$#" -lt 2 ]]; then + echo "expected at least 2 arguments" + return 1 + else + userspec=$1 + shift + + # userspec can optionally include the group, so we parse the user + user=$(echo "$userspec" | cut -d':' -f1) + fi + + if ! am_i_root; then + error "Could not switch to '${userspec}': Operation not permitted" + return 1 + fi + + # Get the HOME directory for the user to switch, as chroot does + # not properly update this env and some scripts rely on it + homedir=$(eval echo "~${user}") + if [[ ! -d $homedir ]]; then + homedir="${HOME:-/}" + fi + + # Obtaining value for "$@" indirectly in order to properly support shell parameter expansion + if [[ "$replace" = true ]]; then + exec chroot --userspec="$userspec" / bash -c "cd ${cwd}; export HOME=${homedir}; exec \"\$@\"" -- "$@" + else + chroot --userspec="$userspec" / bash -c "cd ${cwd}; export HOME=${homedir}; exec \"\$@\"" -- "$@" + fi +} \ No newline at end of file diff --git a/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/clickhouse/run.sh b/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/clickhouse/run.sh index 3cb64ebd1b4a..b6a60f97cf28 100755 --- a/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/clickhouse/run.sh +++ b/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/clickhouse/run.sh @@ -22,7 +22,7 @@ args+=("$@") info "** Starting ClickHouse **" if am_i_root; then - exec gosu "$CLICKHOUSE_DAEMON_USER" "${cmd[@]}" "${args[@]}" + exec_as_user "$CLICKHOUSE_DAEMON_USER" "${cmd[@]}" "${args[@]}" else exec "${cmd[@]}" "${args[@]}" fi diff --git a/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/libclickhouse.sh b/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/libclickhouse.sh index c0285f6147e8..4e1c857afcdb 100644 --- a/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/libclickhouse.sh +++ b/bitnami/clickhouse/22.3/debian-11/rootfs/opt/bitnami/scripts/libclickhouse.sh @@ -233,7 +233,7 @@ clickhouse_start_bg() { local -r cmd=("${CLICKHOUSE_BASE_DIR}/bin/clickhouse-server") local -r args=("--config-file=${CLICKHOUSE_CONF_FILE}" "--pid-file=${CLICKHOUSE_PID_FILE}" "--" "--listen_host=127.0.0.1") if am_i_root; then - gosu "$CLICKHOUSE_DAEMON_USER" "${cmd[@]}" "${args[@]}" >"$log_file" 2>&1 & + run_as_user "$CLICKHOUSE_DAEMON_USER" "${cmd[@]}" "${args[@]}" >"$log_file" 2>&1 & else "${cmd[@]}" "${args[@]}" >"$log_file" 2>&1 & fi