Skip to content

Commit 4d53792

Browse files
committed
Use build secret instead of COPY for RHSM credential script
Replace COPY of the RHSM credential script with RUN --mount=type=secret so that credentials are never committed to an image layer. Previously, the documented RHEL build flow would embed plaintext RHSM_USER and RHSM_PASSWORD in the image layer history, recoverable by anyone with pull access to the registry. The Containerfile now mounts the script as a build secret and guards execution with an existence check, so builds without RHSM (the default CentOS/CI path) continue to work unchanged. The Makefile conditionally passes --secret only when RHSM_SCRIPT is set. Jira: OSPRH-32781 Signed-off-by: Steve Baker <sbaker@redhat.com>
1 parent 134d282 commit 4d53792

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

bootc/Containerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ ARG NVMEOF_PACKAGES="\
114114

115115
ARG USER_PACKAGES=""
116116

117-
ARG RHSM_SCRIPT=empty.sh
118-
COPY $RHSM_SCRIPT /var/tmp/rhsm-script.sh
119-
RUN /var/tmp/rhsm-script.sh && \
117+
RUN --mount=type=secret,id=rhsm,dst=/var/tmp/rhsm-script.sh \
118+
if [ -f /var/tmp/rhsm-script.sh ]; then bash /var/tmp/rhsm-script.sh; fi && \
120119
dnf -y install \
121120
$BOOTSTRAP_PACKAGES \
122121
$CEPH_PACKAGES \

bootc/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ EDPM_QCOW2_IMAGE ?= ${EDPM_BOOTC_REPO}:${EDPM_BOOTC_TAG}-qcow2
88
BUILDER_IMAGE ?= quay.io/centos-bootc/bootc-image-builder:latest
99
HOST_PACKAGES ?= podman osbuild-selinux https://download.devel.redhat.com/rcm-guest/puddles/OpenStack/rhos-release/rhos-release-latest.noarch.rpm
1010
USER_PACKAGES ?=
11-
RHSM_SCRIPT ?= empty.sh
11+
RHSM_SCRIPT ?=
1212
FIPS ?= 1
13+
comma := ,
1314

1415
.ONESHELL:
1516

@@ -34,9 +35,9 @@ build: output/yum.repos.d
3435
sudo buildah inspect ${EDPM_BOOTC_IMAGE} > /dev/null && exit 0 || true
3536
sudo buildah bud \
3637
--build-arg EDPM_BASE_IMAGE=${EDPM_BASE_IMAGE} \
37-
--build-arg RHSM_SCRIPT=${RHSM_SCRIPT} \
3838
--build-arg FIPS=${FIPS} \
3939
--build-arg USER_PACKAGES=${USER_PACKAGES} \
40+
$(if ${RHSM_SCRIPT},--secret id=rhsm$(comma)src=${RHSM_SCRIPT}) \
4041
--volume /etc/pki/ca-trust:/etc/pki/ca-trust:ro,Z \
4142
--volume $(shell pwd)/output/yum.repos.d:/etc/yum.repos.d:rw,Z \
4243
-f ${EDPM_CONTAINERFILE} \

bootc/README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ packages, run the following commands::
8282
export RHEL_MAJOR=9
8383

8484
# make a custom copy of the subscription-manager script and edit it for
85-
# your registration details
85+
# your registration details. The script is mounted as a build secret and
86+
# will not be committed to any image layer.
8687
cp rhsm.sh rhsm-custom.sh
88+
# edit RHSM_USER and RHSM_PASSWORD in rhsm-custom.sh
8789
export RHSM_SCRIPT=rhsm-custom.sh
8890

8991
export EDPM_BOOTC_REPO=quay.io/<account>/edpm-bootc

0 commit comments

Comments
 (0)