Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"I have no name!" as user logging into Jenkins in a docker container that uses Tini

I'm currently using a Jenkins instance inside a docker container. This image happens to use Tini as PID 1. When I try open a shell into it with:

$ docker exec -it jenkins /bin/bash

I get this as username:

I have no name!@<container_id_hash>:/$

This is keeping me from using shell born ssh commands from Jenkins jobs that runs inside this container:

$ ssh
$ No user exists for uid 497
$ id
$ uid=497 gid=495 groups=495

I tried creating an user for that uid in /etc/passwd and also a group for that gid in /etc/group but it was a no deal!

I'm only able to run ssh manually if I login as jenkins user like this:

$ docker exec -it --user=jenkins jenkins /bin/bash

I could circle around that using ssh related plugins. But I'm really curious to understand why this happens only with docker images that use Tini as ENTRYPOINT.

UPDATE1

I did something like this in /etc/passwd:

jenkins:x:497:495::/var/jenkins_home:/bin/bash

and this in /etc/group:

jenkins:x:495:

Also tried other names like yesihaveaname and yesihaveagroup instead of jenkins

UPDATE2

I've been in contact with Tini's developer and he does not believe the cause for this problem is Tini as it does not mess around uid or gid, any other leads would be apreciated.

like image 726
Rogério Peixoto Avatar asked Jun 15 '16 12:06

Rogério Peixoto


People also ask

Which command should be used to start Docker service in the Jenkins Docker container?

On the configuration page, click "Add build step" then "Execute shell". In the command box enter "sudo docker run hello-world"


1 Answers


update
good to know (this was to easy, so I overlooked this for some time *facepalm*):
To login into a container as root, just give --user root to your exec command - like:
docker exec -ti -u root mycontainername bash ... no need to copy passwd file and set pw-hashes ...


Like your posted link says, the UserID inside the container maybe has no name allocated.

(Although I do not use Tini... ) I solved this problem as following:

1.) execute INSIDE the container (docker exec -ti mycontainername sh):

id    # shows the userid (e.g. 1234) and groupid (e.g. 1235) of the current session

2.) execute OUTSIDE the container (on the local machine):

docker cp mycontainername:/etc/passwd /tmp   # this copies the passwd-file to from inside the container to my local /tmp-directory
echo "somename:x:1234:1235:somename:/tmp:/bin/bash" >> /tmp/passwd   # add some username *!!with the userid and groupid from the output!!* of the `id` command inside the container (CAUTION: do NOT overwrite, do JUST APPEND to the file) - "1234" is just exemplary, do not use it
docker cp /tmp/passwd mycontainername:/etc/passwd   # copy the file back, overwriting the /etc/passwd inside the container

Now login to the container (docker exec -ti mycontainername sh) again.

P.S. If you know the root password of the container you can now switch to root If you don't have it, you can copy the "/etc/shadow" file out of the container (like above), then edit the root-entry with a known password hash**, then copy it back into the container and then login to the container and run su)

** to get this password hash on your local system: (1) add a temporary testuser (sudo useradd testdumpuser) (2) give this user as password (sudo passwd testdumpuser) (3) look in the /etc/shadow-file for the "testdumpuser"-entry and copy this long odd string after the first ":" until the second ":"

like image 73
MacMartin Avatar answered Sep 23 '22 21:09

MacMartin