From 060c83e57c64299bc24510b9e57e42001f52a492 Mon Sep 17 00:00:00 2001 From: Linying Assad Date: Thu, 12 Nov 2026 12:38:44 +0800 Subject: [PATCH 1/3] [improvement](build) Run FE and BE runtime images as non-root ### What problem does this PR solve? Issue Number: N/A Problem Summary: FE and BE runtime images default to root, and operator entrypoints modify configuration projected from read-only ConfigMaps. Create a configurable doris UID/GID (10001 by default), assign runtime files and directories to that user, and switch the runtime images to it. Copy writable FE/BE configuration before startup updates it. Route the default Kerberos configuration link through the writable Doris conf directory, including when the entrypoint runs repeatedly. ### Release note FE and BE images run as UID/GID 10001 by default. Kubernetes deployments can supply fsGroup and disable the Operator's system init and cgroup setup. No host cgroup delegation is provisioned. Host kernel tuning and volume-driver support remain platform constraints. ### Check List (For Author) - Test: ShellCheck and bash syntax; projected-config tests for four entrypoints; Kerberos config and repeated-start tests as the image's non-root user; Docker builds; existing Operator 26.0.1 on K3s 1.34.12 with fresh PVCs, no init containers, UID 10001 and all capabilities dropped; SQL, Stream Load, WG queue timeout, fixed-slot memory limit, CPU limit behavior, and persisted data after recreating both Pods. Runtime validation uses packaged Doris 4.1.4 binaries; the master engine was not rebuilt. - Behavior changed: Yes, default image user and writable configuration handling. - Does this need documentation: Yes, included in docker/runtime/README.md. --- docker/runtime/README.md | 41 +++++++++ docker/runtime/be/Dockerfile | 16 +++- .../resource/be_disaggregated_entrypoint.sh | 13 ++- docker/runtime/be/resource/be_entrypoint.sh | 13 ++- docker/runtime/fe/Dockerfile | 16 +++- .../resource/fe_disaggregated_entrypoint.sh | 3 +- docker/runtime/fe/resource/fe_entrypoint.sh | 18 +++- docker/runtime/test/non-root-config-test.sh | 84 +++++++++++++++++++ 8 files changed, 198 insertions(+), 6 deletions(-) create mode 100755 docker/runtime/test/non-root-config-test.sh diff --git a/docker/runtime/README.md b/docker/runtime/README.md index 51bd244f75588f..d7b8f11f5d9fdd 100644 --- a/docker/runtime/README.md +++ b/docker/runtime/README.md @@ -109,3 +109,44 @@ $ cd doris/runtime/ms && docker build . -t doris.ms:3.0.2 -f Dockerfile --build- ### Latest update time 2025-02-12 + +## Running FE and BE without root + +FE and BE images run as `doris` (`10001:10001`) by default. Build arguments +`DORIS_UID` and `DORIS_GID` customize these IDs. Image-owned configuration, +logs, metadata and storage directories are writable by this user. The SQL +administrator account is independent of the operating-system user. The image +provides `/etc/krb5.conf` as a link into the writable Doris configuration +directory, so Operator-mounted Kerberos configuration does not require writes +to `/etc` at startup. + +For Kubernetes, configure the FE and BE Pod security context, for example: + +```yaml +runAsNonRoot: true +runAsUser: 10001 +runAsGroup: 10001 +fsGroup: 10001 +``` + +Use the container security context to set `allowPrivilegeEscalation: false` +and drop all capabilities. With Doris Operator, set BE `enableWorkloadGroup` +to `false` and `skipDefaultSystemInit` to `true` to avoid privileged cgroup +setup and the default system init container. Check the generated Pod to +confirm these settings; custom init containers must also be omitted. + +Skipping system initialization does not tune the host. Doris recommends +`vm.max_map_count >= 2000000`, disabled swap and a sufficient file-descriptor +limit. A non-root image cannot change these host settings. Operator versions +that set `SKIP_CHECK_ULIMIT=true` bypass startup checks, but this does not +remove the underlying kernel limits or their effects under load. Persistent +volumes must be writable by the configured UID/GID; `fsGroup` requires volume +driver support. Existing root-owned data needs its permissions prepared +separately. Custom log, cache, Kerberos and keytab paths must also be readable +or writable as required by Doris. A read-only container root filesystem is +not implied by running without root. + +Without a writable, delegated CPU cgroup, Workload Group CPU weights and CPU +hard limits are unavailable. Leave `doris_cgroup_cpu_path` unset in this mode. +Other Workload Group controls, including query admission and memory limits, +remain available; Kubernetes container CPU limits continue to apply. diff --git a/docker/runtime/be/Dockerfile b/docker/runtime/be/Dockerfile index 62708e384b7691..28181ad7310ca7 100644 --- a/docker/runtime/be/Dockerfile +++ b/docker/runtime/be/Dockerfile @@ -31,6 +31,13 @@ FROM apache/doris:base-6.0 ARG TARGETARCH ARG DORIS_VERSION="x.x.x" +ARG DORIS_UID=10001 +ARG DORIS_GID=10001 + +RUN groupadd --gid "${DORIS_GID}" doris && \ + useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris + +ENV HOME=/home/doris RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([1-9]([0-9])))|master.*' >>/dev/null ; then \ @@ -45,7 +52,7 @@ RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([ ENV JAVA_HOME=/usr/lib/jvm/java ENV PATH=$PATH:$JAVA_HOME/bin:/opt/apache-doris/be/bin -COPY resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/be /opt/apache-doris/be +COPY --chown=${DORIS_UID}:${DORIS_GID} resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/be /opt/apache-doris/be COPY resource/be_*.sh /opt/apache-doris/ @@ -55,6 +62,13 @@ COPY resource/init_be.sh /usr/local/bin/ #RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +# Create writable runtime directories before dropping privileges. +RUN mkdir -p /opt/apache-doris/be/log /opt/apache-doris/be/storage && \ + chown "${DORIS_UID}:${DORIS_GID}" /opt/apache-doris /opt/apache-doris/be/log /opt/apache-doris/be/storage && \ + ln -sf /opt/apache-doris/be/conf/krb5.conf /etc/krb5.conf + +USER ${DORIS_UID}:${DORIS_GID} + WORKDIR /opt/apache-doris ENTRYPOINT ["bash","entry_point.sh"] diff --git a/docker/runtime/be/resource/be_disaggregated_entrypoint.sh b/docker/runtime/be/resource/be_disaggregated_entrypoint.sh index 78365b772edc30..58fe7afa00c789 100755 --- a/docker/runtime/be/resource/be_disaggregated_entrypoint.sh +++ b/docker/runtime/be/resource/be_disaggregated_entrypoint.sh @@ -118,7 +118,8 @@ update_conf_from_configmap() mv -f $tgt ${tgt}.bak fi if [[ "$conffile" == "be.conf" ]]; then - cp $CONFIGMAP_MOUNT_PATH/$conffile $DORIS_HOME/conf/$conffile + cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" + chmod u+w "$tgt" echo "" >> $DORIS_HOME/conf/$conffile echo "########## doris-operator automatically adds ##########" >> $DORIS_HOME/conf/$conffile echo "deploy_mode = cloud" >> $DORIS_HOME/conf/$conffile @@ -549,6 +550,16 @@ mount_kerberos_config() fi KRB5_CONFIG_DIR=$(dirname "$KRB5_CONFIG") + # Resolve only the first link: the conf file may already link to a read-only ConfigMap. + if [[ -L "$KRB5_CONFIG" ]]; then + local config_link + config_link=$(readlink "$KRB5_CONFIG") + if [[ "$config_link" == /* ]]; then + KRB5_CONFIG_DIR=$(dirname "$config_link") + else + KRB5_CONFIG_DIR="$KRB5_CONFIG_DIR/$(dirname "$config_link")" + fi + fi # If the krb5 directory does not exist, need to create it. if [[ ! -d "$KRB5_CONFIG_DIR" ]]; then log_stderr "[info] Creating krb5 directory: $KRB5_CONFIG_DIR" diff --git a/docker/runtime/be/resource/be_entrypoint.sh b/docker/runtime/be/resource/be_entrypoint.sh index 0e6bb9c7edacc7..07cf8e672ab312 100755 --- a/docker/runtime/be/resource/be_entrypoint.sh +++ b/docker/runtime/be/resource/be_entrypoint.sh @@ -100,7 +100,8 @@ update_conf_from_configmap() mv -f $tgt ${tgt}.bak fi if [[ "$conffile" == "be.conf" ]]; then - cp $CONFIGMAP_MOUNT_PATH/$conffile $DORIS_HOME/conf/$file + cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" + chmod u+w "$tgt" continue fi ln -sfT $CONFIGMAP_MOUNT_PATH/$conffile $tgt @@ -114,6 +115,16 @@ mount_kerberos_config() fi KRB5_CONFIG_DIR=$(dirname "$KRB5_CONFIG") + # Resolve only the first link: the conf file may already link to a read-only ConfigMap. + if [[ -L "$KRB5_CONFIG" ]]; then + local config_link + config_link=$(readlink "$KRB5_CONFIG") + if [[ "$config_link" == /* ]]; then + KRB5_CONFIG_DIR=$(dirname "$config_link") + else + KRB5_CONFIG_DIR="$KRB5_CONFIG_DIR/$(dirname "$config_link")" + fi + fi # If the krb5 directory does not exist, need to create it. if [[ ! -d "$KRB5_CONFIG_DIR" ]]; then log_stderr "[info] Creating krb5 directory: $KRB5_CONFIG_DIR" diff --git a/docker/runtime/fe/Dockerfile b/docker/runtime/fe/Dockerfile index 88bf8401d70903..1f098c1fe98570 100644 --- a/docker/runtime/fe/Dockerfile +++ b/docker/runtime/fe/Dockerfile @@ -30,6 +30,13 @@ FROM apache/doris:base-6.0 ARG TARGETARCH ARG DORIS_VERSION="x.x.x" +ARG DORIS_UID=10001 +ARG DORIS_GID=10001 + +RUN groupadd --gid "${DORIS_GID}" doris && \ + useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris + +ENV HOME=/home/doris RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([1-9]([0-9])))|master.*' >>/dev/null ; then \ ln -s /usr/lib/jvm/jdk-17 /usr/lib/jvm/java && \ @@ -43,7 +50,7 @@ RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([ ENV JAVA_HOME=/usr/lib/jvm/java ENV PATH=$PATH:$JAVA_HOME/bin:/opt/apache-doris/fe/bin -COPY resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/fe /opt/apache-doris/fe +COPY --chown=${DORIS_UID}:${DORIS_GID} resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/fe /opt/apache-doris/fe ADD resource/init_fe.sh /usr/local/bin/ @@ -52,6 +59,13 @@ COPY resource/fe_*.sh /opt/apache-doris/ # when you use beijing zone, please enable the set. # RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +# Create writable runtime directories before dropping privileges. +RUN mkdir -p /opt/apache-doris/fe/log /opt/apache-doris/fe/doris-meta && \ + chown "${DORIS_UID}:${DORIS_GID}" /opt/apache-doris /opt/apache-doris/fe/log /opt/apache-doris/fe/doris-meta && \ + ln -sf /opt/apache-doris/fe/conf/krb5.conf /etc/krb5.conf + +USER ${DORIS_UID}:${DORIS_GID} + WORKDIR /opt/apache-doris ENTRYPOINT ["bash","init_fe.sh"] diff --git a/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh b/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh index 496c0ce22ab660..a23a307baaf030 100755 --- a/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh +++ b/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh @@ -435,7 +435,8 @@ function link_config_files() for file in `ls $CONFIGMAP_MOUNT_PATH`; do if [[ "$file" == "fe.conf" ]]; then - cp $CONFIGMAP_MOUNT_PATH/$file $DORIS_HOME/conf/$file + cp "$CONFIGMAP_MOUNT_PATH/$file" "$DORIS_HOME/conf/$file" + chmod u+w "$DORIS_HOME/conf/$file" add_cluster_info_to_conf continue fi diff --git a/docker/runtime/fe/resource/fe_entrypoint.sh b/docker/runtime/fe/resource/fe_entrypoint.sh index 7ea6866f1a0525..dd51e964c5c034 100755 --- a/docker/runtime/fe/resource/fe_entrypoint.sh +++ b/docker/runtime/fe/resource/fe_entrypoint.sh @@ -433,7 +433,13 @@ update_conf_from_configmap() # make a backup mv -f $tgt ${tgt}.bak fi - ln -sfT $CONFIGMAP_MOUNT_PATH/$conffile $tgt + if [[ "$conffile" == "fe.conf" ]]; then + # Startup appends configuration; projected ConfigMap files are read-only. + cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" + chmod u+w "$tgt" + else + ln -sfT "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" + fi done add_fqdn_config } @@ -445,6 +451,16 @@ mount_kerberos_config() fi KRB5_CONFIG_DIR=$(dirname "$KRB5_CONFIG") + # Resolve only the first link: the conf file may already link to a read-only ConfigMap. + if [[ -L "$KRB5_CONFIG" ]]; then + local config_link + config_link=$(readlink "$KRB5_CONFIG") + if [[ "$config_link" == /* ]]; then + KRB5_CONFIG_DIR=$(dirname "$config_link") + else + KRB5_CONFIG_DIR="$KRB5_CONFIG_DIR/$(dirname "$config_link")" + fi + fi # If the krb5 directory does not exist, need to create it. if [[ ! -d "$KRB5_CONFIG_DIR" ]]; then log_stderr "[info] Creating krb5 directory: $KRB5_CONFIG_DIR" diff --git a/docker/runtime/test/non-root-config-test.sh b/docker/runtime/test/non-root-config-test.sh new file mode 100755 index 00000000000000..0005a8630cb2c0 --- /dev/null +++ b/docker/runtime/test/non-root-config-test.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -euo pipefail + +RUNTIME_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +TEST_DIR=$(mktemp -d) +trap 'chmod -R u+w "${TEST_DIR}"; rm -rf "${TEST_DIR}"' EXIT + +log_stderr() { :; } +add_fqdn_config() { echo 'enable_fqdn_mode = true' >> "${DORIS_HOME}/conf/fe.conf"; } + +add_cluster_info_to_conf() { echo 'deploy_mode = cloud' >> "${DORIS_HOME}/conf/fe.conf"; } + +for variant in fe be fe_disaggregated be_disaggregated; do + ( + component=${variant%%_*} + DORIS_HOME="${TEST_DIR}/${variant}" + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/${variant}-configmap" + mkdir -p "${DORIS_HOME}/conf" "${CONFIGMAP_MOUNT_PATH}/..data" + printf '# projected config\n' > "${CONFIGMAP_MOUNT_PATH}/..data/${component}.conf" + chmod 444 "${CONFIGMAP_MOUNT_PATH}/..data/${component}.conf" + ln -s "..data/${component}.conf" "${CONFIGMAP_MOUNT_PATH}/${component}.conf" + printf '# original config\n' > "${DORIS_HOME}/conf/${component}.conf" + # Load only the configuration function, without executing the entrypoint. + if [[ "${variant}" == fe_disaggregated ]]; then + # shellcheck disable=SC1090 + source <(sed -n '/^function link_config_files()/,/^}/p' \ + "${RUNTIME_DIR}/fe/resource/fe_disaggregated_entrypoint.sh") + link_config_files + else + # shellcheck disable=SC1090 + source <(sed -n '/^update_conf_from_configmap()/,/^}/p' \ + "${RUNTIME_DIR}/${component}/resource/${variant}_entrypoint.sh") + update_conf_from_configmap + fi + test ! -L "${DORIS_HOME}/conf/${component}.conf" + grep -q '^# projected config$' "${DORIS_HOME}/conf/${component}.conf" + grep -q '^# original config$' "${DORIS_HOME}/conf/${component}.conf.bak" + echo 'test_setting = true' >> "${DORIS_HOME}/conf/${component}.conf" + test "$(wc -l < "${CONFIGMAP_MOUNT_PATH}/${component}.conf")" -eq 1 + ) +done + +echo 'Non-root projected configuration tests passed' + +for variant in fe be be_disaggregated; do + ( + component=${variant%%_*} + DORIS_HOME="${TEST_DIR}/${variant}" + KRB5_MOUNT_PATH="${TEST_DIR}/${variant}-kerberos" + KRB5_CONFIG="${TEST_DIR}/${variant}-etc/krb5.conf" + export KEYTAB_MOUNT_PATH= + export KEYTAB_FINAL_USED_PATH= + mkdir -p "${KRB5_MOUNT_PATH}" "$(dirname "${KRB5_CONFIG}")" + printf '[libdefaults]\n default_realm = TEST.LOCAL\n' > "${KRB5_MOUNT_PATH}/krb5.conf" + ln -s "${DORIS_HOME}/conf/krb5.conf" "${KRB5_CONFIG}" + chmod 555 "$(dirname "${KRB5_CONFIG}")" + # shellcheck disable=SC1090 + source <(sed -n '/^mount_kerberos_config()/,/^}/p' \ + "${RUNTIME_DIR}/${component}/resource/${variant}_entrypoint.sh") + mount_kerberos_config + mount_kerberos_config + cmp "${KRB5_MOUNT_PATH}/krb5.conf" "${KRB5_CONFIG}" + test -L "${DORIS_HOME}/conf/krb5.conf" + ) +done + +echo 'Non-root Kerberos configuration tests passed' From 073847bc92f57b810c183e7cec883664c514ed7a Mon Sep 17 00:00:00 2001 From: Linying Assad Date: Fri, 20 Nov 2026 21:29:15 +0800 Subject: [PATCH 2/3] [improvement](build) Complete non-root Meta Service runtime support ### Background Standalone FE and BE images already use a configurable non-root Doris user. Meta Service shares the runtime packaging workflow and loads configuration projected by the Kubernetes Operator before starting Meta Service and Recycler. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Enhancement Problem Summary: Meta Service still defaults to root, and its startup configuration handling does not consistently prepare a writable configuration or preserve an existing FDB endpoint when the environment override is absent. Run MS and Recycler as the same default UID/GID as FE and BE, prepare writable configuration, and forward custom IDs through the shared image build helper. ### Details - Before and after: MS changes from root to UID/GID 10001. Image-owned runtime directories are writable; ConfigMap-backed primary configuration is copied and made writable before the FDB endpoint is applied. Repeated starts replace the endpoint instead of accumulating assignments. Role arguments are forwarded. - Configs and defaults: DORIS_UID and DORIS_GID default to 10001 for all component builds. An absent FDB_ENDPOINT preserves the configured endpoint. - Impact on existing users: Existing root-owned volumes require a separate permission migration. No migration or privileged helper is introduced. - Behavior change: MS and Recycler now run without root by default; startup preparation errors fail immediately and the entrypoint execs the start script. ### Testing - Bash syntax, targeted ShellCheck, and git diff --check pass. - Projected read-only configuration and repeated-start tests pass under UID 10001 with all capabilities dropped. Removing the writable-mode correction causes the MS test to fail with Permission denied. - Built standalone linux/amd64 FE, BE and MS images with official, SHA-512-verified Doris 4.1.4 packaged binaries. Verified image IDs after K3s containerd import. - Unmodified Operator 26.0.1 on native x86_64 K3s v1.34.13: DorisCluster and DorisDisaggregatedCluster both start in restricted namespaces with fresh local-path PVCs, no init containers, UID/GID 10001, zero effective capabilities, no privilege escalation and RuntimeDefault seccomp. - SQL insert, Stream Load and queries pass in both deployment modes. Recreated all Doris pods through CR annotations and verified unchanged PVC identities and all five expected rows after service recovery. MS and Recycler both start. - Observed duplicate backend-registration retries and transient DNS/gRPC query recovery after cloud backend replacement; eventual checks pass. These existing startup/reconnection paths are unchanged by this patch. ### Release note Meta Service and Recycler runtime images now use UID/GID 10001 by default, matching FE and BE. Configure writable volumes and matching Kubernetes security contexts; existing root-owned volumes need their permissions prepared separately. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes, included in docker/runtime/README.md. - Pre-submission status: Partially verified: native amd64 with packaged 4.1.4; arm64, the current master engine and existing-PVC migration were not tested. ### AI Disclosure - Tool: Codex. - Generated: Runtime changes, tests, documentation and this description. - Human review: Pending author review. --- docker/runtime/README.md | 40 ++++++++++++-- docker/runtime/docker-build.sh | 8 +-- docker/runtime/ms/Dockerfile | 14 ++++- .../resource/ms_disaggregated_entrypoint.sh | 54 +++++++++++-------- docker/runtime/test/non-root-config-test.sh | 37 +++++++++++++ 5 files changed, 121 insertions(+), 32 deletions(-) diff --git a/docker/runtime/README.md b/docker/runtime/README.md index d7b8f11f5d9fdd..92a31b356b335f 100644 --- a/docker/runtime/README.md +++ b/docker/runtime/README.md @@ -110,9 +110,10 @@ $ cd doris/runtime/ms && docker build . -t doris.ms:3.0.2 -f Dockerfile --build- 2025-02-12 -## Running FE and BE without root +## Running FE, BE and Meta Service without root -FE and BE images run as `doris` (`10001:10001`) by default. Build arguments +The standalone FE, BE and MS images run as `doris` (`10001:10001`) by default. +The MS image also runs Recycler under this identity. Build arguments `DORIS_UID` and `DORIS_GID` customize these IDs. Image-owned configuration, logs, metadata and storage directories are writable by this user. The SQL administrator account is independent of the operating-system user. The image @@ -120,21 +121,50 @@ provides `/etc/krb5.conf` as a link into the writable Doris configuration directory, so Operator-mounted Kerberos configuration does not require writes to `/etc` at startup. -For Kubernetes, configure the FE and BE Pod security context, for example: +The `docker-build.sh` helper forwards `DORIS_UID` and `DORIS_GID` environment +variables to all three image builds. Use the same IDs in the image and the +Kubernetes configuration, and keep them stable across releases. + +For Kubernetes, configure each component's Pod security context, for example: ```yaml runAsNonRoot: true runAsUser: 10001 runAsGroup: 10001 fsGroup: 10001 +seccompProfile: + type: RuntimeDefault ``` -Use the container security context to set `allowPrivilegeEscalation: false` -and drop all capabilities. With Doris Operator, set BE `enableWorkloadGroup` +Use the container security context to set `privileged: false`, +`allowPrivilegeEscalation: false` and drop all capabilities. With Doris Operator, +set BE `enableWorkloadGroup` to `false` and `skipDefaultSystemInit` to `true` to avoid privileged cgroup setup and the default system init container. Check the generated Pod to confirm these settings; custom init containers must also be omitted. +With Operator 26.0.1, these settings are available without changing the +Operator. For a `DorisCluster`, set `feSpec.securityContext` and +`beSpec.securityContext`, and the corresponding `containerSecurityContext` +fields. For a `DorisDisaggregatedCluster`, configure `metaService`, `feSpec` +and every `computeGroups` entry. Set `skipDefaultSystemInit: true` and +`enableWorkloadGroup: false` on each BE/compute group. The Operator switch +controls cgroup setup; it does not disable query admission or memory controls. + +For MS, `doris_cloud.conf` from a ConfigMap is copied into a writable file +before applying `FDB_ENDPOINT`. Without that environment variable, the +configured `fdb_cluster` is preserved. The same entrypoint supports the +packaged default (Meta Service and Recycler) or explicit `--meta-service` +and `--recycler` arguments. FoundationDB and object storage are external +dependencies with their own container-user and storage requirements. + +New volumes still need to be writable: image ownership does not override a +mounted volume's permissions. Validate the actual StorageClass with a fresh +PVC. A successful deployment with local-path storage is not proof that every +CSI driver supports the same permissions. The non-root configuration can be +validated in a namespace enforcing the Kubernetes `restricted` Pod Security +Standard; a storage provisioner's infrastructure is managed separately. + Skipping system initialization does not tune the host. Doris recommends `vm.max_map_count >= 2000000`, disabled swap and a sufficient file-descriptor limit. A non-root image cannot change these host settings. Operator versions diff --git a/docker/runtime/docker-build.sh b/docker/runtime/docker-build.sh index ae980916af9f92..9fd64c841d3022 100755 --- a/docker/runtime/docker-build.sh +++ b/docker/runtime/docker-build.sh @@ -32,6 +32,8 @@ usage() { } version= +DORIS_UID=${DORIS_UID:-10001} +DORIS_GID=${DORIS_GID:-10001} OPTS="$(getopt -n "$0" -o 'v:' -- "$*")" eval set -- "${OPTS}" @@ -103,13 +105,13 @@ cd base-image/ && docker build -t apache/doris:base-latest -f Dockerfile_base . cd - echo "docker build fe image,tag=doris.fe:${version}" -cd fe/ && docker build -t doris.fe:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} . +cd fe/ && docker build -t doris.fe:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} --build-arg DORIS_UID="${DORIS_UID}" --build-arg DORIS_GID="${DORIS_GID}" . cd - echo "docker build be image,tag=doris.be:${version}" -cd be/ && docker build -t doris.be:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} . +cd be/ && docker build -t doris.be:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} --build-arg DORIS_UID="${DORIS_UID}" --build-arg DORIS_GID="${DORIS_GID}" . cd - echo "docker build ms image,tag=doris.ms:${version}" -cd ms/ && docker build -t doris.ms:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} . +cd ms/ && docker build -t doris.ms:${version} -f Dockerfile --build-arg DORIS_VERSION=${version} --build-arg DORIS_UID="${DORIS_UID}" --build-arg DORIS_GID="${DORIS_GID}" . cd - diff --git a/docker/runtime/ms/Dockerfile b/docker/runtime/ms/Dockerfile index 0720bce2501fa5..92ae0f08fc5bb1 100644 --- a/docker/runtime/ms/Dockerfile +++ b/docker/runtime/ms/Dockerfile @@ -31,7 +31,13 @@ FROM apache/doris:base-6.0 ARG TARGETARCH ARG DORIS_VERSION="x.x.x" +ARG DORIS_UID=10001 +ARG DORIS_GID=10001 +RUN groupadd --gid "${DORIS_GID}" doris && \ + useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris + +ENV HOME=/home/doris RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([1-9]([0-9])))|master.*' >>/dev/null ; then \ ln -s /usr/lib/jvm/jdk-17 /usr/lib/jvm/java && \ @@ -45,12 +51,18 @@ RUN if echo $DORIS_VERSION | grep -E '^([3-9]|([1-9]([0-9])))|^branch\-([3-9]|([ ENV JAVA_HOME=/usr/lib/jvm/java ENV PATH=$PATH:$JAVA_HOME/bin:/opt/apache-doris/ms/bin -COPY resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/ms /opt/apache-doris/ms +COPY --chown=${DORIS_UID}:${DORIS_GID} resource/${TARGETARCH:-amd64}/apache-doris-${DORIS_VERSION}-bin-*/ms /opt/apache-doris/ms COPY resource/ms_*.sh /opt/apache-doris/ #RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN mkdir -p /opt/apache-doris/ms/log && \ + chown "${DORIS_UID}:${DORIS_GID}" /opt/apache-doris /opt/apache-doris/ms/log && \ + ln -sf /opt/apache-doris/ms/conf/krb5.conf /etc/krb5.conf + +USER ${DORIS_UID}:${DORIS_GID} + WORKDIR /opt/apache-doris #ENTRYPOINT ["bash","entry_point.sh"] diff --git a/docker/runtime/ms/resource/ms_disaggregated_entrypoint.sh b/docker/runtime/ms/resource/ms_disaggregated_entrypoint.sh index bdb42cf6724b0e..a816325f4a824a 100755 --- a/docker/runtime/ms/resource/ms_disaggregated_entrypoint.sh +++ b/docker/runtime/ms/resource/ms_disaggregated_entrypoint.sh @@ -16,32 +16,40 @@ # specific language governing permissions and limitations # under the License. -# +set -eo pipefail -#get from env -FDB_ENDPOINT=${FDB_ENDPOINT} -CONFIGMAP_PATH=${CONFIGMAP_PATH:="/etc/doris"} -DORIS_HOME=${DORIS_HOME:="/opt/apache-doris"} +CONFIGMAP_PATH=${CONFIGMAP_PATH:-/etc/doris} +DORIS_HOME=${DORIS_HOME:-/opt/apache-doris} -echo "" >> $DORIS_HOME/ms/conf/doris_cloud.conf -echo "fdb_cluster=$FDB_ENDPOINT" >> $DORIS_HOME/ms/conf/doris_cloud.conf -if [[ -d $CONFIGMAP_PATH ]]; then - for file in `ls $CONFIGMAP_PATH` - do - if [[ "$file" == "doris_cloud.conf" ]] ; then - mv -f $DORIS_HOME/ms/conf/$file $DORIS_HOME/ms/conf/$file.bak - cp $CONFIGMAP_PATH/$file $DORIS_HOME/ms/conf/$file - echo "fdb_cluster=$FDB_ENDPOINT" >> $DORIS_HOME/ms/conf/doris_cloud.conf - continue +update_conf_from_configmap() +{ + local source target file + if [[ -d "${CONFIGMAP_PATH}" ]]; then + for source in "${CONFIGMAP_PATH}"/*; do + [[ -f "${source}" ]] || continue + file=$(basename "${source}") + target="${DORIS_HOME}/ms/conf/${file}" + if [[ -e "${target}" || -L "${target}" ]]; then + mv -f "${target}" "${target}.bak" fi - - if test -e $DORIS_HOME/ms/conf/$file ; then - mv -f $DORIS_HOME/ms/conf/$file $DORIS_HOME/ms/conf/$file.bak + if [[ "${file}" == doris_cloud.conf ]]; then + # Projected ConfigMaps are read-only; startup needs a writable copy. + cp "${source}" "${target}" + chmod u+w "${target}" + else + ln -sfT "${source}" "${target}" fi - ln -sfT $CONFIGMAP_PATH/$file $DORIS_HOME/ms/conf/$file - done -fi + done + fi -./doris-debug --component ms + if [[ -n "${FDB_ENDPOINT:-}" ]]; then + target="${DORIS_HOME}/ms/conf/doris_cloud.conf" + # Do not accumulate endpoint assignments when the entrypoint is rerun. + sed -i '/^[[:space:]]*fdb_cluster[[:space:]]*=/d' "${target}" + printf '\nfdb_cluster=%s\n' "${FDB_ENDPOINT}" >> "${target}" + fi +} -$DORIS_HOME/ms/bin/start.sh --console --conf=$DORIS_HOME/ms/conf/doris_cloud.conf +update_conf_from_configmap +"${DORIS_HOME}/doris-debug" --component ms +exec "${DORIS_HOME}/ms/bin/start.sh" --console "--conf=${DORIS_HOME}/ms/conf/doris_cloud.conf" "$@" diff --git a/docker/runtime/test/non-root-config-test.sh b/docker/runtime/test/non-root-config-test.sh index 0005a8630cb2c0..78cd2de16fe5c1 100755 --- a/docker/runtime/test/non-root-config-test.sh +++ b/docker/runtime/test/non-root-config-test.sh @@ -82,3 +82,40 @@ for variant in fe be be_disaggregated; do done echo 'Non-root Kerberos configuration tests passed' + +( + DORIS_HOME="${TEST_DIR}/ms" + CONFIGMAP_PATH="${TEST_DIR}/ms-configmap" + FDB_ENDPOINT='test:test@fdb:4500' + mkdir -p "${DORIS_HOME}/ms/conf" "${CONFIGMAP_PATH}/..data" + printf '# original config\n' > "${DORIS_HOME}/ms/conf/doris_cloud.conf" + printf '# projected config\nfdb_cluster=old:old@old:4500\n' > "${CONFIGMAP_PATH}/..data/doris_cloud.conf" + chmod 444 "${CONFIGMAP_PATH}/..data/doris_cloud.conf" + ln -s '..data/doris_cloud.conf' "${CONFIGMAP_PATH}/doris_cloud.conf" + printf '\n' > "${CONFIGMAP_PATH}/core-site.xml" + # shellcheck disable=SC1090 + source <(sed -n '/^update_conf_from_configmap()/,/^}/p' \ + "${RUNTIME_DIR}/ms/resource/ms_disaggregated_entrypoint.sh") + update_conf_from_configmap + grep -q '^# original config$' "${DORIS_HOME}/ms/conf/doris_cloud.conf.bak" + update_conf_from_configmap + test ! -L "${DORIS_HOME}/ms/conf/doris_cloud.conf" + test -L "${DORIS_HOME}/ms/conf/core-site.xml" + grep -qx "fdb_cluster=${FDB_ENDPOINT}" "${DORIS_HOME}/ms/conf/doris_cloud.conf" + test "$(grep -c '^fdb_cluster=' "${DORIS_HOME}/ms/conf/doris_cloud.conf")" -eq 1 + grep -qx 'fdb_cluster=old:old@old:4500' "${CONFIGMAP_PATH}/doris_cloud.conf" + echo 'test_setting = true' >> "${DORIS_HOME}/ms/conf/doris_cloud.conf" + + # Without a ConfigMap, repeated starts replace the endpoint in the image config. + CONFIGMAP_PATH="${TEST_DIR}/no-configmap" + FDB_ENDPOINT='new:new@new-fdb:4500' + update_conf_from_configmap + update_conf_from_configmap + grep -qx "fdb_cluster=${FDB_ENDPOINT}" "${DORIS_HOME}/ms/conf/doris_cloud.conf" + test "$(grep -c '^fdb_cluster=' "${DORIS_HOME}/ms/conf/doris_cloud.conf")" -eq 1 + unset FDB_ENDPOINT + update_conf_from_configmap + grep -qx 'fdb_cluster=new:new@new-fdb:4500' "${DORIS_HOME}/ms/conf/doris_cloud.conf" +) + +echo 'Non-root MS configuration tests passed' From 77d915c04af9c285510fd8029f127d6410048495 Mon Sep 17 00:00:00 2001 From: morningman Date: Fri, 4 Dec 2026 22:20:41 +0800 Subject: [PATCH 3/3] [fix](build) Preserve non-root runtime build and startup settings ### Background The standalone runtime build uses verified Doris release archives for FE, BE, and Meta Service on Ubuntu and UBI 9. The entrypoints install projected configuration before they start Doris. ### What problem does this PR solve? Issue Number: None Related PR: #70821 (non-root runtime update), #70770 (shared runtime builder), #39093 (disaggregated entrypoint) PR Type: Bugfix Problem Summary: The shared builder forwards invalid runtime IDs before downloading the archive or starting the base build. Its previous default mirror returned HTTP 403 when requesting the 4.1.5 checksums. A projected FE config also discards the FQDN setting that disaggregated startup applies before installing the file. Validate the IDs early, use the Apache download mirror, and apply cloud settings to the installed config. ### Details - **Change map:** 200 production, 81 test, and 24 documentation lines changed. No generated files. Build changes validate IDs and select the download mirror. Entrypoint changes install the projected config before applying startup settings. - **Frequency:** Reproduced when building with UID 0 or starting disaggregated FE with a projected fe.conf that omits enable_fqdn_mode. The legacy mirror returned 403 in the verification environment. - **Root cause:** The builder forwards IDs without checking them, and the FE entrypoint applies FQDN settings to the image config before replacing it with the projected config. - **Why existing tests missed it:** Build tests checked valid identity forwarding and mock checksums. The entrypoint test exercised the copy helper outside the disaggregated FE startup sequence. Kernel regression tests start packaged services and do not exercise these runtime build scripts. - **Fix:** Validate decimal IDs before fetching artifacts and before creating Docker users. Point the builder at the current Apache download mirror. Install writable primary configs before applying cloud settings, preserve explicit FQDN mode, and replace generated cloud assignments on restart. - **Other paths and branches:** Both distro launchers use the shared builder. Integrated FE and BE share the projected file handling, and disaggregated BE reapplies its cloud mode. Meta Service retains its existing FDB handling. The shared builder is outside branch-4.0 and branch-4.1 at the inspected refs. Their FE entrypoints retain the old ordering. This change targets master. - **Behavior change:** Invalid build-time IDs fail earlier, and disaggregated FE defaults to FQDN mode when its effective config omits the setting. ### Testing - Confirmed red and green results for invalid IDs, the download URL, and disaggregated FE with a read-only projected config. - Passed the runtime build unit tests, targeted ShellCheck, and Bash syntax checks. - Built 24 Docker fixture images for Ubuntu and UBI 9 on amd64 and arm64. Checked default and custom IDs for FE, BE, and MS, then ran the non-root configuration tests on both distributions and architectures. - Retrieved the official 4.1.5 checksums for the comparison inputs and verified the current operator tool source pin. ### Release note Validate non-root runtime IDs before image builds, use the current Apache release download mirror, and preserve the FQDN default and cloud configuration across projected-config startup and restart. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes. The runtime README documents the IDs, startup behavior, and matching standalone Operator CLI. - Pre-submission status: Partially verified: full Doris binary image builds and Kubernetes upgrade tests are tracked in the release verification stage. ### AI Disclosure - Tool: Codex (GPT-6). - Generated: Implementation, tests, and draft. - Human review: Pending maintainer review. --- docker/runtime/README.md | 24 ++++++-- docker/runtime/be/Dockerfile | 10 +++- .../resource/be_disaggregated_entrypoint.sh | 53 ++++++++--------- docker/runtime/be/resource/be_entrypoint.sh | 28 +++++---- docker/runtime/build-runtime.sh | 14 ++++- docker/runtime/fe/Dockerfile | 10 +++- .../resource/fe_disaggregated_entrypoint.sh | 48 ++++++++-------- docker/runtime/fe/resource/fe_entrypoint.sh | 27 ++++----- docker/runtime/ms/Dockerfile | 10 +++- docker/runtime/test/non-root-config-test.sh | 57 +++++++++++++++++-- docker/runtime/tests/test_docker_build.py | 24 ++++++++ 11 files changed, 205 insertions(+), 100 deletions(-) diff --git a/docker/runtime/README.md b/docker/runtime/README.md index 0ae31834be41df..96dfc3d162391e 100644 --- a/docker/runtime/README.md +++ b/docker/runtime/README.md @@ -141,15 +141,18 @@ Do not use `--pull` on a component build that consumes a locally built base. - The runtime does not contain gdb, perf, BCC, iperf3, patchelf, vim, development headers or Python 2. Use a separate diagnostic container when needed. - FE images omit Arthas and its bundled dependencies. -- Both operator tools remain at `/opt/apache-doris/`. They are compiled from - the pinned doris-operator source with the updated Go toolchain, x/net and edwards25519; - Operator debug mode and compute-group discovery retain their commands. +- Both operator tools remain at `/opt/apache-doris/`. The runtime base builds + them from the pinned doris-operator source. For `dorisctl preflight`, use the + standalone CLI from the Operator release that matches the target CRDs and + controller. ## Running FE, BE and Meta Service without root The standalone FE, BE and MS images run as `doris` (`10001:10001`) by default. The MS image also runs Recycler under this identity. Build arguments -`DORIS_UID` and `DORIS_GID` customize these IDs. Image-owned configuration, +`DORIS_UID` and `DORIS_GID` accept unused decimal IDs in the base image +from 1 through 4294967294. The build scripts validate them before downloading +the archive. An omitted argument uses 10001. Image-owned configuration, logs, metadata and storage directories are writable by this user. The SQL administrator account is independent of the operating-system user. The image provides `/etc/krb5.conf` as a link into the writable Doris configuration @@ -183,8 +186,17 @@ Operator. For a `DorisCluster`, set `feSpec.securityContext` and `beSpec.securityContext`, and the corresponding `containerSecurityContext` fields. For a `DorisDisaggregatedCluster`, configure `metaService`, `feSpec` and every `computeGroups` entry. Set `skipDefaultSystemInit: true` and -`enableWorkloadGroup: false` on each BE/compute group. The Operator switch -controls cgroup setup; it does not disable query admission or memory controls. +`enableWorkloadGroup: false` on each BE/compute group when using Operator +26.0.1. With an Operator release that supports `systemInitMode`, prepare +the nodes and choose `NodePrepared` to retain the BE startup checks. The +Workload Group switch controls OS-level CPU setup. Query admission and +memory controls remain available. + +The disaggregated FE and BE entrypoints copy their projected primary +configuration before applying cloud settings. FE preserves an explicitly +configured FQDN mode and defaults to enabling it when the projected file +omits it. On restart, the entrypoints replace their cloud assignments in +the writable working copy. For MS, `doris_cloud.conf` from a ConfigMap is copied into a writable file before applying `FDB_ENDPOINT`. Without that environment variable, the diff --git a/docker/runtime/be/Dockerfile b/docker/runtime/be/Dockerfile index 138258946d50e7..36faa059b3c1e7 100644 --- a/docker/runtime/be/Dockerfile +++ b/docker/runtime/be/Dockerfile @@ -36,7 +36,15 @@ ARG DORIS_VERSION="x.x.x" ARG DORIS_UID=10001 ARG DORIS_GID=10001 -RUN groupadd --gid "${DORIS_GID}" doris && \ +RUN for id in "${DORIS_UID}" "${DORIS_GID}"; do \ + case "${id}" in ""|0*|*[!0-9]*) \ + echo "DORIS_UID and DORIS_GID must be positive decimal IDs" >&2; exit 1 ;; \ + esac; \ + if [ "${#id}" -gt 10 ] || [ "${id}" -gt 4294967294 ]; then \ + echo "DORIS_UID and DORIS_GID must not exceed 4294967294" >&2; exit 1; \ + fi; \ + done && \ + groupadd --gid "${DORIS_GID}" doris && \ useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris ENV HOME=/home/doris diff --git a/docker/runtime/be/resource/be_disaggregated_entrypoint.sh b/docker/runtime/be/resource/be_disaggregated_entrypoint.sh index 58fe7afa00c789..cf8bd0c9a38811 100755 --- a/docker/runtime/be/resource/be_disaggregated_entrypoint.sh +++ b/docker/runtime/be/resource/be_disaggregated_entrypoint.sh @@ -94,39 +94,32 @@ function add_cpu_limit_config() fi } -# update config add `deploy_mode`. +# Install the projected config before setting the cloud deployment mode. update_conf_from_configmap() { - echo "" >> $DORIS_HOME/conf/be.conf - echo "########## doris-operator automatically adds ##########" >> $DORIS_HOME/conf/be.conf - echo "deploy_mode = cloud" >> $DORIS_HOME/conf/be.conf - if [[ "x$CONFIGMAP_MOUNT_PATH" == "x" ]] ; then - log_stderr '[info] Empty $CONFIGMAP_MOUNT_PATH env var, skip it!' - return 0 + if [[ -d "${CONFIGMAP_MOUNT_PATH:-}" ]]; then + local source target file + for source in "${CONFIGMAP_MOUNT_PATH}"/*; do + [[ -e "${source}" ]] || continue + file=${source##*/} + target="${DORIS_HOME}/conf/${file}" + if [[ -e "${target}" || -L "${target}" ]]; then + mv -fT -- "${target}" "${target}.bak" || return 1 + fi + if [[ "${file}" == be.conf ]]; then + cp -- "${source}" "${target}" && chmod u+w "${target}" || return 1 + else + ln -sfT -- "${source}" "${target}" || return 1 + fi + done fi - if ! test -d $CONFIGMAP_MOUNT_PATH ; then - log_stderr "[info] $CONFIGMAP_MOUNT_PATH not exist or not a directory, ignore ..." - return 0 + + local config="${DORIS_HOME}/conf/be.conf" + sed -i -E '/^[[:space:]]*deploy_mode[[:space:]]*=/d; /^########## doris-operator automatically adds ##########$/d' "${config}" || return 1 + if [[ -n "$(tail -c 1 -- "${config}")" ]]; then + printf '\n' >> "${config}" fi - local tgtconfdir=$DORIS_HOME/conf - for conffile in `ls $CONFIGMAP_MOUNT_PATH` - do - log_stderr "[info] Process conf file $conffile ..." - local tgt=$tgtconfdir/$conffile - if test -e $tgt ; then - # make a backup - mv -f $tgt ${tgt}.bak - fi - if [[ "$conffile" == "be.conf" ]]; then - cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" - chmod u+w "$tgt" - echo "" >> $DORIS_HOME/conf/$conffile - echo "########## doris-operator automatically adds ##########" >> $DORIS_HOME/conf/$conffile - echo "deploy_mode = cloud" >> $DORIS_HOME/conf/$conffile - continue - fi - ln -sfT $CONFIGMAP_MOUNT_PATH/$conffile $tgt - done + printf '########## doris-operator automatically adds ##########\ndeploy_mode = cloud\n' >> "${config}" } # resolve password for root @@ -635,7 +628,7 @@ else log_stderr "[info] the host machine not support avx2 instruction set." fi -update_conf_from_configmap +update_conf_from_configmap || exit 1 add_workloadgroup_config add_cpu_limit_config mount_kerberos_config diff --git a/docker/runtime/be/resource/be_entrypoint.sh b/docker/runtime/be/resource/be_entrypoint.sh index 07cf8e672ab312..219b65f7b11388 100755 --- a/docker/runtime/be/resource/be_entrypoint.sh +++ b/docker/runtime/be/resource/be_entrypoint.sh @@ -86,25 +86,23 @@ update_conf_from_configmap() log_stderr '[info] Empty $CONFIGMAP_MOUNT_PATH env var, skip it!' return 0 fi - if ! test -d $CONFIGMAP_MOUNT_PATH ; then + if [[ ! -d "${CONFIGMAP_MOUNT_PATH}" ]]; then log_stderr "[info] $CONFIGMAP_MOUNT_PATH not exist or not a directory, ignore ..." return 0 fi - local tgtconfdir=$DORIS_HOME/conf - for conffile in `ls $CONFIGMAP_MOUNT_PATH` - do - log_stderr "[info] Process conf file $conffile ..." - local tgt=$tgtconfdir/$conffile - if test -e $tgt ; then - # make a backup - mv -f $tgt ${tgt}.bak + local source target file + for source in "${CONFIGMAP_MOUNT_PATH}"/*; do + [[ -e "${source}" ]] || continue + file=${source##*/} + target="${DORIS_HOME}/conf/${file}" + if [[ -e "${target}" || -L "${target}" ]]; then + mv -fT -- "${target}" "${target}.bak" || return 1 fi - if [[ "$conffile" == "be.conf" ]]; then - cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" - chmod u+w "$tgt" - continue + if [[ "${file}" == be.conf ]]; then + cp -- "${source}" "${target}" && chmod u+w "${target}" || return 1 + else + ln -sfT -- "${source}" "${target}" || return 1 fi - ln -sfT $CONFIGMAP_MOUNT_PATH/$conffile $tgt done } @@ -522,7 +520,7 @@ else log_stderr "[info] the host machine not support avx2 instruction set." fi -update_conf_from_configmap +update_conf_from_configmap || exit 1 add_workloadgroup_config add_cpu_limit_config mount_kerberos_config diff --git a/docker/runtime/build-runtime.sh b/docker/runtime/build-runtime.sh index 4430c87937a561..6f5f4f01bcaec9 100644 --- a/docker/runtime/build-runtime.sh +++ b/docker/runtime/build-runtime.sh @@ -48,6 +48,16 @@ if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-._][a-zA-Z0-9._-]+)?$ ]]; then exit 1 fi +DORIS_UID=${DORIS_UID-10001} +DORIS_GID=${DORIS_GID-10001} +for arg in DORIS_UID DORIS_GID; do + id=${!arg} + if [[ ! "${id}" =~ ^[1-9][0-9]{0,9}$ ]] || (( 10#${id} > 4294967294 )); then + echo "Invalid ${arg}: expected a decimal ID between 1 and 4294967294" >&2 + exit 1 + fi +done + runtime_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) work_dir=${DORIS_IMAGE_WORK_DIR:-"${runtime_dir}/../../output/runtime-images/${runtime_variant}"} mkdir -p "${work_dir}" @@ -75,7 +85,7 @@ fi base_image=${DORIS_BASE_IMAGE:-"apache/doris:base-8.0-${runtime_variant}-jdk${java_version}"} package_name="apache-doris-${version}-bin-${url_arch}" archive_name="${package_name}.tar.gz" -download_base=${DORIS_DOWNLOAD_BASE_URL:-https://apache-doris-releases.oss-accelerate.aliyuncs.com} +download_base=${DORIS_DOWNLOAD_BASE_URL:-https://apache-doris-downloads.oss-accelerate.aliyuncs.com} expected_sha512=${DORIS_ARCHIVE_SHA512:-} # Read only the checksum, not paths or commands from the checksum document. @@ -138,7 +148,7 @@ for role in fe be ms; do image="${DORIS_IMAGE_PREFIX:-doris}.${role}:${version}${DORIS_IMAGE_TAG_SUFFIX-${runtime_tag_suffix}}" docker build --no-cache --platform "linux/${arch}" \ --build-arg "BASE_IMAGE=${base_image}" --build-arg "JAVA_VERSION=${java_version}" \ - --build-arg "DORIS_UID=${DORIS_UID:-10001}" --build-arg "DORIS_GID=${DORIS_GID:-10001}" \ + --build-arg "DORIS_UID=${DORIS_UID}" --build-arg "DORIS_GID=${DORIS_GID}" \ --build-arg "DORIS_VERSION=${version}" -t "${image}" "${context}" docker image inspect "${image}" > "${work_dir}/${role}-${version}-${arch}.image.json" done diff --git a/docker/runtime/fe/Dockerfile b/docker/runtime/fe/Dockerfile index 72130380a4301d..b3cfa040468435 100644 --- a/docker/runtime/fe/Dockerfile +++ b/docker/runtime/fe/Dockerfile @@ -43,7 +43,15 @@ FROM ${BASE_IMAGE} AS runtime ARG DORIS_UID=10001 ARG DORIS_GID=10001 -RUN groupadd --gid "${DORIS_GID}" doris && \ +RUN for id in "${DORIS_UID}" "${DORIS_GID}"; do \ + case "${id}" in ""|0*|*[!0-9]*) \ + echo "DORIS_UID and DORIS_GID must be positive decimal IDs" >&2; exit 1 ;; \ + esac; \ + if [ "${#id}" -gt 10 ] || [ "${id}" -gt 4294967294 ]; then \ + echo "DORIS_UID and DORIS_GID must not exceed 4294967294" >&2; exit 1; \ + fi; \ + done && \ + groupadd --gid "${DORIS_GID}" doris && \ useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris ENV HOME=/home/doris diff --git a/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh b/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh index a23a307baaf030..e332450e68a153 100755 --- a/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh +++ b/docker/runtime/fe/resource/fe_disaggregated_entrypoint.sh @@ -414,34 +414,32 @@ function check_and_modify_fqdn_config() function add_cluster_info_to_conf() { - echo "" >> ${DORIS_HOME}/conf/fe.conf - echo "########## doris-operator automatically adds ##########" >> ${DORIS_HOME}/conf/fe.conf - echo "meta_service_endpoint=$MS_ENDPOINT" >> ${DORIS_HOME}/conf/fe.conf - echo "cluster_id=$CLUSTER_ID" >> ${DORIS_HOME}/conf/fe.conf - echo "deploy_mode=cloud" >> ${DORIS_HOME}/conf/fe.conf + local config="${DORIS_HOME}/conf/fe.conf" + # Apply the cloud assignments to the effective file, including on restart. + sed -i -E '/^[[:space:]]*(meta_service_endpoint|cluster_id|deploy_mode)[[:space:]]*=/d; /^########## doris-operator automatically adds ##########$/d' "${config}" || return 1 + if [[ -n "$(tail -c 1 -- "${config}")" ]]; then + printf '\n' >> "${config}" + fi + printf '########## doris-operator automatically adds ##########\nmeta_service_endpoint=%s\ncluster_id=%s\ndeploy_mode=cloud\n' \ + "${MS_ENDPOINT:-}" "${CLUSTER_ID}" >> "${config}" } function link_config_files() { - if [[ -d $CONFIGMAP_MOUNT_PATH ]]; then - #backup files want to replace - for file in `ls $CONFIGMAP_MOUNT_PATH`; - do - if [[ -f $DORIS_HOME/conf/$file ]]; then - mv $DORIS_HOME/conf/$file $DORIS_HOME/conf/$file.bak + if [[ -d "${CONFIGMAP_MOUNT_PATH:-}" ]]; then + local source target file + for source in "${CONFIGMAP_MOUNT_PATH}"/*; do + [[ -e "${source}" ]] || continue + file=${source##*/} + target="${DORIS_HOME}/conf/${file}" + if [[ -e "${target}" || -L "${target}" ]]; then + mv -fT -- "${target}" "${target}.bak" || return 1 fi - done - - for file in `ls $CONFIGMAP_MOUNT_PATH`; - do - if [[ "$file" == "fe.conf" ]]; then - cp "$CONFIGMAP_MOUNT_PATH/$file" "$DORIS_HOME/conf/$file" - chmod u+w "$DORIS_HOME/conf/$file" - add_cluster_info_to_conf - continue + if [[ "${file}" == fe.conf ]]; then + cp -- "${source}" "${target}" && chmod u+w "${target}" || return 1 + else + ln -sfT -- "${source}" "${target}" || return 1 fi - - ln -sfT $CONFIGMAP_MOUNT_PATH/$file $DORIS_HOME/conf/$file done fi } @@ -539,9 +537,9 @@ if [[ "x$fe_addrs" == "x" ]]; then exit fi -add_cluster_info_to_conf -check_and_modify_fqdn_config -link_config_files +link_config_files || exit 1 +add_cluster_info_to_conf || exit 1 +check_and_modify_fqdn_config || exit 1 # resolve password for root to manage nodes in doris. resolve_password_from_secret #parse tls connection config diff --git a/docker/runtime/fe/resource/fe_entrypoint.sh b/docker/runtime/fe/resource/fe_entrypoint.sh index dd51e964c5c034..23e0ca37b1bea2 100755 --- a/docker/runtime/fe/resource/fe_entrypoint.sh +++ b/docker/runtime/fe/resource/fe_entrypoint.sh @@ -419,26 +419,23 @@ update_conf_from_configmap() add_fqdn_config return 0 fi - if ! test -d $CONFIGMAP_MOUNT_PATH ; then + if [[ ! -d "${CONFIGMAP_MOUNT_PATH}" ]]; then log_stderr "[info] $CONFIGMAP_MOUNT_PATH not exist or not a directory, ignore ..." add_fqdn_config return 0 fi - local tgtconfdir=$DORIS_HOME/conf - for conffile in `ls $CONFIGMAP_MOUNT_PATH` - do - log_stderr "[info] Process conf file $conffile ..." - local tgt=$tgtconfdir/$conffile - if test -e $tgt ; then - # make a backup - mv -f $tgt ${tgt}.bak + local source target file + for source in "${CONFIGMAP_MOUNT_PATH}"/*; do + [[ -e "${source}" ]] || continue + file=${source##*/} + target="${DORIS_HOME}/conf/${file}" + if [[ -e "${target}" || -L "${target}" ]]; then + mv -fT -- "${target}" "${target}.bak" || return 1 fi - if [[ "$conffile" == "fe.conf" ]]; then - # Startup appends configuration; projected ConfigMap files are read-only. - cp "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" - chmod u+w "$tgt" + if [[ "${file}" == fe.conf ]]; then + cp -- "${source}" "${target}" && chmod u+w "${target}" || return 1 else - ln -sfT "$CONFIGMAP_MOUNT_PATH/$conffile" "$tgt" + ln -sfT -- "${source}" "${target}" || return 1 fi done add_fqdn_config @@ -620,7 +617,7 @@ if [[ "x$fe_addrs" == "x" ]]; then fi #first upate config -update_conf_from_configmap +update_conf_from_configmap || exit 1 collect_env_info wait_for_fqdn_ready || exit 1 mount_kerberos_config diff --git a/docker/runtime/ms/Dockerfile b/docker/runtime/ms/Dockerfile index 148f7bd6162d5a..d7103c109dc347 100644 --- a/docker/runtime/ms/Dockerfile +++ b/docker/runtime/ms/Dockerfile @@ -36,7 +36,15 @@ ARG DORIS_VERSION="x.x.x" ARG DORIS_UID=10001 ARG DORIS_GID=10001 -RUN groupadd --gid "${DORIS_GID}" doris && \ +RUN for id in "${DORIS_UID}" "${DORIS_GID}"; do \ + case "${id}" in ""|0*|*[!0-9]*) \ + echo "DORIS_UID and DORIS_GID must be positive decimal IDs" >&2; exit 1 ;; \ + esac; \ + if [ "${#id}" -gt 10 ] || [ "${id}" -gt 4294967294 ]; then \ + echo "DORIS_UID and DORIS_GID must not exceed 4294967294" >&2; exit 1; \ + fi; \ + done && \ + groupadd --gid "${DORIS_GID}" doris && \ useradd --uid "${DORIS_UID}" --gid "${DORIS_GID}" --create-home --shell /bin/bash doris ENV HOME=/home/doris diff --git a/docker/runtime/test/non-root-config-test.sh b/docker/runtime/test/non-root-config-test.sh index 78cd2de16fe5c1..dd27f241152998 100755 --- a/docker/runtime/test/non-root-config-test.sh +++ b/docker/runtime/test/non-root-config-test.sh @@ -30,8 +30,8 @@ add_cluster_info_to_conf() { echo 'deploy_mode = cloud' >> "${DORIS_HOME}/conf/f for variant in fe be fe_disaggregated be_disaggregated; do ( component=${variant%%_*} - DORIS_HOME="${TEST_DIR}/${variant}" - CONFIGMAP_MOUNT_PATH="${TEST_DIR}/${variant}-configmap" + DORIS_HOME="${TEST_DIR}/${variant} home" + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/${variant} configmap" mkdir -p "${DORIS_HOME}/conf" "${CONFIGMAP_MOUNT_PATH}/..data" printf '# projected config\n' > "${CONFIGMAP_MOUNT_PATH}/..data/${component}.conf" chmod 444 "${CONFIGMAP_MOUNT_PATH}/..data/${component}.conf" @@ -54,15 +54,64 @@ for variant in fe be fe_disaggregated be_disaggregated; do grep -q '^# original config$' "${DORIS_HOME}/conf/${component}.conf.bak" echo 'test_setting = true' >> "${DORIS_HOME}/conf/${component}.conf" test "$(wc -l < "${CONFIGMAP_MOUNT_PATH}/${component}.conf")" -eq 1 + if [[ "${variant}" == be_disaggregated ]]; then + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/unmounted" + update_conf_from_configmap + update_conf_from_configmap + test "$(grep -c '^deploy_mode[[:space:]]*=' "${DORIS_HOME}/conf/be.conf")" -eq 1 + fi ) done +# Exercise the actual call order, not just the copy helper. A projected file +# replaces the image's fe.conf, so defaults must be applied after the copy. +( + DORIS_HOME="${TEST_DIR}/cloud-fe-start" + FE_CONFFILE="${DORIS_HOME}/conf/fe.conf" + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/cloud-fe-project" + export MS_ENDPOINT=ms:5000 + export CLUSTER_ID=42 + mkdir -p "${DORIS_HOME}/conf" "${CONFIGMAP_MOUNT_PATH}" + printf 'http_port = 8030\n' > "${FE_CONFFILE}" + printf 'http_port = 8040\n' > "${CONFIGMAP_MOUNT_PATH}/fe.conf" + chmod 444 "${CONFIGMAP_MOUNT_PATH}/fe.conf" + entrypoint="${RUNTIME_DIR}/fe/resource/fe_disaggregated_entrypoint.sh" + # shellcheck disable=SC1090 + source <(sed -n '/^parse_confval_from_fe_conf()/,/^}/p; /^function check_and_modify_fqdn_config()/,/^}/p; /^function add_cluster_info_to_conf()/,/^}/p; /^function link_config_files()/,/^}/p' "${entrypoint}") + set -- fe-service + # Match the literal positional argument in the entrypoint source. + # shellcheck disable=SC1090,SC2016 + source <(sed -n '/^fe_addrs=\$1$/,/^# resolve password/p' "${entrypoint}") + if ! grep -qx 'enable_fqdn_mode = true' "${FE_CONFFILE}"; then + echo 'Disaggregated FE lost the default FQDN mode after installing the projected config' >&2 + exit 1 + fi + grep -qx 'http_port = 8040' "${FE_CONFFILE}" + grep -qx 'meta_service_endpoint=ms:5000' "${FE_CONFFILE}" + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/unmounted" + # Match the literal positional argument in the entrypoint source. + # shellcheck disable=SC1090,SC2016 + source <(sed -n '/^fe_addrs=\$1$/,/^# resolve password/p' "${entrypoint}") + for property in enable_fqdn_mode meta_service_endpoint cluster_id deploy_mode; do + test "$(grep -c "^${property}[[:space:]]*=" "${FE_CONFFILE}")" -eq 1 + done + CONFIGMAP_MOUNT_PATH="${TEST_DIR}/cloud-fe-project" + chmod u+w "${CONFIGMAP_MOUNT_PATH}/fe.conf" + printf 'enable_fqdn_mode = false\n' >> "${CONFIGMAP_MOUNT_PATH}/fe.conf" + chmod 444 "${CONFIGMAP_MOUNT_PATH}/fe.conf" + # Match the literal positional argument in the entrypoint source. + # shellcheck disable=SC1090,SC2016 + source <(sed -n '/^fe_addrs=\$1$/,/^# resolve password/p' "${entrypoint}") + grep -qx 'enable_fqdn_mode = false' "${FE_CONFFILE}" + test "$(grep -c '^enable_fqdn_mode[[:space:]]*=' "${FE_CONFFILE}")" -eq 1 +) + echo 'Non-root projected configuration tests passed' for variant in fe be be_disaggregated; do ( component=${variant%%_*} - DORIS_HOME="${TEST_DIR}/${variant}" + DORIS_HOME="${TEST_DIR}/${variant} home" KRB5_MOUNT_PATH="${TEST_DIR}/${variant}-kerberos" KRB5_CONFIG="${TEST_DIR}/${variant}-etc/krb5.conf" export KEYTAB_MOUNT_PATH= @@ -76,7 +125,7 @@ for variant in fe be be_disaggregated; do "${RUNTIME_DIR}/${component}/resource/${variant}_entrypoint.sh") mount_kerberos_config mount_kerberos_config - cmp "${KRB5_MOUNT_PATH}/krb5.conf" "${KRB5_CONFIG}" + test "$(readlink -f "${KRB5_CONFIG}")" = "$(readlink -f "${KRB5_MOUNT_PATH}/krb5.conf")" test -L "${DORIS_HOME}/conf/krb5.conf" ) done diff --git a/docker/runtime/tests/test_docker_build.py b/docker/runtime/tests/test_docker_build.py index bdd206faf474d3..282191e6b2a3ae 100644 --- a/docker/runtime/tests/test_docker_build.py +++ b/docker/runtime/tests/test_docker_build.py @@ -54,6 +54,7 @@ import sys args = sys.argv[1:] +Path(os.environ["CHECKSUM_URL"]).write_text(args[args.index("-o") - 1]) Path(args[args.index("-o") + 1]).write_text(os.environ["CHECKSUM_DOCUMENT"]) """ @@ -96,9 +97,11 @@ def archive(self, version="4.1.5", arch="arm64", include_ms=True): def build(self, archive, digest, version="4.1.5", script="docker-build.sh", **overrides): env = dict(os.environ) env.pop("DORIS_IMAGE_TAG_SUFFIX", None) + env.pop("DORIS_DOWNLOAD_BASE_URL", None) env.update( PATH=f"{self.bin}:{env['PATH']}", DOCKER_CALLS=str(self.calls), + CHECKSUM_URL=str(self.work / "checksum-url"), DORIS_ARCHIVE=str(archive), DORIS_ARCHIVE_SHA512=digest, DORIS_ARCH="arm64", @@ -206,6 +209,16 @@ def test_checksum_documents_accept_gnu_and_bsd_formats(self): result = self.build(archive, "", CHECKSUM_DOCUMENT=document) self.assertEqual(result.returncode, 0, result.stderr) + def test_default_checksum_uses_the_apache_download_mirror(self): + archive, digest = self.archive() + result = self.build(archive, "", CHECKSUM_DOCUMENT=f"{digest} archive.tar.gz\n") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual( + (self.work / "checksum-url").read_text(), + "https://apache-doris-downloads.oss-accelerate.aliyuncs.com/" + "apache-doris-4.1.5-bin-arm64.tar.gz.sha512", + ) + def test_ambiguous_or_malformed_checksum_document_is_rejected(self): archive, digest = self.archive() for document in ["not a checksum", f"{digest}\n{digest}\n"]: @@ -214,6 +227,17 @@ def test_ambiguous_or_malformed_checksum_document_is_rejected(self): self.assertNotEqual(result.returncode, 0) self.assertFalse(self.calls.exists()) + def test_invalid_runtime_identity_is_rejected_before_artifact_work(self): + archive, digest = self.archive() + for key in ("DORIS_UID", "DORIS_GID"): + for value in ("0", "-1", "1x", "010001", "4294967295", ""): + with self.subTest(key=key, value=value): + self.calls.unlink(missing_ok=True) + result = self.build(archive, digest, **{key: value}) + self.assertNotEqual(result.returncode, 0) + self.assertIn(f"Invalid {key}", result.stderr) + self.assertFalse(self.calls.exists()) + def test_invalid_version_is_rejected_before_building(self): archive, digest = self.archive() result = self.build(archive, digest, version="../4.1.5")