0

If I run the docker exec it is always root user.

The requirement is to always docker exec other than root user still the entrypoint needs to run root some of the sshd config changes and it's restarting. I can't change the user permissions as well to accommodate to change ssh config

is there way to remove root user from bash when I did su in entrypoint.sh

When I do docker exec it should be an example user only, I understand that it is only possible through USER command https://docs.docker.com/engine/reference/builder/#user

I have tried multiple solutions with docker and dokcer-composer still no success.

For example here https://stackoverflow.com/a/47410394/358458

I am just copying and pasting some of the content to understand my question more.

Dokcerfile

FROM ubuntu:latest

RUN useradd -ms /bin/bash exemple

COPY entrypoint.sh /root/entrypoint.sh

ENTRYPOINT "/root/entrypoint.sh"

entrypoint.sh

#!/bin/bash
id
echo 'Banner /usr/bin/custom-banner' >> /etc/ssh/sshd_config
rm -f /etc/ssh/ssh_host_dsa_*

su - exemple
cd /home/example
id
$ docker build -t so-test .
$ docker run --rm -it so-test bash
I am root
uid=0(root) gid=0(root) groups=0(root)
exemple@37b01e316a95:~$ id
uid=1000(exemple) gid=1000(exemple) groups=1000(exemple)
Mallikarjunarao Kosuri
  • 1,023
  • 7
  • 25
  • 52
  • Anyone who can run `docker exec` can pretty trivially use Docker to root the host; they can if nothing else add themselves to the host's `/etc/sudoers` file and manually poke around in the Docker data directory. They could also replace this container with a different one injecting different configuration files. You can't really restrict `docker exec` at all. – David Maze Mar 26 '23 at 10:26
  • (I wouldn't normally recommend running sshd in a container at all. It looks like you're thinking about things like host keys, which is better than many setups, but it's usually easier to operate an administer a container like you would the single process it runs. That might simplify the overall Docker setup, though you still can't prevent `exec` as root into it.) – David Maze Mar 26 '23 at 10:29
  • Thanks for inputs, I think I am not worried ssh part, I am looking little hack that executes the entry point with root user, while docker user had limited permissions. – Mallikarjunarao Kosuri Mar 27 '23 at 05:17

0 Answers0