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

proposal for file permission handling in projected service account volume #1598

Merged
merged 1 commit into from
Apr 15, 2020

Conversation

zshihang
Copy link
Contributor

@zshihang zshihang commented Mar 6, 2020

Motivation:

currently the mode of projected service account volume is 0600 effectively 0400, which may not work in pods with non-root containers. see kubernetes/kubernetes#74565.

Proposal:

  • Case 1: The pod has an fsGroup set. We can set the file permission on the
    token file to 0600 and let the fsGroup mechanism work as designed. It will
    set the permissions to 0640, chown the token file to the fsGroup and start
    the containers with a supplemental group that grants them access to the
    token file. This works today.
  • Case 2: The pod’s containers declare the same runAsUser for all containers
    in the pod. We chown the token file to the pod’s runAsUser to grant the
    containers access to the token.
  • Fallback: We set the file permissions to world readable (0644) to match the
    behavior of secrets.

Ref: kubernetes/kubernetes#70679
Ref: #542

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 6, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @zshihang. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 6, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 6, 2020
@k8s-ci-robot k8s-ci-robot added kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/storage Categorizes an issue or PR as relevant to SIG Storage. labels Mar 6, 2020
@zshihang
Copy link
Contributor Author

zshihang commented Mar 6, 2020

/cc @mikedanese
/cc @liggitt

@zshihang zshihang closed this Mar 6, 2020
@zshihang zshihang reopened this Mar 6, 2020
@zshihang zshihang force-pushed the permission branch 3 times, most recently from 313a588 to 1f17ed9 Compare March 10, 2020 00:18
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 10, 2020
@zshihang
Copy link
Contributor Author

/assign @saad-ali


UserID can be obtained by the following three ways:
1. `runAsUser` in `SecurityContext`
2. fetch UserID from image status
Copy link
Member

@liggitt liggitt Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all images pulled and present by the time we need to create the volume for mounting and choose a file mode (including volumes we would need to create for initContainers)?

also, can the preferred uid/gid for an image change over the life of a pod if a container image is changed in the pod spec or is restarted/repulled?

Copy link
Contributor Author

@zshihang zshihang Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, all volumes are mounted before SyncPod is called in kuberuntime manager. this proposal will not work without alternation on the existing abstraction of kuberuntime manager and volume manager.

good point. the uid/gid will not change if a new image with different uid/gid is pulled. this will be an issue for uid but not for gid because the user in the new image will be added to the gid. to work around this changing uid issue, we have to change the ownership each pulling, which requires implementing a SetOwnership method without remounting. talked to @saad-ali about the implications of this method: 1. "the operation is recursive and can take many many minutes to complete for volumes with lots of files and directories." 2. some files might be used by containers while being updated with new permissions.

the complexity of solving both issues is high when introducing the uid in images. ideally in this case we have to push container runtime side to add a functionality to set ownership of volume mounts. see moby/moby#2259. then we can set ownership uid-wise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the recursive SetOwnership is a concern for this particularly case. It's only problematic for very large volumes with lots of files. But changing permissions of files while they're in use is a concern.

1. same as the proposal except for creating a different volume for a different
user ID instead of setting GroupID ownership.
+ projected service account token is a pod level resource
+ scalability issue. # of volumes = # of user IDs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we reuse the same token (to avoid a renewal loop per container), is the scale we'd hit at up to one volume per container problematic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the data in cache in the kubelet so this is purely scalability of kubelet volume management. IMO the major downside of this approach is implementation complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, besides the implementation complexity of managing volumes for different uids, i'd also like the unix primitive idea of group.

@mikedanese
Copy link
Member

@msau42 @gnufied any more comments on this?

@msau42
Copy link
Member

msau42 commented Apr 9, 2020

I am fine limiting the scope to projected service account volumes for now, and revisiting other ephemeral volumes as a future enhancement.

@@ -159,6 +161,55 @@ sources:
audience: ca.istio.io
```

### File Permission
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know how/if this interacts with SELinux?

@gnufied @jsafrane

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELinux labels on files are orthogonal to UID/GIDs and are set by the container runtime when pods start.
#1621 tries to change it, still, it's separate from file owners and permissions.

@mikedanese
Copy link
Member

From sig-auth.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 15, 2020
@msau42
Copy link
Member

msau42 commented Apr 15, 2020

/lgtm
/approve
from sig-storage

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mikedanese, msau42, zshihang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 15, 2020
@k8s-ci-robot k8s-ci-robot merged commit ba41363 into kubernetes:master Apr 15, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Apr 15, 2020
@hasheddan
Copy link

@zshihang @mikedanese has there been any documentation added to k/website for this behavior? I would be happy to add some if not :)

@zshihang
Copy link
Contributor Author

zshihang commented Jun 2, 2020

feel free to do so.

RomanBednar pushed a commit to RomanBednar/enhancements that referenced this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.