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

subPath in volumeMount is not writable for non-root users #41638

Closed
thriqon opened this issue Feb 17, 2017 · 9 comments · Fixed by #43775
Closed

subPath in volumeMount is not writable for non-root users #41638

thriqon opened this issue Feb 17, 2017 · 9 comments · Fixed by #43775
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/storage Categorizes an issue or PR as relevant to SIG Storage.
Milestone

Comments

@thriqon
Copy link

thriqon commented Feb 17, 2017

Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): no

What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): subpath, emptyDir, mode, permissions


Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT

Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:57:25Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:52:34Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration: Bare metal, SSD, but also VMs
  • OS (e.g. from /etc/os-release): Debian GNU/Linux 8 (jessie)
  • Kernel (e.g. uname -a): 4.8.0-0.bpo.2-amd64
  • Install tools:
  • Others: Docker v1.12.6

What happened: When I mount an emptyDir volume using a subpath, I'm unable to write into it if my process is not running as root. When I leave out the subpath, I can.

What you expected to happen: I can write to the directory in both cases.

How to reproduce it (as minimally and precisely as possible):

kind: Pod
apiVersion: v1
metadata: { name: "test-modes" }
spec:
  volumes:
    - { name: "direct",  emptyDir: {}}
    - { name: "subpath", emptyDir: {}}
  securityContext:
    fsGroup: 100
    # games(35) is member in group users(100)
    runAsUser: 35
  containers:
    - image: alpine:latest
      name: show
      command: ["/bin/sh", "-c", "id && ls -dl /mnts/*"]
      volumeMounts:
        - name: "direct"
          mountPath: "/mnts/direct"
        - name: "subpath"
          mountPath: "/mnts/subpath"
          subPath: a/b/c

Output is:

uid=35(games) gid=35(games) groups=100(users)
drwxrwsrwx    2 root     users         4096 Feb 17 12:38 /mnts/direct
drwxr-sr-x    2 root     users         4096 Feb 17 12:38 /mnts/subpath

Anything else we need to know:

This issue is related to #39474. I know this is caused by the Docker daemon creating those directories on a bind mount. Nevertheless, I expect Kubernetes to abstract this away, since this behavior is neither documented nor IMHO intuitive.

@calebamiles calebamiles added kind/bug Categorizes issue or PR as related to a bug. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. labels Feb 17, 2017
@calebamiles
Copy link
Contributor

Could someone from @kubernetes/sig-node-bugs please take a look? Thanks!

cc: @kubernetes/sig-storage-bugs

@smarterclayton
Copy link
Contributor

@pmorie @kubernetes/sig-storage-misc

@calebamiles calebamiles modified the milestone: v1.6 Mar 8, 2017
@dchen1107 dchen1107 removed the sig/node Categorizes an issue or PR as relevant to SIG Node. label Mar 10, 2017
@dchen1107
Copy link
Member

cc/ @saad-ali

@pwittrock pwittrock removed this from the v1.6 milestone Mar 11, 2017
@calebamiles calebamiles added this to the v1.5 milestone Mar 14, 2017
@wongma7
Copy link
Contributor

wongma7 commented Mar 28, 2017

attempted fix created here #43775

k8s-github-robot pushed a commit that referenced this issue Mar 30, 2017
Automatic merge from submit-queue

Create subPaths and set their permissions like we do mountPaths

fixes #41638

If a subPath does not exist at the time MountVolume.Setup happens, SetVolumeOwnership will not have walked to the subPath and set appropriate permissions on it, leading to the above issue

So later, at makeMounts when we are parsing subPaths, let's create all subPaths and set their permissions according to how the parent mountPath looks.

```release-note
NONE
```
amisevsk added a commit to amisevsk/fabric8-online that referenced this issue Apr 10, 2017
Mount the PVC used for workspaces to the Che server
to allow the server to create directory that is mounted
in the workspace. This is necessary because directories
created by kubernetes when mounting a subpath are created
with root permissions and cannot be modified by a non-root
user.

See: kubernetes/kubernetes#41638

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/fabric8-online that referenced this issue Apr 11, 2017
Mount the PVC used for workspaces to the Che server
to allow the server to create directory that is mounted
in the workspace. This is necessary because directories
created by kubernetes when mounting a subpath are created
with root permissions and cannot be modified by a non-root
user.

See: kubernetes/kubernetes#41638

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
@wongma7
Copy link
Contributor

wongma7 commented Apr 21, 2017

I created a cherrypick PR for 1.6 here: #44782 since this bug is against 1.6. Could someone (who agrees this could be cherrypicked) please add the cherrypick-candidate label + milestone to the original PR #43775, thank you!

edit: sorry, it's against 1.5. Should it be cherrypicked back to that as well?

@rakeshvanga
Copy link

I'm still facing this issue with Kubernetes version 1.12.8 on a AKS cluster when I mount a Azure Storage as azureFile share.
Did anyone know if the issue is fixed for all types of mounts and not only just the emptyDir?

@alegmal
Copy link

alegmal commented Apr 20, 2020

same issue on GCP @ k8s 1.14

@ronaldpetty
Copy link

k8s 1.17 via eks as well

@Saksow
Copy link

Saksow commented Mar 31, 2021

So what's the recommendation? Not using subPath?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/storage Categorizes an issue or PR as relevant to SIG Storage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants