Skip to content

Commit 8f60aa5

Browse files
committed
feat: arbitrary UID support, GID 0
1 parent cb69931 commit 8f60aa5

8 files changed

Lines changed: 47 additions & 47 deletions

File tree

Containerfile.alpine

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ COPY Containerfile.alpine /Containerfile
8181

8282
RUN /prep_release_container.sh
8383

84-
USER puppetdb:0
84+
# group 0 allows arbitrary UIDs, 64604 is set as default
85+
USER 64604:0
8586

8687
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
8788
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]

Containerfile.ubuntu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ COPY Containerfile.ubuntu /Containerfile
9090

9191
RUN /prep_release_container.sh
9292

93-
USER puppetdb:0
93+
# group 0 allows arbitrary UIDs, 64604 is set as default
94+
USER 64604:0
9495

9596
# k8s uses livenessProbe, startupProbe, readinessProbe and ignores HEALTHCHECK
9697
HEALTHCHECK --interval=20s --timeout=15s --retries=12 --start-period=3m CMD ["/healthcheck.sh"]

MIGRATION.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Migrations
22

3-
## v8.15.0
3+
## Coming from a fixed UID release
44

5-
UID is changed from 1001 on alpine and 999 on ubuntu to 64604.
6-
If you already deployed the containers with mounted volume, you NEED to change the ownershop of these volumes and the files underneath.
5+
The container runs with **group 0** and works under **any UID**. File access is granted exclusively through group 0, and the UID of files on mounted volumes does not matter. There is no `puppet` service account in the image anymore.
6+
7+
For existing volumes, run once:
78

89
```bash
9-
chown -R 64604:64604 [PATH TO THE VOLUME]
10+
chgrp -R 0 [PATH TO THE VOLUME]
11+
chmod -R g+rwX [PATH TO THE VOLUME]
1012
```
13+
14+
On Kubernetes/OpenShift using `fsGroup: 0` in the pod securityContext can be used to achieve the same.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [End of Life for OpenVox DB 7](#end-of-life-for-openvox-db-7)
1212
- [Migration](#migration)
1313
- [Version schema](#version-schema)
14+
- [Permissions](#permissions)
1415
- [Configuration](#configuration)
1516
- [Cert File Locations](#cert-file-locations)
1617
- [Initialization Scripts](#initialization-scripts)
@@ -73,6 +74,17 @@ The OpenVoxDB version describes the database version contained in the image.
7374
The container version follows semantic versioning and describes changes to the
7475
container image independently of the OpenVoxDB version.
7576

77+
## Permissions
78+
79+
The image runs with GID 0 and supports any runtime UID. GID 0 is what allows
80+
file access.
81+
82+
Volumes can be adjusted to it via:
83+
84+
```shell
85+
chgrp -R 0 <dir> && chmod -R g+rwX <dir>
86+
```
87+
7688
## Configuration
7789

7890
<!-- markdownlint-disable table-column-style -->

openvoxdb/files/container-entrypoint.d/10-wait-for-hosts.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ OPENVOXSERVER_HOSTNAME="${OPENVOXSERVER_HOSTNAME:-puppet}"
3333
OPENVOXSERVER_PORT="${OPENVOXSERVER_PORT:-8140}"
3434

3535
# wait for postgres is ready
36-
/wtfc.sh --timeout="${OPENVOXDB_WAITFORHOST_SECONDS}" --interval=1 --progress "pg_isready -h ${OPENVOXDB_POSTGRES_HOSTNAME} --port '${OPENVOXDB_POSTGRES_PORT:-5432}'"
36+
# -U is required: without it pg_isready derives a username from /etc/passwd,
37+
# which fails under arbitrary UIDs ("no attempt")
38+
/wtfc.sh --timeout="${OPENVOXDB_WAITFORHOST_SECONDS}" --interval=1 --progress "pg_isready -h ${OPENVOXDB_POSTGRES_HOSTNAME} --port '${OPENVOXDB_POSTGRES_PORT:-5432}' -U '${OPENVOXDB_POSTGRES_USER:-openvoxdb}'"
3739

3840
# wait for puppetserver DNS, then healthcheck
3941
if [ "$USE_OPENVOXSERVER" = true ]; then

openvoxdb/files/container-entrypoint.d/20-configure-ssl.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ if [ "$USE_OPENVOXSERVER" = true ]; then
1010
# enable SSL in Jetty
1111
sed -i '/^# ssl-/s/^# //g' /etc/puppetlabs/puppetdb/conf.d/jetty.ini
1212
fi
13-
14-
if [ -w "$SSLDIR" ] && [ "$(id -un)" = "root" ]; then
15-
# make sure Java apps running as puppetdb can read these files
16-
echo "Setting ownership for $SSLDIR to puppetdb:puppetdb"
17-
chown -R puppetdb:puppetdb ${SSLDIR}
18-
fi

openvoxdb/files/ssl.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ ca_running() {
152152
httpsreq_insecure "$(get "${CA}/certificate/ca")" > /dev/null
153153
}
154154

155-
set_file_perms() {
156-
msg "Securing permissions on ${SSLDIR}"
157-
158-
# 700 for directories, 600 for files
159-
find "${SSLDIR}/." -type d -exec chmod u=rwx,g=,o= -- {} +
160-
find "${SSLDIR}/." -type f -exec chmod u=rw,g=,o= -- {} +
161-
}
162-
163155
### Verify we got a signed certificate
164156
verify_cert() {
165157
if [ -f "${CERTFILE}" ] && [ "$(head -1 "${CERTFILE}")" = "${CERTHEADER}" ]; then
@@ -260,7 +252,6 @@ msg "* WAITFORCERT: '${WAITFORCERT}' seconds"
260252
certnames=$(cd "${PRIVKEYDIR}" && ls -A -m -- *.pem 2> /dev/null)
261253
if [ -s "${CERTFILE}" ]; then
262254
msg "Certificates (${certnames}) have already been generated - exiting!"
263-
set_file_perms
264255
exit 0
265256
# warn when rekeying an existing host as it's typically user error
266257
elif [ -n "${certnames}" ]; then
@@ -373,6 +364,4 @@ if ! cert=$(retry_httpsreq "$CERTREQ" $((WAITFORCERT)) 10); then
373364
fi
374365
printf "%s\n" "${cert}" > "${CERTFILE}"
375366

376-
set_file_perms
377-
378367
verify_cert

openvoxdb/prep_release_container.sh

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,26 @@ else
2424
exit 1
2525
fi
2626

27-
# Create puppet user and group, and set permissions on necessary directories
28-
# Used for rootless execution of the container and to match permissions expected by Puppet Server
29-
if command -v apk > /dev/null 2>&1; then
30-
addgroup -g 64604 puppetdb
31-
adduser -G puppetdb -u 64604 -h /opt/puppetlabs/server/data/puppetdb -H -D -s /sbin/nologin puppetdb
32-
else
33-
groupadd --gid 64604 puppetdb
34-
useradd \
35-
--gid puppetdb \
36-
--home-dir /opt/puppetlabs/server/data/puppetdb \
37-
--no-create-home \
38-
--shell /usr/sbin/nologin \
39-
--uid 64604 \
40-
puppetdb
41-
fi
42-
43-
mkdir -p "$LOGDIR"
44-
45-
chown -R puppetdb:puppetdb /etc/puppetlabs/puppetdb
46-
chown -R puppetdb:puppetdb /opt/puppetlabs/server/data/puppetdb
47-
chown -R puppetdb:puppetdb /var/log/puppetlabs/puppetdb
48-
chown -R puppetdb:puppetdb /var/run/puppetlabs/puppetdb
49-
chown -R puppetdb:puppetdb "$LOGDIR"
27+
# The container runs as UID 64604 by default, but any UID works. Everything the
28+
# server needs to write is root-owned with group 0 mirroring the owner permissions
29+
mkdir -p "$LOGDIR" "$SSLDIR"
30+
31+
chown -R 0:0 /etc/puppetlabs/puppetdb
32+
chown -R 0:0 /opt/puppetlabs/server/data/puppetdb
33+
chown -R 0:0 /var/log/puppetlabs/puppetdb
34+
chown -R 0:0 /var/run/puppetlabs/puppetdb
35+
chown -R 0:0 "$LOGDIR"
36+
37+
# group-0 perms for arbitrary UIDs
38+
for d in /etc/puppetlabs /etc/logrotate.d /var/log/puppetlabs /var/run/puppetlabs /opt/puppetlabs "$LOGDIR"; do
39+
mkdir -p "$d"
40+
chgrp -R 0 "$d"
41+
chmod -R g=u "$d"
42+
find "$d" -type d -exec chmod g+s {} +
43+
done
44+
45+
# empty USER lets foreground run under any UID
46+
sed -i 's/^ *USER="puppetdb"/USER=""/' /etc/default/puppetdb
5047

5148
# We want to use the HOCON database.conf and config.conf files, so get rid of the packaged files
5249
rm -f /etc/puppetlabs/puppetdb/conf.d/database.ini

0 commit comments

Comments
 (0)