Skip to content

Commit

Permalink
Merge pull request #3168 from cisagov/dk/3166-node-permissions-fix
Browse files Browse the repository at this point in the history
#3166: Fix for node container permissions bug
  • Loading branch information
dave-kennedy-ecs authored Dec 5, 2024
2 parents ee4a584 + 3f062a9 commit 1282897
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ services:
volumes:
- .:/app
working_dir: /app
entrypoint: /app/node_entrypoint.sh
stdin_open: true
tty: true
command: ./run_node_watch.sh
Expand Down
6 changes: 3 additions & 3 deletions src/node.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM docker.io/cimg/node:current-browsers
WORKDIR /app

USER root

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=circleci:circleci package*.json ./

RUN npm install
COPY --chown=circleci:circleci package*.json ./
24 changes: 24 additions & 0 deletions src/node_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Get UID and GID of the /app directory owner
HOST_UID=$(stat -c '%u' /app)
HOST_GID=$(stat -c '%g' /app)

# Check if the circleci user exists
if id "circleci" &>/dev/null; then
echo "circleci user exists. Updating UID and GID to match host UID:GID ($HOST_UID:$HOST_GID)"

# Update circleci user's UID and GID
groupmod -g "$HOST_GID" circleci
usermod -u "$HOST_UID" circleci

echo "Updating ownership of /app recursively to circleci:circleci"
chown -R circleci:circleci /app

# Switch to circleci user and execute the command
echo "Switching to circleci user and running command: $@"
su -s /bin/bash -c "$*" circleci
else
echo "circleci user does not exist. Running command as the current user."
exec "$@"
fi
1 change: 1 addition & 0 deletions src/run_node_watch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

npm install
npm rebuild
dir=./registrar/assets
Expand Down

0 comments on commit 1282897

Please sign in to comment.