Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions in docker images are lost during gitpod restore #3174

Closed
shaal opened this issue Feb 11, 2021 · 11 comments · Fixed by #3385
Closed

Permissions in docker images are lost during gitpod restore #3174

shaal opened this issue Feb 11, 2021 · 11 comments · Fixed by #3385

Comments

@shaal
Copy link
Contributor

shaal commented Feb 11, 2021

UPDATE:

This problem is actually not just about setuid, but about permissions in general.
Follow this comment #3174 (comment) for an even simpler steps to reproduce the issue.


Describe the bug

In a workspace using sudo docker-up and pulling a docker image, it has sudo with the correct setuid bit.
-rwsrwxrwx 1 root root 157192 Feb 2 2020 /usr/bin/sudo

But after timeout/restarting the workspace, the sudo in the image has the wrong setuid bit
-rwxr-xr-x 1 root root 157192 Feb 2 2020 /usr/bin/sudo

Steps to reproduce

I created a minimal setup to reproduce the behavior:
https://gitpod.io/#https://github.com/shaal/gitpod-restart-test

  1. Start the workspace
  2. The workspace will run sudo docker-up
  3. The workspace will pull an image and display the image's /usr/bin/sudo permissions (ie. docker run -it --rm drud/ddev-webserver:v1.16.3 ls -l /usr/bin/sudo)
  4. The permission should be -rwsrwxrwx
  5. Using https://gitpod.io/workspaces - Stop the current workspace (alternatively you can wait for the workspace to timeout)
  6. Start the same workspace again
  7. Run docker run -it --rm drud/ddev-webserver:v1.16.3 ls -l /usr/bin/sudo
  8. Now the permission is wrong -rwxr-xr-x, it's missing the setuid bit.
  • Please note that the issue happens with any image.

Expected behavior

The setuid bit should stay the same after restarting a workspace.

Additional information

Example repository

https://github.com/shaal/gitpod-restart-test

@ArthurSens ArthurSens added type: bug Something isn't working type: needs triage We've seen the issue but need to investigate to decide what type of issue it is labels Feb 11, 2021
@ArthurSens
Copy link
Contributor

ArthurSens commented Feb 11, 2021

Thanks for the report @shaal!

Sorry if the answer is obvious, but how does changing the setuid bit affects your work when using Gitpod? I'm not saying it isn't a bug, just thinking about prioritization... 🤔

@shaal
Copy link
Contributor Author

shaal commented Feb 11, 2021

Sorry, I tried being specific and wanted to show the simplest way to reproduce the bug.

The way it affects my work, is that when a workspace times out, I can no longer work on that workspace again, until I destroy all docker containers.

You can see an example project here -
https://gitpod.io/#https://github.com/shaal/ddevenv

It opens one terminal with sudo docker-up, and another terminal with ddev start (pulling docker images to build the environment).
When starting the workspace everything works well.
Run gp url 8080, and open that URL in browser.
You would see the following:
image

Now stop the workspace (or wait for it to timeout)
Start the workspace again.

You'll see in the 3rd terminal, the command ddev start, failing with this error:

Starting ddevenv... 
Building ddev-ssh-agent 
Recreating ddev-ssh-agent ... done
 
Failed to start ddevenv: ddev-ssh-agent failed to become ready; debug with 'docker logs ddev-ssh-agent'; error: container /ddev-ssh-agent unhealthy:  

Running docker logs ddev-ssh-agent display this:

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
Creating a proxy socket...
Running socat UNIX-LISTEN:/tmp/.ssh-agent/proxy-socket,perm=0666,fork UNIX-CONNECT:/tmp/.ssh-agent/socket
Launching ssh-agent...
2021/02/11 18:53:12 socat[11] E bind(5, {AF=1 "/tmp/.ssh-agent/proxy-socket"}, 30): Permission denied
unix_listener: cannot bind to path /tmp/.ssh-agent/socket: Permission denied

@rfay
Copy link

rfay commented Feb 11, 2021

The fundamental problem is that several of the images used for ddev have sudo in them, and of course sudo is not usable with the setuid bit reset inappropriately. I'm sure there are other utilities that would be hobbled with the setuid inappropriately reset, but sudo is the big one.

When a workspace is awakened, the setuid bit is no longer set on sudo inside these images. It should not have been changed.

And it doesn't matter if you re-pull the image. Same result.

@csweichel csweichel added feature: docker in workspaces feature: root access roadmap item: root & docker https://bit.ly/2XlgB5p and removed type: needs triage We've seen the issue but need to investigate to decide what type of issue it is labels Feb 12, 2021
@csweichel
Copy link
Contributor

Thank you for reporting this.

This look like an issue with the content init during workspace startup. Apparently we're not preserving file modes correctly in some cases.

@rfay
Copy link

rfay commented Feb 14, 2021

I'm obviously a novice to the codebase, but a common way to lose setuid bits and ownership information is to run tar x without root privileges. I wonder if that's happening here:

tarcmd := exec.Command("tar", "x")

@rfay
Copy link

rfay commented Feb 17, 2021

This problem is actually not just about setuid, but about permissions in general.

In a docker image that had a directory with permissions 0777 (/etc/alternatives), after restore it has 0755 privileges.

@shaal maybe you can update the title to add "different permissions entirely"

@shaal shaal changed the title sudo's setuid bit is gone after workspace restart Permissions in docker images are lost during gitpod restore Feb 17, 2021
@rfay
Copy link

rfay commented Feb 17, 2021

I put together a repro case for the loss of permissions. It shows that both files and directories inside a docker image have their permissions changed (lost) during a gitpod restore.

Please see https://github.com/rfay/gitpod-bug-repro or go straight to https://gitpod.io/#https://github.com/rfay/gitpod-bug-repro - it's easy to follow and recreate, and shows at least 3 cases of lost permissions, not just setuid (as was the OP here) but also directory and file permissions of 777 get cut back to 755.

@aledbf
Copy link
Member

aledbf commented Mar 10, 2021

@rfay thank you for the repository reproducing the issue.

@shaal
Copy link
Contributor Author

shaal commented Mar 28, 2021

@aledbf @csweichel is it possible to re-open this issue? I think the bug is not resolved yet.

The new Gitpod , does restore the workspace with the correct file permissions, but the owner of the files is 33333 instead of root.

I forked @rfay repo, and added a .gitpod.yml file that runs the docker command during prebuild.
https://github.com/shaal/gitpod-bug-repro

You can run the command manually, according to the Readme of that repo to see the same issue.

The result after workspace restore: (where file owner should be root and not 33333)

/var/tmp:
total 8
drwxrwxrwx 2 www-data 33333 4096 Feb 17 21:16 dir-with-perms
drwxr-xr-x 2    33333 33333 4096 Feb 17 21:28 filebits
/var/tmp/dir-with-perms:
total 0
/var/tmp/filebits:
total 0
-rwsr-xr-x 1 33333 33333 0 Feb 17 21:28 setuid
-rwxrwxrwx 1 33333 33333 0 Feb 17 21:28 sevens
---------- 1 33333 33333 0 Feb 17 21:28 zeroes

@aledbf
Copy link
Member

aledbf commented Mar 30, 2021

@shaal please check #3636

@shaal
Copy link
Contributor Author

shaal commented Mar 30, 2021

@aledbf Unfortunately, I cannot test it until I get have access to a working build of that PR.
#3636 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants