0

I was performing some experiments in Docker and found a strange behaviour.

I was able to override the ownership of a file created with the root user inside the Docker with another user without root permissions.

Below are the steps to reproduce it:

$> docker run -dit ubuntu:16.04 bash $> docker exec -it cont_id bash $> apt update && apt install -y vim $> useradd cp -m $> vim /home/cp/hello.txt # Write some text and save it $> su cp $> cd ~/ && ls -latr; # Will list hello.txt with user and group as root $> vim hello.txt # Write some text and try saving it normally which will fail. # Try saving it with `:wq!` 

Voila, it is saved and the user and group to which the file belongs also change to the new user.

I have done a terminal recording for this and the same is posted here.

2
  • 2
    Possible dup of How does vim steal root owned files Commented Jan 21, 2018 at 11:51
  • And so it seems that the file is replaced with a new one. On performing echo "sometext " >> /filePath, doesn't change the inode value. Vim does change the inode value every time. Thanks. Commented Jan 21, 2018 at 12:02

1 Answer 1

0

Indeed, this has nothing to do with the Docker. This is normal behaviour in vim where it will replace the file with a new one as the user, given, the user has full permission on a folder. The same cannot happen for a folder where the user doesn't have full permission.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.