Skip to content

permission denied if chown after chmod #6047

@snarlysodboxer

Description

@snarlysodboxer

This runs, it gives a 0 Exit status:

FROM ubuntu:trusty

RUN adduser --disabled-password --gecos "" davidamick
RUN mkdir /home/davidamick/testDir
RUN echo "hello world" > /home/davidamick/testDir/testFile

###
RUN chown -R davidamick. /home/davidamick
RUN chmod 700 /home/davidamick/testDir
RUN chmod 600 /home/davidamick/testDir/testFile
###

USER davidamick
ENTRYPOINT ["/bin/bash"]
CMD ["-l", "-c", "touch /home/davidamick/testDir/testFile"]

However if I simply change the chown command to be just after the chmod commands like this:

FROM ubuntu:trusty

RUN adduser --disabled-password --gecos "" davidamick
RUN mkdir /home/davidamick/testDir
RUN echo "hello world" > /home/davidamick/testDir/testFile

###
RUN chmod 700 /home/davidamick/testDir
RUN chmod 600 /home/davidamick/testDir/testFile
RUN chown -R davidamick. /home/davidamick
###

USER davidamick
ENTRYPOINT ["/bin/bash"]
CMD ["-l", "-c", "touch /home/davidamick/testDir/testFile"]

then running it fails with:

touch: cannot touch '/home/davidamick/testDir/testFile': Permission denied

I have confirmed the this with several other things too, for example changing the command like so:

CMD ["-l", "-c", "ls -ahlR /home/davidamick/testDir"]

as well as just running bash interactively and manually attempting to touch/list the files that were chown-ed.
It also does not seem to be related to bash or the environment (that I know of,) since I discovered this issue while doing this:

FROM ubuntu:trusty

RUN apt-get update && apt-get install -y ssh
RUN mkdir /var/run/sshd

RUN adduser --disabled-password --gecos "" davidamick
ADD my_pubkey /home/davidamick/.ssh/authorized_keys

###
RUN chmod 700 /home/davidamick/.ssh
RUN chmod 600 /home/davidamick/.ssh/authorized_keys
RUN chown -R davidamick. /home/davidamick
###

ENTRYPOINT ["/usr/sbin/sshd"]
CMD ["-d"]

which produced the sshd debug error:

debug1: Could not open authorized keys '/home/davidamick/.ssh/authorized_keys': Permission denied

and all it took for it to start working was to move the chown command above the chmod commands.

Is this a bug or am I missing something here? Thanks all.

UPDATE: with my host info:
Ubuntu 12.04

uname -a
Linux my-hostname 3.8.0-39-generic #58~precise1-Ubuntu SMP Fri May 2 21:33:40 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
docker version
Client version: 0.11.0
Client API version: 1.11
Go version (client): go1.2.1
Git commit (client): 15209c3
Server version: 0.11.0
Server API version: 1.11
Git commit (server): 15209c3
Go version (server): go1.2.1
Last stable version: 0.11.1, please update docker
docker info
Containers: 76
Images: 364
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Dirs: 516
Execution Driver: native-0.2
Kernel Version: 3.8.0-39-generic
WARNING: No swap limit support

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions