-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[REVERT][REVERRT] Add group and user in dockerfile to run container as unprivileged #502
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,68 @@ | ||
FROM node:16.13.2-alpine AS BUILD_IMAGE | ||
|
||
# Set the platform to build image for | ||
ARG TARGETPLATFORM | ||
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} | ||
|
||
# Install additional tools needed if on arm64 / armv7 | ||
RUN \ | ||
case "${TARGETPLATFORM}" in \ | ||
'linux/arm64') apk add --no-cache python3 make g++ ;; \ | ||
'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ | ||
esac | ||
|
||
# Create and set the working directory | ||
WORKDIR /app | ||
|
||
# Install app dependencies | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile --network-timeout 1000000 | ||
|
||
# Copy over all project files and folders to the working directory | ||
COPY . ./ | ||
|
||
# Build initial app for production | ||
RUN yarn build | ||
|
||
# Production stage | ||
FROM node:16.13.2-alpine | ||
|
||
# Define some ENV Vars | ||
ENV PORT=80 \ | ||
DIRECTORY=/app \ | ||
IS_DOCKER=true | ||
|
||
# Create and set the working directory | ||
WORKDIR ${DIRECTORY} | ||
|
||
# Install tini for initialization and tzdata for setting timezone | ||
RUN apk add --no-cache tzdata tini | ||
|
||
# Copy built application from build phase | ||
COPY --from=BUILD_IMAGE /app ./ | ||
|
||
# Finally, run start command to serve up the built application | ||
ENTRYPOINT [ "/sbin/tini", "--" ] | ||
CMD [ "yarn", "build-and-start" ] | ||
|
||
# Expose the port | ||
EXPOSE ${PORT} | ||
|
||
# Run simple healthchecks every 5 mins, to check that everythings still great | ||
HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check | ||
FROM node:16.13.2-alpine AS BUILD_IMAGE | ||
|
||
# Set the platform to build image for | ||
ARG TARGETPLATFORM | ||
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} | ||
|
||
# Install additional tools needed if on arm64 / armv7 | ||
RUN \ | ||
case "${TARGETPLATFORM}" in \ | ||
'linux/arm64') apk add --no-cache python3 make g++ ;; \ | ||
'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ | ||
esac | ||
|
||
# Create and set the working directory | ||
WORKDIR /app | ||
|
||
# Install app dependencies | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile --network-timeout 1000000 | ||
|
||
# Copy over all project files and folders to the working directory | ||
COPY . ./ | ||
|
||
# Build initial app for production | ||
RUN yarn build | ||
|
||
# Production stage | ||
FROM node:16.13.2-alpine | ||
|
||
# Define some ENV Vars | ||
ENV PORT=8080 \ | ||
DIRECTORY=/app \ | ||
IS_DOCKER=true \ | ||
USER=docker \ | ||
UID=12345 \ | ||
GID=23456 | ||
|
||
# Install tini for initialization and tzdata for setting timezone | ||
RUN apk add --no-cache tzdata tini \ | ||
# Add group | ||
&& addgroup --gid ${GID} "${USER}" \ | ||
# Add user | ||
&& adduser \ | ||
--disabled-password \ | ||
--ingroup "${USER}" \ | ||
--gecos "" \ | ||
--home "${DIRECTORY}" \ | ||
--no-create-home \ | ||
--uid "$UID" \ | ||
"$USER" | ||
|
||
USER ${USER} | ||
|
||
# Create and set the working directory | ||
WORKDIR ${DIRECTORY} | ||
|
||
# Copy built application from build phase | ||
COPY --from=BUILD_IMAGE --chown=${USER}:${USER} /app ./ | ||
|
||
# Finally, run start command to serve up the built application | ||
ENTRYPOINT [ "/sbin/tini", "--" ] | ||
CMD [ "yarn", "build-and-start" ] | ||
|
||
# Expose the port | ||
EXPOSE ${PORT} | ||
|
||
# Run simple healthchecks every 5 mins, to check that everythings still great | ||
HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
--- | ||
# Welcome to Dashy! To get started, run `docker compose up -d` | ||
# You can configure your container here, by modifying this file | ||
version: "3.8" | ||
services: | ||
dashy: | ||
container_name: Dashy | ||
# Pull latest image from DockerHub | ||
image: lissy93/dashy | ||
# To build from source, replace 'image: lissy93/dashy' with 'build: .' | ||
# build: . | ||
# Or, to use a Dockerfile for your archtecture, uncomment the following | ||
# context: . | ||
# dockerfile: ./docker/Dockerfile-arm32v7 | ||
# You can also use an image with a different tag, or pull from a different registry, e.g: | ||
# image: ghcr.io/lissy93/dashy or image: lissy93/dashy:arm64v8 | ||
# Pass in your config file below, by specifying the path on your host machine | ||
# volumes: | ||
# - /path/to/my-config.yml:/app/public/conf.yml | ||
# - /path/to/item-icons:/app/public/item-icons | ||
# Set port that web service will be served on. Keep container port as 80 | ||
ports: | ||
- 4000:80 | ||
# Set any environmental variables | ||
environment: | ||
- NODE_ENV=production | ||
# Specify your user ID and group ID. You can find this by running `id -u` and `id -g` | ||
# - UID=1000 | ||
# - GID=1000 | ||
# Specify restart policy | ||
restart: unless-stopped | ||
# Configure healthchecks | ||
healthcheck: | ||
test: ['CMD', 'node', '/app/services/healthcheck'] | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 40s | ||
--- | ||
# Welcome to Dashy! To get started, run `docker compose up -d` | ||
# You can configure your container here, by modifying this file | ||
version: "3.8" | ||
services: | ||
dashy: | ||
container_name: Dashy | ||
|
||
# Pull latest image from DockerHub | ||
image: lissy93/dashy | ||
|
||
# To build from source, replace 'image: lissy93/dashy' with 'build: .' | ||
# build: . | ||
|
||
# Or, to use a Dockerfile for your archtecture, uncomment the following | ||
# context: . | ||
# dockerfile: ./docker/Dockerfile-arm32v7 | ||
|
||
# You can also use an image with a different tag, or pull from a different registry, e.g: | ||
# image: ghcr.io/lissy93/dashy or image: lissy93/dashy:arm64v8 | ||
|
||
# Pass in your config file below, by specifying the path on your host machine | ||
# volumes: | ||
# - /path/to/my-config.yml:/app/public/conf.yml | ||
# - /path/to/item-icons:/app/public/item-icons | ||
|
||
# Set port that web service will be served on. Keep container port as 8080 | ||
ports: | ||
- 4000:8080 | ||
|
||
# Set any environmental variables | ||
environment: | ||
- NODE_ENV=production | ||
# Specify your user ID and group ID. You can find this by running `id -u` and `id -g` | ||
# - UID=1000 | ||
# - GID=1000 | ||
|
||
# Specify restart policy | ||
restart: unless-stopped | ||
|
||
# Configure healthchecks | ||
healthcheck: | ||
test: ['CMD', 'node', '/app/services/healthcheck'] | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 40s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the code doesn't need permissions to modify the source itself, I'd set the permissions so root owns the files and everyone else can read them (644). Otherwise, if there was a way for someone to take over the node process, they could add their own files and/or modify the source code.