origin icon indicating copy to clipboard operation
origin copied to clipboard

Is there a way to force an ownership id on a directoy created by VolumeMount SubPath

Open fortinj66 opened this issue 9 years ago • 22 comments

I am trying to use SubPath on an NFS PVC. The subpath was created fine, but the owner:group assigned was root:root. I would have expected the owner to be the run as user. Is there a way to set the owner during creation?

Also, permissions are set as 755 rather than 775 so I can't user directory sticky bit write access either...

Version

oc version oc v1.5.1 kubernetes v1.5.2+43a9be4 features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://os-master-d01:8443 openshift v1.5.1 kubernetes v1.5.2+43a9be4

fortinj66 avatar Oct 09 '17 18:10 fortinj66

I think that more information would be useful, so people will be able to help you quicker.

How do you define your pod? By which SCC a pod was admitted? You can get this information by inspecting a pod with oc get pod <pod> -o yaml

the owner:group assigned was root:root. I would have expected the owner to be the run as user.

Looks like a pod was admitted by privileged or anyuid SCC, otherwise it wouldn't run as root user.

Also, have you seen our recommendations about using NFS and supplementalGroups? In case you missed it, here are the links: https://docs.openshift.org/latest/install_config/persistent_storage/persistent_storage_nfs.html#nfs-supplemental-groups and https://docs.openshift.org/latest/install_config/persistent_storage/pod_security_context.html#supplemental-groups

php-coder avatar Oct 10 '17 15:10 php-coder

@pweil- Who can help with storage related issues?

php-coder avatar Oct 10 '17 15:10 php-coder

@openshift/sig-storage

pweil- avatar Oct 10 '17 15:10 pweil-

@php-coder

sigh... unfortunately, for many reasons I have no control over, the pods have to run as anyuid. Internally the images run with UID 1000...

    openshift.io/deployment-config.latest-version: "2"
    openshift.io/deployment-config.name: jef-test-micro
    openshift.io/deployment.name: jef-test-micro-2
    openshift.io/generated-by: OpenShiftWebConsole
    openshift.io/scc: anyuid

[johnf@os-master-d01 ~]$ oc rsh jef-test-micro-2-0rvcd id
uid=1000(appuser) gid=1000(appuser)
[johnf@os-master-d01 ~]$

I've looked at the supplemental group information, but since the permissions on the new directory get set to 755, the group doesn't have write access. Plus since the group owner is root I would have to allow gid 0 as the supplemental group... Setting the sticky bit has the same issue in terms of permissions...

fortinj66 avatar Oct 10 '17 16:10 fortinj66

I want to try a non-anyuid scc. I have created a new scc uid1000 with the idea that it will force the pods to run as the indicated id (and maybe assign the correct permissions to the subpath).

NAME      PRIV      CAPS      SELINUX     RUNASUSER   FSGROUP    SUPGROUP   PRIORITY   READONLYROOTFS   VOLUMES
uid1000   false     []        MustRunAs   MustRunAs   RunAsAny   RunAsAny   10         false            [configMap downwardAPI emptyDir gitRepo persistentVolumeClaim secret]

How do I assign the UID in the deployment configuration/template? This is one of the areas where I feel the documentation is a little light on examples...

fortinj66 avatar Oct 10 '17 17:10 fortinj66

I have created a new scc uid1000

I see that SCC has priority 10 and anyuid AFAIR has the same priority. If service account have access to both of them, then most likely anyuid will be used (see more about prioritization: https://docs.openshift.org/latest/architecture/additional_concepts/authorization.html#scc-prioritization)

I suggest to set priority 15 for uid1000 SCC.

How do I assign the UID in the deployment configuration/template?

You should edit deployment config (oc edit dc/<name>) and specify securityContext.runAsUser parameter for a container: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container

php-coder avatar Oct 10 '17 17:10 php-coder

I found that and added it... I'm getting closer...

Error creating: pods "jef-test-4-4-" is forbidden: unable to validate against any security context constraint: [securityContext.runAsUser: Invalid value: 1000: UID on container jef-test-4 does not match required range. Found 1000, required min: 1000060000 max: 1000069999]

fortinj66 avatar Oct 10 '17 17:10 fortinj66

I found it. It's in the namespace/project definition...

So even with runAsUser set, the permissions are incorrect with the subpath:

~/logs $ pwd                                                                                                                                                                                                                                         
/home/appuser/logs                                                                                                                                                                                                                                   

~/logs $ df .                                                                                                                                                                                                                                        
Filesystem           1K-blocks      Used Available Use% Mounted on                                                                                                                                                                                   
filesrv01:/root_vdm_1/os_dev_logs/os_dev_logs/dev-jef-test-4                                                                                                                                                                                         
                      10325760    106528  10219232   1% /home/appuser/logs                                                                                                                                                                           

~/logs $ ls -al                                                                                                                                                                                                                                      
total 8                                                                                                                                                                                                                                              
drwxr-sr-x    2 root     appuser         80 Oct 10 13:53 .                                                                                                                                                                                           
drwxr-sr-x    6 appuser  appuser        191 Oct 10 13:53 ..                                                                                                                                                                                          
-rw-r--r--    1 root     appuser       4422 Oct 10 13:53 .index.php    

~/logs $ id                                                                                                                                                                                                                                          
uid=1000(appuser) gid=1000(appuser) groups=1000060000                                                                                                                                                                                                

fortinj66 avatar Oct 10 '17 17:10 fortinj66

please try supplementalgroups. it should: modify the directory to have 775 perms, change the owner to the supplemental group, and add the supplemental group to the container's group memberships.

there was a bug where supplementalgroups would work for mountPaths but not subPaths but it should have been backported to 3.5

wongma7 avatar Oct 10 '17 19:10 wongma7

I'll give that a try... Thanks!

fortinj66 avatar Oct 10 '17 19:10 fortinj66

with supplemental groups you can also specify a range for other pods that the deployment config boots up.

On Tue, Oct 10, 2017 at 1:30 PM, John Fortin [email protected] wrote:

I'll give that a try... Thanks!

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/16757#issuecomment-335582276, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLTZw_n3wpFkSMkf7tW1pbvBzhDg4p4ks5sq8XdgaJpZM4Py6Jl .

erinboyd avatar Oct 10 '17 20:10 erinboyd

oh, and you have to set in the SCC 'supplemental groups' to 'MustRunAsRange' in that scenario.

On Tue, Oct 10, 2017 at 2:13 PM, Erin Boyd [email protected] wrote:

with supplemental groups you can also specify a range for other pods that the deployment config boots up.

On Tue, Oct 10, 2017 at 1:30 PM, John Fortin [email protected] wrote:

I'll give that a try... Thanks!

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/16757#issuecomment-335582276, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLTZw_n3wpFkSMkf7tW1pbvBzhDg4p4ks5sq8XdgaJpZM4Py6Jl .

erinboyd avatar Oct 10 '17 20:10 erinboyd

https://docs.openshift.org/latest/install_config/persistent_storage/pod_security_context.html

On Tue, Oct 10, 2017 at 2:14 PM, Erin Boyd [email protected] wrote:

oh, and you have to set in the SCC 'supplemental groups' to 'MustRunAsRange' in that scenario.

On Tue, Oct 10, 2017 at 2:13 PM, Erin Boyd [email protected] wrote:

with supplemental groups you can also specify a range for other pods that the deployment config boots up.

On Tue, Oct 10, 2017 at 1:30 PM, John Fortin [email protected] wrote:

I'll give that a try... Thanks!

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/16757#issuecomment-335582276, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLTZw_n3wpFkSMkf7tW1pbvBzhDg4p4ks5sq8XdgaJpZM4Py6Jl .

erinboyd avatar Oct 10 '17 20:10 erinboyd

For some reason the pods are not getting the correct scc.

When I assign to uid1000 the scc in the pod becomes restricted. When I assign anyuid to default the scc in the pod becomes anyuid...

fortinj66 avatar Oct 10 '17 20:10 fortinj66

After getting the scc correct and setting supplemental groups I get the following permissions on the created directory:

drwxr-xr-x. 2 root root 80 Oct 10 17:19 dev-jef-test-7

I was hoping for:

drwxrwxr-x. 2 root 1000 80 Oct 10 17:19 dev-jef-test-7

So that doesn't seem to have worked...

      openshift.io/deployment-config.latest-version: "13"
      openshift.io/deployment-config.name: jef-test-7
      openshift.io/deployment.name: jef-test-7-13
      openshift.io/generated-by: OpenShiftWebConsole
      openshift.io/scc: uid1000
...
     securityContext:
        capabilities:
          drop:
          - MKNOD
          - SYS_CHROOT
        privileged: false
        runAsUser: 1000
        seLinuxOptions:
          level: s0:c8,c2
...
    securityContext:
      fsGroup: 1000
      seLinuxOptions:
        level: s0:c8,c2
      supplementalGroups:
      - 1000
    serviceAccount: default

fortinj66 avatar Oct 10 '17 21:10 fortinj66

are the permissions on the mountPath correct at least? if so then this version probably doesn't have the subpath fix backported to it, I don't remember the exact version unfortunately.

wongma7 avatar Oct 10 '17 21:10 wongma7

Would the fix be in Origin 3.6?

Sent from my iPhone

On Oct 10, 2017, at 5:35 PM, Matthew Wong [email protected] wrote:

are the permissions on the mountPath correct at least? if so then this version probably doesn't have the subpath fix backported to it, I don't remember the exact version unfortunately.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fortinj66 avatar Oct 10 '17 21:10 fortinj66

Yes, just checked.

On Tue, Oct 10, 2017 at 5:57 PM John Fortin [email protected] wrote:

Would the fix be in Origin 3.6?

Sent from my iPhone

On Oct 10, 2017, at 5:35 PM, Matthew Wong [email protected] wrote:

are the permissions on the mountPath correct at least? if so then this version probably doesn't have the subpath fix backported to it, I don't remember the exact version unfortunately.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/16757#issuecomment-335620432, or mute the thread https://github.com/notifications/unsubscribe-auth/AMgP-EbXeTRQk3h4bdCjJjaFn7DczLHgks5sq-gugaJpZM4Py6Jl .

wongma7 avatar Oct 18 '17 16:10 wongma7

Awesome! Thanks!

Sent from my iPhone

On Oct 18, 2017, at 12:24 PM, Matthew Wong [email protected] wrote:

Yes, just checked.

On Tue, Oct 10, 2017 at 5:57 PM John Fortin [email protected] wrote:

Would the fix be in Origin 3.6?

Sent from my iPhone

On Oct 10, 2017, at 5:35 PM, Matthew Wong [email protected] wrote:

are the permissions on the mountPath correct at least? if so then this version probably doesn't have the subpath fix backported to it, I don't remember the exact version unfortunately.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/openshift/origin/issues/16757#issuecomment-335620432, or mute the thread https://github.com/notifications/unsubscribe-auth/AMgP-EbXeTRQk3h4bdCjJjaFn7DczLHgks5sq-gugaJpZM4Py6Jl .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

fortinj66 avatar Oct 18 '17 16:10 fortinj66

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot avatar Feb 23 '18 11:02 openshift-bot