Skip to content

Commit 2776543

Browse files
committed
Support for Running Deployer with Aribtrary UID
The deployer container is now able to run as an arbitrary UID in an OpenShift environment. This ensures that the deployer is able to run properly using the 'restricted' SCC.
1 parent b12caea commit 2776543

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

bin/uid_daemon.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# Copyright 2020 Crunchy Data Solutions, Inc.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
if ! whoami &> /dev/null
17+
then
18+
if [[ -w /etc/passwd ]]
19+
then
20+
sed "/daemon:x:2:/d" /etc/passwd >> /tmp/uid.tmp
21+
cp /tmp/uid.tmp /etc/passwd
22+
rm -f /tmp/uid.tmp
23+
echo "${USER_NAME:-daemon}:x:$(id -u):0:${USER_NAME:-daemon} user:${HOME}:/bin/bash" >> /etc/passwd
24+
fi
25+
fi
26+
exec "$@"

centos7/Dockerfile.pgo-deployer.centos7

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ RUN yum -y install epel-release \
1616
which \
1717
gettext
1818

19-
USER daemon
20-
2119
COPY installers/ansible /ansible
2220
COPY installers/image/bin/pgo-deploy.sh /pgo-deploy.sh
2321
COPY installers/image/inventory_template /inventory_template
22+
COPY bin/uid_daemon.sh /uid_daemon.sh
23+
24+
RUN chmod g=u /etc/passwd
25+
RUN chmod g=u /uid_daemon.sh
26+
27+
ENTRYPOINT ["/uid_daemon.sh"]
28+
29+
USER daemon
30+
31+
CMD ["/pgo-deploy.sh"]

installers/kubectl/postgres-operator.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ spec:
134134
restartPolicy: Never
135135
containers:
136136
- name: pgo-deploy
137-
command: ["/pgo-deploy.sh"]
138137
image: registry.developers.crunchydata.com/crunchydata/pgo-deployer:centos7-4.3.1
139138
imagePullPolicy: IfNotPresent
140139
env:

rhel7/Dockerfile.pgo-deployer.rhel7

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ RUN yum install -y https://download.fedoraproject.org/pub/epel/epel-release-late
1616
which \
1717
gettext
1818

19-
USER daemon
20-
2119
COPY installers/ansible /ansible
2220
COPY installers/image/bin/pgo-deploy.sh /pgo-deploy.sh
2321
COPY installers/image/inventory_template /inventory_template
22+
COPY bin/uid_daemon.sh /uid_daemon.sh
23+
24+
RUN chmod g=u /etc/passwd
25+
RUN chmod g=u /uid_daemon.sh
26+
27+
ENTRYPOINT ["/uid_daemon.sh"]
28+
29+
USER daemon
30+
31+
CMD ["/pgo-deploy.sh"]

0 commit comments

Comments
 (0)