Skip to content

Commit

Permalink
fix container as a non-root user #3049
Browse files Browse the repository at this point in the history
  • Loading branch information
yurake committed Feb 15, 2023
1 parent 0e01648 commit 5144e94
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions kubernetes/cassandra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"
USER cassandra
WORKDIR /opt/cassandra
COPY entrypoint-wrap.sh /
COPY init /docker-entrypoint-initdb.d
ENTRYPOINT ["/entrypoint-wrap.sh"]
Expand Down
1 change: 1 addition & 0 deletions kubernetes/mongodb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"
USER mongodb
COPY init /docker-entrypoint-initdb.d
2 changes: 2 additions & 0 deletions kubernetes/monitoring/test/postmannewman/quarkus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"
RUN addgroup -S newman && adduser -S newman -G newman
USER newman
COPY hostname-quarkus.postman_environment.json /etc/newman/
COPY jaxrs-quarkus.postman_collection.json /etc/newman/
3 changes: 2 additions & 1 deletion kubernetes/mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"
COPY init /docker-entrypoint-initdb.d
USER mysql
COPY init /docker-entrypoint-initdb.d
16 changes: 16 additions & 0 deletions kubernetes/nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,21 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"

COPY default.conf /etc/nginx/conf.d/default.conf
COPY docs /etc/nginx/docs

# Implement changes required to run NGINX as an unprivileged user
RUN sed -i '/user nginx;/d' /etc/nginx/nginx.conf \
&& sed -i 's,/var/run/nginx.pid,/tmp/nginx.pid,' /etc/nginx/nginx.conf \
&& sed -i "/^http {/a \ proxy_temp_path /tmp/proxy_temp;\n \
client_body_temp_path /tmp/client_temp;\n fastcgi_temp_path /tmp/fastcgi_temp;\n \
uwsgi_temp_path /tmp/uwsgi_temp;\n scgi_temp_path /tmp/scgi_temp;\n" /etc/nginx/nginx.conf \
# Nginx user must own the cache and etc directory to write cache and tweak the nginx config
&& chown -R nginx:nginx /var/cache/nginx \
&& chmod -R g+w /var/cache/nginx \
&& chown -R nginx:nginx /etc/nginx \
&& chmod -R g+w /etc/nginx

EXPOSE 8080
USER nginx
2 changes: 1 addition & 1 deletion kubernetes/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
server {

listen 80;
listen 8080;
server_name localhost;

root /etc/nginx/docs;
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/nginx/nginx-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ spec:
image: yurak/nginx:latest
imagePullPolicy: Always
ports:
- containerPort: 80
- containerPort: 8080
livenessProbe:
tcpSocket:
port: 80
port: 8080
readinessProbe:
httpGet:
port: 9113
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/nginx/nginx-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ spec:
app: nginx
ports:
- protocol: TCP
port: 80
port: 8080
1 change: 1 addition & 0 deletions kubernetes/postgres/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/yurake/k8s-3tier-webapp"
USER postgres
COPY init /docker-entrypoint-initdb.d
COPY conf/postgresql.conf /etc/postgresql/postgresql.conf
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]
2 changes: 2 additions & 0 deletions kubernetes/rabbitmq/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ RUN apk update && \
apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
apk del tzdata
USER rabbitmq

COPY custom_definitions.json /etc/rabbitmq/
RUN printf 'management.load_definitions = /etc/rabbitmq/custom_definitions.json\n' >> /etc/rabbitmq/rabbitmq.conf && \
rabbitmq-plugins enable rabbitmq_prometheus

0 comments on commit 5144e94

Please sign in to comment.