Skip to content

Commit c522344

Browse files
committed
[OPENJDK-312] Don't chmod /etc/passwd
CRI-O on OCP >= 4.2 generates a passwd line at runtime for the running user's random UID, which removes the requirement for us to do the same. Fixes CVE-2021-20264. Use nss_wrapper to provide passwd metadata for the running UID, based on the template passwd line for the jboss user. Necessary for OCP 3.11. Signed-off-by: Jonathan Dowland <[email protected]>
1 parent e26463c commit c522344

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

modules/run/bash/artifacts/opt/jboss/container/java/run/run-java.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,10 @@ get_exec_args() {
217217
fi
218218
}
219219

220+
# Ensure that the running UID has the "jboss" passwd metadata
220221
# XXX: Maybe we should make this an entrypoint for the image?
221222
function configure_passwd() {
222-
sed "/^jboss/s/[^:]*/$(id -u)/3" /etc/passwd > /tmp/passwd
223-
cat /tmp/passwd > /etc/passwd
224-
rm /tmp/passwd
223+
sed "/^jboss/s/[^:]*/$(id -u)/3" /etc/passwd > "$HOME/passwd"
225224
}
226225

227226
# Start JVM

modules/run/bash/module.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,24 @@ envs:
4848
- name: JAVA_ARGS
4949
description: Arguments passed to the `java` application.
5050

51+
- name: LD_PRELOAD
52+
value: libnss_wrapper.so
53+
- name: NSS_WRAPPER_PASSWD
54+
value: /home/jboss/passwd
55+
- name: NSS_WRAPPER_GROUP
56+
value: /etc/group
57+
5158
execute:
5259
- script: configure.sh
5360
- script: backward_compatibility.sh
5461

5562
modules:
5663
install:
64+
- name: jboss.container.user
5765
- name: jboss.container.java.jvm.bash
5866
- name: jboss.container.util.logging.bash
5967
- name: jboss.container.openjdk.jdk
68+
69+
packages:
70+
install:
71+
- nss_wrapper

modules/user/configure.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ set -e
66
# This ID is registered static ID for the JBoss EAP product
77
# on RHEL which makes it safe to use.
88
groupadd -r jboss -g 185 && useradd -u 185 -r -g root -G jboss -m -d /home/jboss -s /sbin/nologin -c "JBoss user" jboss
9-
chmod ug+rwX /home/jboss
10-
chmod 664 /etc/passwd
9+
cp /etc/passwd /home/jboss/passwd
10+
chmod ug+rwX /home/jboss /home/jboss/passwd

0 commit comments

Comments
 (0)