From 5dfd5ff2b46aa684dd0e3ce0d6c4905cceed0510 Mon Sep 17 00:00:00 2001 From: aipcc-bot Date: Mon, 21 Sep 2026 15:49:06 +0000 Subject: [PATCH] fix(konflux): prevent static glibc NSS crashes Dynamically link the CLI and supervisor against their runtime glibc, and constrain the fully static sandbox to built-in NSS services before startup. RHAI-1927 Assisted-by: OpenAI Codex Signed-off-by: aipcc-bot --- deploy/docker/Dockerfile.konflux.cli | 21 ++++++++-------- deploy/docker/Dockerfile.konflux.sandbox | 5 +++- deploy/docker/Dockerfile.konflux.supervisor | 22 +++++++--------- deploy/konflux/cli/rpms.in.yaml | 7 +----- deploy/konflux/cli/rpms.lock.yaml | 28 --------------------- deploy/konflux/sandbox/nss-static.c | 25 ++++++++++++++++++ deploy/konflux/supervisor/rpms.in.yaml | 7 +----- deploy/konflux/supervisor/rpms.lock.yaml | 28 --------------------- 8 files changed, 50 insertions(+), 93 deletions(-) create mode 100644 deploy/konflux/sandbox/nss-static.c diff --git a/deploy/docker/Dockerfile.konflux.cli b/deploy/docker/Dockerfile.konflux.cli index ebc6b0951f..bc70f161dd 100644 --- a/deploy/docker/Dockerfile.konflux.cli +++ b/deploy/docker/Dockerfile.konflux.cli @@ -6,9 +6,8 @@ # CLI image for RHEL/Konflux (hermetic build). # # Multi-stage build that compiles the openshell CLI from source on UBI9 as a -# fully-static binary. It is built against glibc with -# `-C target-feature=+crt-static` using Red Hat's glibc-static package -# (CodeReady Builder), so the build has no dependency on musl. +# dynamically linked glibc binary, matching the runtime image's libc and NSS +# modules. # # Requires prefetched dependencies via Hermeto (cargo, rpm, generic). # See deploy/konflux/ for prefetch configs. @@ -18,7 +17,7 @@ ARG RUST_VERSION=1.95.0 # --------------------------------------------------------------------------- -# Build stage: compile CLI (fully-static glibc binary) +# Build stage: compile CLI (dynamically linked glibc binary) # --------------------------------------------------------------------------- FROM registry.access.redhat.com/ubi9/ubi:9.8@sha256:25a147defd01e19674714f55d17538c8dbe55d8c305fa157ecc3f9c8977b05b6 AS builder @@ -27,7 +26,6 @@ ARG TARGETARCH RUN dnf install -y --nodocs \ gcc gcc-c++ make cmake \ - glibc-static \ openssl-devel git-core xz \ && dnf clean all @@ -58,17 +56,18 @@ RUN sed -i 's|members = \["crates/\*"\]|members = ["crates/openshell-cli", "crat # pass the git tag with the leading "v" stripped. Empty otherwise. ARG OPENSHELL_VERSION="" -# `-C target-feature=+crt-static` links glibc statically, producing a -# fully-static (static-PIE) binary with no runtime libc dependency. RUN . /tmp/build-env && \ VER="${OPENSHELL_VERSION#v}" && \ if [ -n "$VER" ]; then export OPENSHELL_GIT_VERSION="$VER"; fi && \ - RUSTFLAGS="-C target-feature=+crt-static" \ cargo build --release \ --target "${RUST_TARGET}" \ --package openshell-cli && \ mkdir -p /build/output && \ - cp /build/target/${RUST_TARGET}/release/openshell /build/output/ + cp /build/target/${RUST_TARGET}/release/openshell /build/output/ && \ + readelf -l /build/output/openshell > /tmp/program-headers && \ + if ! grep -q 'Requesting program interpreter' /tmp/program-headers; then \ + echo "openshell is not dynamically linked" >&2; exit 1; \ + fi # --------------------------------------------------------------------------- # Runtime @@ -84,8 +83,8 @@ RUN update-crypto-policies --set DEFAULT:PQ COPY --from=builder --chmod=0555 /build/output/openshell /usr/local/bin/openshell LABEL com.redhat.component="odh-openshell-cli-container" \ - description="Statically linked (glibc) CLI for OpenShell sandboxed AI agent runtimes" \ - summary="Statically linked (glibc) CLI for OpenShell sandboxed AI agent runtimes" \ + description="OpenShell CLI for sandboxed AI agent runtimes" \ + summary="OpenShell CLI for sandboxed AI agent runtimes" \ name="rhoai/odh-openshell-cli-rhel9" \ maintainer="['managed-open-data-hub@redhat.com']" \ io.openshift.expose-services="" \ diff --git a/deploy/docker/Dockerfile.konflux.sandbox b/deploy/docker/Dockerfile.konflux.sandbox index 9e57029051..b75bf40f11 100644 --- a/deploy/docker/Dockerfile.konflux.sandbox +++ b/deploy/docker/Dockerfile.konflux.sandbox @@ -49,6 +49,7 @@ COPY Cargo.toml Cargo.lock ./ COPY .cargo/ .cargo/ COPY crates/ crates/ COPY proto/ proto/ +COPY deploy/konflux/sandbox/nss-static.c deploy/konflux/sandbox/nss-static.c # Version stamped into the binary via openshell-core::VERSION; tag builds # pass the git tag with the leading "v" stripped. Empty otherwise. @@ -67,7 +68,9 @@ ARG OPENSHELL_VERSION="" RUN . /tmp/build-env && \ VER="${OPENSHELL_VERSION#v}" && \ if [ -n "$VER" ]; then export OPENSHELL_GIT_VERSION="$VER"; fi && \ - RUSTFLAGS="-C target-feature=+crt-static" \ + gcc -std=c11 -Wall -Wextra -Werror -c \ + deploy/konflux/sandbox/nss-static.c -o /tmp/nss-static.o && \ + RUSTFLAGS="-C target-feature=+crt-static -C link-arg=/tmp/nss-static.o" \ cargo build --release \ --target "${RUST_TARGET}" \ --package openshell-sandbox \ diff --git a/deploy/docker/Dockerfile.konflux.supervisor b/deploy/docker/Dockerfile.konflux.supervisor index a653a4940c..1629b810e1 100644 --- a/deploy/docker/Dockerfile.konflux.supervisor +++ b/deploy/docker/Dockerfile.konflux.supervisor @@ -7,9 +7,7 @@ # # The supervisor runs in its own container, outside the agent workload. The # workload-side runtime ships separately in Dockerfile.konflux.sandbox. The -# binary is built against glibc with `-C target-feature=+crt-static` using Red -# Hat's glibc-static package (CodeReady Builder), so the build has no -# dependency on musl. +# binary is dynamically linked against the runtime image's glibc. # # Requires prefetched dependencies via Hermeto (cargo, rpm, generic). # See deploy/konflux/ for prefetch configs. @@ -19,7 +17,7 @@ ARG RUST_VERSION=1.95.0 # --------------------------------------------------------------------------- -# Build stage: compile supervisor (fully-static glibc binary) +# Build stage: compile supervisor (dynamically linked glibc binary) # --------------------------------------------------------------------------- FROM registry.access.redhat.com/ubi9/ubi:9.8@sha256:25a147defd01e19674714f55d17538c8dbe55d8c305fa157ecc3f9c8977b05b6 AS builder @@ -28,7 +26,6 @@ ARG TARGETARCH RUN dnf install -y --nodocs --setopt=install_weak_deps=0 \ gcc gcc-c++ make cmake \ - glibc-static \ openssl-devel git-core xz \ && dnf clean all @@ -54,9 +51,6 @@ COPY proto/ proto/ # pass the git tag with the leading "v" stripped. Empty otherwise. ARG OPENSHELL_VERSION="" -# `-C target-feature=+crt-static` links glibc statically, producing a -# fully-static (static-PIE) binary with no runtime libc dependency. -# # The alias re-adds `bundled-ca-roots`, which a bare `--no-default-features` # would drop, keeping the supervisor on the same trust roots as upstream. # @@ -67,7 +61,6 @@ ARG OPENSHELL_VERSION="" RUN . /tmp/build-env && \ VER="${OPENSHELL_VERSION#v}" && \ if [ -n "$VER" ]; then export OPENSHELL_GIT_VERSION="$VER"; fi && \ - RUSTFLAGS="-C target-feature=+crt-static" \ cargo build --release \ --target "${RUST_TARGET}" \ --package openshell-supervisor \ @@ -75,7 +68,11 @@ RUN . /tmp/build-env && \ --no-default-features \ --features defaults-without-telemetry && \ mkdir -p /build/output && \ - cp /build/target/${RUST_TARGET}/release/openshell-supervisor /build/output/ + cp /build/target/${RUST_TARGET}/release/openshell-supervisor /build/output/ && \ + readelf -l /build/output/openshell-supervisor > /tmp/program-headers && \ + if ! grep -q 'Requesting program interpreter' /tmp/program-headers; then \ + echo "openshell-supervisor is not dynamically linked" >&2; exit 1; \ + fi # --------------------------------------------------------------------------- # Runtime @@ -91,12 +88,11 @@ RUN microdnf install -y --nodocs --setopt=install_weak_deps=0 \ # Enable post-quantum cryptography support in the RHEL system policy. RUN update-crypto-policies --set DEFAULT:PQ -# Copy the fully-static binary produced by the builder stage. COPY --from=builder --chmod=0555 /build/output/openshell-supervisor /openshell-supervisor LABEL com.redhat.component="odh-openshell-supervisor-container" \ - description="Statically linked (glibc) sandbox supervisor for OpenShell, run outside the agent workload" \ - summary="Statically linked (glibc) sandbox supervisor for OpenShell, run outside the agent workload" \ + description="Sandbox supervisor for OpenShell, run outside the agent workload" \ + summary="Sandbox supervisor for OpenShell, run outside the agent workload" \ name="rhoai/odh-openshell-supervisor-rhel9" \ maintainer="['managed-open-data-hub@redhat.com']" \ io.openshift.expose-services="" \ diff --git a/deploy/konflux/cli/rpms.in.yaml b/deploy/konflux/cli/rpms.in.yaml index 90f76437d7..60d526144e 100644 --- a/deploy/konflux/cli/rpms.in.yaml +++ b/deploy/konflux/cli/rpms.in.yaml @@ -24,17 +24,12 @@ contentOrigin: baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/baseos/os/ - repoid: ubi-9-appstream-rpms baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/appstream/os/ - # glibc-static (for `-C target-feature=+crt-static`) ships in CodeReady - # Builder, whose content is public on the UBI CDN. - - repoid: ubi-9-codeready-builder-rpms - baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/codeready-builder/os/ packages: - # Build stage: static glibc + build tools + # Build stage: build tools - gcc - make - tar - xz - - glibc-static # Build stage: Rust compilation (rustup provides rust/cargo) - gcc-c++ - cmake diff --git a/deploy/konflux/cli/rpms.lock.yaml b/deploy/konflux/cli/rpms.lock.yaml index 2edbf6ce11..7c259bc9b4 100644 --- a/deploy/konflux/cli/rpms.lock.yaml +++ b/deploy/konflux/cli/rpms.lock.yaml @@ -1047,20 +1047,6 @@ arches: name: zlib evr: 1.2.11-40.el9 sourcerpm: zlib-1.2.11-40.el9.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/aarch64/codeready-builder/os/Packages/g/glibc-static-2.34-275.el9_8.aarch64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 1249076 - checksum: sha256:a683861245c3bbd125301070aca013ed0a7603f6bcf64d99914dcf9ae792b281 - name: glibc-static - evr: 2.34-275.el9_8 - sourcerpm: glibc-2.34-275.el9_8.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/aarch64/codeready-builder/os/Packages/l/libxcrypt-static-4.4.18-3.el9.aarch64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 111974 - checksum: sha256:8bb8a0eb808c389cfec8a0b29ef66a608cc04711b5d4a0ad515f3a32522ae6e0 - name: libxcrypt-static - evr: 4.4.18-3.el9 - sourcerpm: libxcrypt-4.4.18-3.el9.src.rpm source: [] module_metadata: [] - arch: x86_64 @@ -2101,19 +2087,5 @@ arches: name: zlib evr: 1.2.11-40.el9 sourcerpm: zlib-1.2.11-40.el9.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/codeready-builder/os/Packages/g/glibc-static-2.34-275.el9_8.x86_64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 1532701 - checksum: sha256:d35de990a70f4a636753a1e45e2e73b6dd66fc46985bbd6695aaac2c68f399a0 - name: glibc-static - evr: 2.34-275.el9_8 - sourcerpm: glibc-2.34-275.el9_8.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/codeready-builder/os/Packages/l/libxcrypt-static-4.4.18-3.el9.x86_64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 105711 - checksum: sha256:e2b914f5e136df3c90367dc222e9d893d0c34662f9f2d496b0cadd7d277c579a - name: libxcrypt-static - evr: 4.4.18-3.el9 - sourcerpm: libxcrypt-4.4.18-3.el9.src.rpm source: [] module_metadata: [] diff --git a/deploy/konflux/sandbox/nss-static.c b/deploy/konflux/sandbox/nss-static.c new file mode 100644 index 0000000000..7c12bc916c --- /dev/null +++ b/deploy/konflux/sandbox/nss-static.c @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +/* + * Static glibc binaries cannot safely load NSS modules from an arbitrary + * workload image. Configure every glibc NSS database before Rust startup so + * lookups use only services built into libc. + */ + +extern int __nss_configure_lookup(const char *database, const char *service_line); + +static void __attribute__((constructor)) configure_static_nss(void) +{ + static const char *const file_databases[] = { + "aliases", "ethers", "group", "gshadow", "initgroups", + "netgroup", "networks", "passwd", "protocols", "publickey", + "rpc", "services", "shadow", + }; + unsigned long i; + + for (i = 0; i < sizeof(file_databases) / sizeof(file_databases[0]); ++i) + (void)__nss_configure_lookup(file_databases[i], "files"); + + (void)__nss_configure_lookup("hosts", "files dns"); +} diff --git a/deploy/konflux/supervisor/rpms.in.yaml b/deploy/konflux/supervisor/rpms.in.yaml index 0728a19492..9bfdcdd0c6 100644 --- a/deploy/konflux/supervisor/rpms.in.yaml +++ b/deploy/konflux/supervisor/rpms.in.yaml @@ -21,17 +21,12 @@ contentOrigin: baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/baseos/os/ - repoid: ubi-9-appstream-rpms baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/appstream/os/ - # glibc-static (for `-C target-feature=+crt-static`) ships in CodeReady - # Builder, whose content is public on the UBI CDN. - - repoid: ubi-9-codeready-builder-rpms - baseurl: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/$basearch/codeready-builder/os/ packages: - # Build stage: static glibc + build tools + # Build stage: build tools - gcc - make - tar - xz - - glibc-static # Build stage: Rust compilation (rustup provides rust/cargo) - gcc-c++ - cmake diff --git a/deploy/konflux/supervisor/rpms.lock.yaml b/deploy/konflux/supervisor/rpms.lock.yaml index a436e9cf9e..0572ad9bb6 100644 --- a/deploy/konflux/supervisor/rpms.lock.yaml +++ b/deploy/konflux/supervisor/rpms.lock.yaml @@ -963,20 +963,6 @@ arches: name: zlib evr: 1.2.11-40.el9 sourcerpm: zlib-1.2.11-40.el9.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/aarch64/codeready-builder/os/Packages/g/glibc-static-2.34-275.el9_8.aarch64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 1249076 - checksum: sha256:a683861245c3bbd125301070aca013ed0a7603f6bcf64d99914dcf9ae792b281 - name: glibc-static - evr: 2.34-275.el9_8 - sourcerpm: glibc-2.34-275.el9_8.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/aarch64/codeready-builder/os/Packages/l/libxcrypt-static-4.4.18-3.el9.aarch64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 111974 - checksum: sha256:8bb8a0eb808c389cfec8a0b29ef66a608cc04711b5d4a0ad515f3a32522ae6e0 - name: libxcrypt-static - evr: 4.4.18-3.el9 - sourcerpm: libxcrypt-4.4.18-3.el9.src.rpm source: [] module_metadata: [] - arch: x86_64 @@ -1926,19 +1912,5 @@ arches: name: zlib evr: 1.2.11-40.el9 sourcerpm: zlib-1.2.11-40.el9.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/codeready-builder/os/Packages/g/glibc-static-2.34-275.el9_8.x86_64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 1532701 - checksum: sha256:d35de990a70f4a636753a1e45e2e73b6dd66fc46985bbd6695aaac2c68f399a0 - name: glibc-static - evr: 2.34-275.el9_8 - sourcerpm: glibc-2.34-275.el9_8.src.rpm - - url: https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/codeready-builder/os/Packages/l/libxcrypt-static-4.4.18-3.el9.x86_64.rpm - repoid: ubi-9-codeready-builder-rpms - size: 105711 - checksum: sha256:e2b914f5e136df3c90367dc222e9d893d0c34662f9f2d496b0cadd7d277c579a - name: libxcrypt-static - evr: 4.4.18-3.el9 - sourcerpm: libxcrypt-4.4.18-3.el9.src.rpm source: [] module_metadata: []