Skip to content

Commit 1d92e9a

Browse files
authored
Fix user permissions in docker (OpenHands#1565)
* permissions mostly working * fix browser
1 parent 6013fae commit 1d92e9a

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

containers/app/Dockerfile

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ FROM python:3.12-slim as runtime
3333
WORKDIR /app
3434

3535
ENV RUN_AS_DEVIN=true
36-
ENV SANDBOX_USER_ID=1000
36+
ENV OPENDEVIN_USER_ID=1000
3737
ENV USE_HOST_NETWORK=false
3838
ENV SSH_HOSTNAME=host.docker.internal
3939
ENV WORKSPACE_BASE=/opt/workspace_base
@@ -43,29 +43,33 @@ RUN mkdir -p $WORKSPACE_BASE
4343
RUN apt-get update -y \
4444
&& apt-get install -y curl ssh sudo
4545

46-
RUN useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash opendevin && \
46+
RUN sed -i 's/^UID_MIN.*/UID_MIN 499/' /etc/login.defs # Default is 1000, but OSX is often 501
47+
48+
RUN groupadd app
49+
RUN useradd -l -m -u $OPENDEVIN_USER_ID -s /bin/bash opendevin && \
50+
usermod -aG app opendevin && \
4751
usermod -aG sudo opendevin && \
4852
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
49-
RUN chown -R opendevin:opendevin /app
53+
RUN chown -R opendevin:app /app && chmod -R 770 /app
5054
USER opendevin
5155

5256
ENV VIRTUAL_ENV=/app/.venv \
5357
PATH="/app/.venv/bin:$PATH" \
5458
PYTHONPATH='/app'
5559

56-
COPY --chown=opendevin --from=backend-builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
57-
USER root
58-
RUN chown -R opendevin:opendevin ${VIRTUAL_ENV}
59-
USER opendevin
60+
COPY --chown=opendevin:app --chmod=770 --from=backend-builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
61+
RUN playwright install --with-deps chromium
62+
63+
COPY --chown=opendevin:app --chmod=770 ./opendevin ./opendevin
64+
COPY --chown=opendevin:app --chmod=777 ./opendevin/runtime/plugins ./opendevin/runtime/plugins
65+
COPY --chown=opendevin:app --chmod=770 ./agenthub ./agenthub
6066

61-
COPY --chown=opendevin ./opendevin ./opendevin
62-
COPY --chown=opendevin ./agenthub ./agenthub
6367
RUN python opendevin/core/download.py # No-op to download assets
64-
RUN playwright install --with-deps chromium
68+
RUN chown -R opendevin:app /app/logs && chmod -R 770 /app/logs # This gets created by the download.py script
6569

66-
COPY --chown=opendevin --from=frontend-builder /app/dist ./frontend/dist
6770

68-
COPY --chown=opendevin ./containers/app/entrypoint.sh /app/entrypoint.sh
71+
COPY --chown=opendevin:app --chmod=770 --from=frontend-builder /app/dist ./frontend/dist
72+
COPY --chown=opendevin:app --chmod=770 ./containers/app/entrypoint.sh /app/entrypoint.sh
6973

7074
USER root
7175
CMD ["/app/entrypoint.sh"]

containers/app/entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ fi
1212

1313
# change uid of opendevin user to match the host user
1414
# but the group id is not changed, so the user can still access everything under /app
15-
usermod -u $SANDBOX_USER_ID opendevin
15+
useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser
16+
usermod -aG app enduser
17+
mkdir -p /home/enduser/.cache/ms-playwright/
18+
mv /home/opendevin/.cache/ms-playwright/ /home/enduser/.cache/
1619

1720
# get the user group of /var/run/docker.sock and set opendevin to that group
1821
DOCKER_SOCKET_GID=$(stat -c '%g' /var/run/docker.sock)
1922
echo "Docker socket group id: $DOCKER_SOCKET_GID"
20-
usermod -aG $DOCKER_SOCKET_GID opendevin
23+
usermod -aG $DOCKER_SOCKET_GID enduser
2124

2225
# switch to the user and start the server
23-
su opendevin -c "cd /app && uvicorn opendevin.server.listen:app --host 0.0.0.0 --port 3000"
26+
su enduser -c "cd /app && uvicorn opendevin.server.listen:app --host 0.0.0.0 --port 3000"

opendevin/runtime/plugins/jupyter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class JupyterRequirement(PluginRequirement):
99
name: str = 'jupyter'
1010
host_src: str = os.path.dirname(
1111
os.path.abspath(__file__)
12-
) # The directory of this file (sandbox/plugins/jupyter)
12+
) # The directory of this file (opendevin/runtime/plugins/jupyter)
1313
sandbox_dest: str = '/opendevin/plugins/jupyter'
1414
bash_script_path: str = 'setup.sh'

0 commit comments

Comments
 (0)