Skip to content

Commit

Permalink
remove non-root user & sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
Interpause committed Jan 16, 2023
1 parent d194674 commit f74baa9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 30 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// Please follow the same method of creating shell scripts in the `hooks` folder.
"postCreateCommand": ". /tmp/.devcontainer/hooks/postCreate.sh",
"postStartCommand": ". /tmp/.devcontainer/hooks/postStart.sh",
"remoteUser": "user",
"remoteEnv": {
"WORKSPACE_ROOT": "${containerWorkspaceFolder}"
},
Expand Down
9 changes: 2 additions & 7 deletions .devcontainer/hooks/postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

. /opt/ros/$ROS_DISTRO/setup.sh

# Mitigates the Dockerfile somehow breaking folder permissions.
echo Workspace root is $WORKSPACE_ROOT
sudo ln -s "$WORKSPACE_ROOT" /code
sudo chown user:user "$WORKSPACE_ROOT"

# Something deleted the package indexes so we re-download them for convenience.
sudo apt-get update
sudo rosdep update
apt-get update
rosdep update
7 changes: 3 additions & 4 deletions .devcontainer/hooks/postStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ test -d "/code/.git" \
)

# (OPTION) Symlink `/data` to `/code/data` for convenience if using `/data` mount point.
# sudo chown user:user /data
# sudo ln -sf /data /code/
# ln -sf /data /code/

# Ensure dependencies are installed.
sudo rosdep install -i --from-path /code -y
sudo pip install -r /code/requirements.txt
rosdep install -i --from-path /code -y
pip install -r /code/requirements.txt
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"label": "rosdep install dependencies",
"type": "shell",
"command": "sudo rosdep install -i --from-path /code -y",
"command": "rosdep install --ignore-src --from-path . -y",
"problemMatcher": []
},
{
Expand Down
16 changes: 2 additions & 14 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@ RUN echo 'Etc/UTC' > /etc/timezone \
RUN apt-get update \
# Needed to curl and authorize ROS repository key.
&& apt-get install -y curl gnupg lsb-release software-properties-common \
&& apt-get install -y sudo git \
&& apt-get install -y git \
# Enable universe repositories.
&& add-apt-repository universe

# Create user and add to sudoers.
ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG USER_SH=/bin/bash
RUN groupadd -g $USER_GID $USERNAME \
&& useradd -u $USER_UID -g $USER_GID -s $USER_SH -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Add VNC server & noVNC web app for debugging and control.
COPY ./.devcontainer/scripts/desktop-lite-debian.sh /tmp/scripts/desktop-lite-debian.sh
ENV DBUS_SESSION_BUS_ADDRESS="autolaunch:" \
Expand All @@ -37,7 +27,7 @@ ENV DBUS_SESSION_BUS_ADDRESS="autolaunch:" \
VNC_PORT="5901" \
NOVNC_PORT="6080" \
DISPLAY=":1"
RUN bash /tmp/scripts/desktop-lite-debian.sh $USERNAME password
RUN bash /tmp/scripts/desktop-lite-debian.sh root password

# Enable openCL support (OpenCV uses it for hardware acceleration).
RUN mkdir -p /etc/OpenCL/vendors && \
Expand Down Expand Up @@ -80,8 +70,6 @@ ENTRYPOINT [ \
"/entrypoint.sh" \
]

USER $USERNAME

# Make /bin/sh launch bash instead.
ENV ENV=\$HOME/.shrc
RUN echo "exec bash" >> ~/.shrc
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ git rm example_module
The `rosdep` and Ubuntu package managers rely on a local cache of their package index. If the package index is outdated, it may not contain any active package distribution server, leading to package downloads failing. Hence, it is recommended to periodically re-download the package index:

```sh
sudo apt-get update
sudo rosdep update
apt-get update
rosdep update
```

### Minimize changes to the Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
# (OPTION) Mount point for `data` folder.
# - ./data:/data:cached
# (OPTION)(LINUX)(X11) Mount host's `.Xauthority` to allow container to self-authenticate with X Server.
# - $HOME/.Xauthority:/home/user/.Xauthority:rw
# - $HOME/.Xauthority:/home/root/.Xauthority:rw

# (OPTION)(LINUX)(X11) Use X Server address from host.
# environment:
Expand Down

0 comments on commit f74baa9

Please sign in to comment.