Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jun 19, 2023
2 parents b7e71ea + 5619968 commit 1bc1447
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 38 deletions.
20 changes: 13 additions & 7 deletions src/docker/Dockerfile-bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-bookworm-slim as base
ENV DEBIAN_FRONTEND noninteractive

# Configure local user
ENV USER root
USER root
ENV HOME /app-root

# Avoid Python cache during build
Expand Down Expand Up @@ -188,17 +188,23 @@ RUN rm arch.sh
ENV PYTHONDONTWRITEBYTECODE=
ENV PIP_BREAK_SYSTEM_PACKAGES=

# Configure startup
COPY uid_entrypoint.sh /
RUN chmod a=rx /uid_entrypoint.sh \
&& chmod a+w /etc/passwd /etc/shadow
ENTRYPOINT ["/tini", "--", "/uid_entrypoint.sh"]

# Configure local user
RUN mkdir -p /run/user/0 ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& chown -R ${USER} /run/user/0 ${HOME} \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid
USER 0:0
ENV XDG_RUNTIME_DIR=/run/user/0
ENV USER app-user
RUN mkdir -p ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
ENV TMPDIR=${HOME}/.local/tmp
ENV BUILDKIT_HOST=unix:///run/user/0/buildkit/buildkitd.sock

# Install Azure Pipelines Agent startup script
WORKDIR ${AZP_HOME}
COPY start.sh .

# Run as exec form, so that it can receive signals from Tini
USER ${USER}
CMD ["bash", "start.sh"]
21 changes: 13 additions & 8 deletions src/docker/Dockerfile-bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim as base
ENV DEBIAN_FRONTEND noninteractive

# Configure local user
ENV USER root
USER root
ENV HOME /app-root

# Avoid Python cache during build
Expand Down Expand Up @@ -148,7 +148,6 @@ ENV TINI_VERSION ${TINI_VERSION}
RUN curl -LsSf --retry 3 https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$(ARCH_X64=amd64 bash arch.sh) -o /tini \
&& chmod +x /tini \
&& /tini --version
ENTRYPOINT ["/tini", "--"]

# Install BuildKit, then verify installation
ARG BUILDKIT_VERSION
Expand Down Expand Up @@ -184,17 +183,23 @@ RUN rm arch.sh
# Reset Python configs to default
ENV PYTHONDONTWRITEBYTECODE=

# Configure startup
COPY uid_entrypoint.sh /
RUN chmod a=rx /uid_entrypoint.sh \
&& chmod a+w /etc/passwd /etc/shadow
ENTRYPOINT ["/tini", "--", "/uid_entrypoint.sh"]

# Configure local user
RUN mkdir -p /run/user/0 ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& chown -R ${USER} /run/user/0 ${HOME} \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid
USER 0:0
ENV XDG_RUNTIME_DIR=/run/user/0
ENV USER app-user
RUN mkdir -p ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
ENV TMPDIR=${HOME}/.local/tmp
ENV BUILDKIT_HOST=unix:///run/user/0/buildkit/buildkitd.sock

# Install Azure Pipelines Agent startup script
WORKDIR ${AZP_HOME}
COPY start.sh .

# Run as exec form, so that it can receive signals from Tini
USER ${USER}
CMD ["bash", "start.sh"]
20 changes: 13 additions & 7 deletions src/docker/Dockerfile-focal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal as base
ENV DEBIAN_FRONTEND noninteractive

# Configure local user
ENV USER root
USER root
ENV HOME /app-root

# Avoid Python cache during build
Expand Down Expand Up @@ -185,17 +185,23 @@ RUN rm arch.sh
# Reset Python configs to default
ENV PYTHONDONTWRITEBYTECODE=

# Configure startup
COPY uid_entrypoint.sh /
RUN chmod a=rx /uid_entrypoint.sh \
&& chmod a+w /etc/passwd /etc/shadow
ENTRYPOINT ["/tini", "--", "/uid_entrypoint.sh"]

# Configure local user
RUN mkdir -p /run/user/0 ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& chown -R ${USER} /run/user/0 ${HOME} \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid
USER 0:0
ENV XDG_RUNTIME_DIR=/run/user/0
ENV USER app-user
RUN mkdir -p ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
ENV TMPDIR=${HOME}/.local/tmp
ENV BUILDKIT_HOST=unix:///run/user/0/buildkit/buildkitd.sock

# Install Azure Pipelines Agent startup script
WORKDIR ${AZP_HOME}
COPY start.sh .

# Run as exec form, so that it can receive signals from Tini
USER ${USER}
CMD ["bash", "start.sh"]
20 changes: 13 additions & 7 deletions src/docker/Dockerfile-jammy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy as base
ENV DEBIAN_FRONTEND noninteractive

# Configure local user
ENV USER root
USER root
ENV HOME /app-root

# Avoid Python cache during build
Expand Down Expand Up @@ -193,17 +193,23 @@ RUN rm arch.sh
# Reset Python configs to default
ENV PYTHONDONTWRITEBYTECODE=

# Configure startup
COPY uid_entrypoint.sh /
RUN chmod a=rx /uid_entrypoint.sh \
&& chmod a+w /etc/passwd /etc/shadow
ENTRYPOINT ["/tini", "--", "/uid_entrypoint.sh"]

# Configure local user
RUN mkdir -p /run/user/0 ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& chown -R ${USER} /run/user/0 ${HOME} \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid
USER 0:0
ENV XDG_RUNTIME_DIR=/run/user/0
ENV USER app-user
RUN mkdir -p ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
ENV TMPDIR=${HOME}/.local/tmp
ENV BUILDKIT_HOST=unix:///run/user/0/buildkit/buildkitd.sock

# Install Azure Pipelines Agent startup script
WORKDIR ${AZP_HOME}
COPY start.sh .

# Run as exec form, so that it can receive signals from Tini
USER ${USER}
CMD ["bash", "start.sh"]
20 changes: 13 additions & 7 deletions src/docker/Dockerfile-ubi8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8 as base

# Configure local user
ENV USER root
USER root
ENV HOME /app-root

# Avoid Python cache during build
Expand Down Expand Up @@ -184,17 +184,23 @@ RUN rm arch.sh
# Reset Python configs to default
ENV PYTHONDONTWRITEBYTECODE=

# Configure startup
COPY uid_entrypoint.sh /
RUN chmod a=rx /uid_entrypoint.sh \
&& chmod a+w /etc/passwd /etc/shadow
ENTRYPOINT ["/tini", "--", "/uid_entrypoint.sh"]

# Configure local user
RUN mkdir -p /run/user/0 ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& chown -R ${USER} /run/user/0 ${HOME} \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid
USER 0:0
ENV XDG_RUNTIME_DIR=/run/user/0
ENV USER app-user
RUN mkdir -p ${HOME}/.local/tmp ${HOME}/.local/share/buildkit \
&& echo ${USER}:100000:65536 | tee /etc/subuid | tee /etc/subgid \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers
ENV TMPDIR=${HOME}/.local/tmp
ENV BUILDKIT_HOST=unix:///run/user/0/buildkit/buildkitd.sock

# Install Azure Pipelines Agent startup script
WORKDIR ${AZP_HOME}
COPY start.sh .

# Run as exec form, so that it can receive signals from Tini
USER ${USER}
CMD ["bash", "start.sh"]
17 changes: 17 additions & 0 deletions src/docker/uid_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

if ! whoami &>/dev/null; then
# Create arbitrary user at run-time
echo "${USER}:x:$(id -u):0:::${HOME}:/sbin/nologin" >>/etc/passwd
# Allow to log without password
echo "${USER}:!:18000:0:99999:7:::" >>/etc/shadow
# Reset permissions for local user
sudo chmod a-w /etc/passwd /etc/shadow

# Local config for BuildKit
export XDG_RUNTIME_DIR=/run/user/$(id -u)
export BUILDKIT_HOST=unix:///run/user/$(id -u)/buildkit/buildkitd.sock
fi

exec "$@"
3 changes: 1 addition & 2 deletions src/helm/azure-pipelines-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ Can be overriden by setting ".Values.securityContext".
See: https://kubernetes.io/docs/concepts/windows/intro/#compatibility-v1-pod-spec-containers
*/}}
{{- define "azure-pipelines-agent.defaultSecurityContext" -}}
runAsNonRoot: false
runAsNonRoot: true
readOnlyRootFilesystem: false
{{- if .Values.image.isWindows }}
windowsOptions:
runAsUserName: ContainerAdministrator
{{- else }}
allowPrivilegeEscalation: false
runAsUser: 0
capabilities:
drop: ["ALL"]
{{- end }}
Expand Down

0 comments on commit 1bc1447

Please sign in to comment.