Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security - Backend - wolfi container base image with support for rootless user #8179

Merged
merged 23 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6c8a2a5
[grid] secure base + rootless user + cached deps
yashgorana Oct 18, 2023
3c0d1d5
[grid] make syft use rootless user paths
yashgorana Oct 18, 2023
7249a68
Fixed issue with missing build tools for some python packages
madhavajay Oct 18, 2023
a46ccd5
Merge branch 'dev' into yash/secure-base
yashgorana Oct 20, 2023
9ee1995
revert setup.cfg changes
yashgorana Oct 20, 2023
9a3df9b
[grid] fix duplication in build caches
yashgorana Oct 20, 2023
2b4030e
[grid] fix potential deps conflicts
yashgorana Oct 20, 2023
1b38416
[grid] fix incorrect backend target name
yashgorana Oct 20, 2023
10bfcdb
Merge branch 'dev' into yash/secure-base
yashgorana Oct 23, 2023
c241c37
[grid] rename env BACKEND_STORAGE_PATH to CREDENTIALS_VOLUME
yashgorana Oct 23, 2023
7d78fec
[grid] use rootless /home/azureuser/data for storage
yashgorana Oct 23, 2023
c468426
[grid] update helm charts
yashgorana Oct 23, 2023
644d364
[grid] do not log private key
yashgorana Oct 23, 2023
fd9cedf
[grid] fix mkdir
yashgorana Oct 23, 2023
133b71f
revert worker changes
yashgorana Oct 23, 2023
2698c95
[grid] fix ci error
yashgorana Oct 23, 2023
2a78582
[grid] use new syftuser(uid=1000)
yashgorana Oct 24, 2023
429bfdf
[tox] print user & id
yashgorana Oct 25, 2023
6a3f2ef
Merge branch 'dev' into yash/secure-base
yashgorana Oct 26, 2023
9da1be4
[tox] fix integration tests
yashgorana Oct 26, 2023
c3dc987
[grid] log permissions
yashgorana Oct 26, 2023
2167f75
[grid] revert to root user
yashgorana Oct 26, 2023
fbdb1d1
Merge branch 'dev' into yash/secure-base
yashgorana Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
**/*.pyc

grid/data
grid/packer
grid/.devspace
syftcli
syftcli

syft/tests
syft/README.md
112 changes: 61 additions & 51 deletions packages/grid/backend/backend.dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
ARG PYTHON_VERSION='3.11'
ARG PYTHON_VERSION="3.11"
ARG TZ="Etc/UTC"
ARG SYFT_WORKDIR="/home/nonroot/app"
ARG NONROOT_UG="nonroot:nonroot"

FROM python:3.11-slim as build
# ==================== [BUILD STEP] Python Dev Base ==================== #

# set UTC timezone
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM cgr.dev/chainguard/wolfi-base as python_dev

RUN mkdir -p /root/.local
ARG PYTHON_VERSION
ARG TZ

RUN apt-get update && apt-get upgrade -y
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install -y --no-install-recommends \
curl python3-dev gcc make build-essential cmake git
# Setup Python DEV
RUN apk update && \
apk add build-base gcc tzdata python-$PYTHON_VERSION-dev py$PYTHON_VERSION-pip && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN --mount=type=cache,target=/root/.cache \
pip install -U pip
# ==================== [BUILD STEP] Install Syft Dependency ==================== #

#install jupyterlab
RUN --mount=type=cache,target=/root/.cache \
pip install --user jupyterlab
FROM python_dev as syft_deps

WORKDIR /app
ARG SYFT_WORKDIR
ARG NONROOT_UG

# Backend
FROM python:$PYTHON_VERSION-slim as backend
RUN apt-get update && apt-get upgrade -y
COPY --from=build /root/.local /root/.local
USER nonroot
WORKDIR $SYFT_WORKDIR
ENV PATH=$PATH:/home/nonroot/.local/bin

ENV PYTHONPATH=/app
ENV PATH=/root/.local/bin:$PATH
# copy skeleton to do package install
COPY --chown=$NONROOT_UG syft/setup.py ./syft/setup.py
COPY --chown=$NONROOT_UG syft/setup.cfg ./syft/setup.cfg
COPY --chown=$NONROOT_UG syft/pyproject.toml ./syft/pyproject.toml
COPY --chown=$NONROOT_UG syft/MANIFEST.in ./syft/MANIFEST.in
COPY --chown=$NONROOT_UG syft/src/syft/VERSION ./syft/src/syft/VERSION
COPY --chown=$NONROOT_UG syft/src/syft/capnp ./syft/src/syft/capnp

# Install all dependencies together here to avoid any version conflicts across pkgs
RUN --mount=type=cache,target=/home/nonroot/.cache/,rw,uid=65532 \
pip install --user pip-autoremove jupyterlab==4.0.7 -e ./syft/ && \
pip-autoremove ansible ansible-core -y

# ==================== [Final] Setup Syft Server ==================== #

FROM cgr.dev/chainguard/wolfi-base as backend

# inherit from global
ARG PYTHON_VERSION
ARG TZ
ARG SYFT_WORKDIR
ARG NONROOT_UG

RUN --mount=type=cache,target=/root/.cache \
pip install -U pip
# Setup Python
RUN apk update && \
apk add --no-cache tzdata bash python-$PYTHON_VERSION py$PYTHON_VERSION-pip && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
rm -rf /var/cache/apk/*

WORKDIR /app
USER nonroot
WORKDIR $SYFT_WORKDIR

# Update environment variables
ENV PATH=$PATH:/home/nonroot/.local/bin \
PYTHONPATH=$SYFT_WORKDIR \
APPDIR=$SYFT_WORKDIR

# Copy pre-built jupyterlab, syft dependencies
COPY --chown=$NONROOT_UG --from=syft_deps /home/nonroot/.local /home/nonroot/.local

# copy grid
COPY grid/backend /app/
COPY --chown=$NONROOT_UG grid/backend/grid ./grid

# copy skeleton to do package install
COPY syft/setup.py /app/syft/setup.py
COPY syft/setup.cfg /app/syft/setup.cfg
COPY syft/pyproject.toml /app/syft/pyproject.toml
COPY syft/MANIFEST.in /app/syft/MANIFEST.in
COPY syft/src/syft/VERSION /app/syft/src/syft/VERSION
COPY syft/src/syft/capnp /app/syft/src/syft/capnp

# install syft
RUN --mount=type=cache,target=/root/.cache \
pip install --user -e /app/syft && \
pip uninstall ansible ansible-core -y && \
rm -rf ~/.local/lib/python3.11/site-packages/ansible_collections

# security patches
RUN apt purge --auto-remove linux-libc-dev -y || true
RUN apt purge --auto-remove libldap-2.5-0 -y || true

# copy any changed source
COPY syft/src /app/syft/src

# change to worker-start.sh or start-reload.sh as needed
CMD ["bash", "/app/grid/start.sh"]
# copy syft
COPY --chown=$NONROOT_UG syft/ ./syft/

CMD ["bash", "./grid/start.sh"]
2 changes: 1 addition & 1 deletion packages/grid/backend/grid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_env(key: str, default: str = "") -> Optional[str]:
return None


CREDENTIALS_PATH = str(get_env("CREDENTIALS_PATH", "/storage/credentials.json"))
CREDENTIALS_PATH = str(get_env("CREDENTIALS_PATH", "./storage/credentials.json"))
NODE_PRIVATE_KEY = "NODE_PRIVATE_KEY"
NODE_UID = "NODE_UID"

Expand Down
2 changes: 1 addition & 1 deletion packages/grid/backend/grid/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
mongo_store_config = MongoStoreConfig(client_config=mongo_client_config)


client_config = SQLiteStoreClientConfig(path="/storage/")
yashgorana marked this conversation as resolved.
Show resolved Hide resolved
client_config = SQLiteStoreClientConfig(path="./storage/")
sql_store_config = SQLiteStoreConfig(client_config=client_config)

node_type = get_node_type()
Expand Down
6 changes: 3 additions & 3 deletions packages/grid/backend/grid/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ if [[ ${DEV_MODE} == "True" ]];
then
echo "DEV_MODE Enabled"
RELOAD="--reload"
pip install -e "/app/syft[telemetry]"
pip install -e "$APPDIR/syft[telemetry]"
fi

set +e
NODE_PRIVATE_KEY=$(python /app/grid/bootstrap.py --private_key)
NODE_UID=$(python /app/grid/bootstrap.py --uid)
NODE_PRIVATE_KEY=$(python $APPDIR/grid/bootstrap.py --private_key)
NODE_UID=$(python $APPDIR/grid/bootstrap.py --uid)
set -e

echo "NODE_PRIVATE_KEY=$NODE_PRIVATE_KEY"
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ dev:
value: "True"
logs: {}
sync:
- path: ./backend/grid:/app/grid
- path: ../syft:/app/syft
- path: ./backend/grid:/home/nonroot/app/grid
- path: ../syft:/home/nonroot/app/syft

profiles:
- name: gateway
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
worker = worker_class(
name=node_name,
local_db=True,
sqlite_path="/storage/",
sqlite_path="./storage/",
node_type=node_type,
enable_warnings=enable_warnings,
node_side_type=node_side_type,
Expand Down