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

Mounts and capabilities #507

Merged
merged 2 commits into from
Dec 3, 2020
Merged

Mounts and capabilities #507

merged 2 commits into from
Dec 3, 2020

Conversation

ChunyiLyu
Copy link
Contributor

@ChunyiLyu ChunyiLyu commented Nov 30, 2020

This fixes issue: https://github.com/rabbitmq/tanzu-cluster-operator/issues/20

Note to reviewers: remember to look at the commits in this PR and consider if they can be squashed

Summary Of Changes

  • always mount '/var/lib/rabbitmq/' before '/var/lib/rabbitmq/mnesia/' to avoid shadowing; popular open-sourced container runtimes like docker and containerD will sort mounts in alphabetical order to avoid this issue, but there's no guarantee that all container runtime would do so
  • update initContainer capabilities to be able to deploy successfully in cluster with ESXi runtime
  • Context on the capabilities: dropping all capabilities except CHOWN, DAC_OVERRIDE, and FOWNER. The first of these capabilities is necessary to change a file's owner, the second is necessary to permit chown to traverse directories to which root doesn't otherwise have access. FOWNER is required for chmod and chgrp

Strictly speaking DAC_OVERRIDE isn't necessary, only DAC_READ_SEARCH is, but as it's not included in the default set using it is slightly more complex. I don't think there's much practical benefit since by default the only process with any capabilities at all is the chown process (everything else runs as 472 and gets no capabilities at all).

Additional Context

  • to make sure that '/var/lib/rabbitmq/' always mounts before '/var/lib/rabbitmq/mnesia/', volumeMounts is handled as a special case if it's patched with override

Local Testing

unit, integration, and system tests have all passed

to avoid shadowing

- popular open-sourced container runtimes like docker and containerD
will sort mounts in alphabetical order to avoid this issue, but
there's no guarantee that all container runtime would do so
@ChunyiLyu ChunyiLyu requested a review from mkuratczyk November 30, 2020 16:36
Copy link
Collaborator

@mkuratczyk mkuratczyk left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines 502 to 537
Drop: []corev1.Capability{"ALL"},
Add: []corev1.Capability{"CHOWN", "FOWNER"},
Drop: []corev1.Capability{
"FSETID",
"KILL",
"SETGID",
"SETUID",
"SETPCAP",
"NET_BIND_SERVICE",
"NET_RAW",
"SYS_CHROOT",
"MKNOD",
"AUDIT_WRITE",
"SETFCAP",
},
Copy link
Member

Choose a reason for hiding this comment

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

@coro proposed in #303 (comment) to drop all and only allow the needed capabilities.
Allow listing rather than deny listing is a better security standard.

IIRC the corresponding bug in the ESXi runtime will be fixed soon.
@Zerpet was discovering that issue and was in touch with that team.

Copy link
Contributor Author

@ChunyiLyu ChunyiLyu Dec 1, 2020

Choose a reason for hiding this comment

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

As I said in standup, I am aware of this fix: https://gitlab.eng.vmware.com/core-build/spherelet-agent/commit/31b0f133d2fca969b4e561d8f05a26b1f08dd498.

However, It's unclear to me when this fix can be released and how often does user upgrade while using these environments with spherelet. As long as we are dropping all known unneeded capabilities, I don't see much difference of security protection between the two different approaches. In addition to that, this is only the security context for our initContainer, which is ephemeral and not long running. IMO we should merge this update to make sure that our operator works with spherelet before GA. Thoughts? @mkuratczyk @coro

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, I thought the bug mentioned in standup was a different one. My bad.
In that case, let's merge this PR as is and revert this change in the future once the fix is rolled out?

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to add a comment like // Remove default capabilities allowed by Docker except for CHOWN and FOWNER. Otherwise, it's hard to read what capabilities the container will run with.

Comment on lines 502 to 537
Drop: []corev1.Capability{"ALL"},
Add: []corev1.Capability{"CHOWN", "FOWNER"},
Drop: []corev1.Capability{
"FSETID",
"KILL",
"SETGID",
"SETUID",
"SETPCAP",
"NET_BIND_SERVICE",
"NET_RAW",
"SYS_CHROOT",
"MKNOD",
"AUDIT_WRITE",
"SETFCAP",
},
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to add a comment like // Remove default capabilities allowed by Docker except for CHOWN and FOWNER. Otherwise, it's hard to read what capabilities the container will run with.

- previous configurations didn't work with ESXi runtime
- dropping all capabilities except CHOWN, DAC_OVERRIDE, and FOWNER
- CHOWN is necessary to change a file's
owner, the second is necessary to permit chown to traverse directories
to which root doesn't otherwise have access. FOWNER bypass checks on operations
that require the file system UID of the process to match the UID of the file.
@ChunyiLyu ChunyiLyu force-pushed the mounts-and-capabilities branch from 6c3e4e2 to 7549bfd Compare December 3, 2020 11:47
@ChunyiLyu ChunyiLyu merged commit 72ac2ff into main Dec 3, 2020
@ChunyiLyu ChunyiLyu deleted the mounts-and-capabilities branch December 3, 2020 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants