-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
CNI file permissions based on CIS Benchmarks #8991
CNI file permissions based on CIS Benchmarks #8991
Conversation
/sem-approve |
Looks like a handful of tests failing in the CNI package with errors like these:
|
Just a small FYI missa-wndrvr will be away until Aug. 6 2024 but will address any comments upon his return. |
I can see the 5 test cases related to reading "10-calico.conflist" run by the function "runCniContainer" failing. Could I get some feedback or assistance on this? Is there a way to give permissions to that function to be able to read/write as the owner of the file since it's a temp file created for testing purposes? Also, for my own knowledge, why does it not have the necessary permissions to read the file since it was created in the test run? Does this unit test failure signify that it might affect other people's deployments or is it only related to how the test case was written? |
@missa-wndrvr sorry for the delay. My understanding is that the tests are running the calico-cni container, which writes a 10-calico.conflist file with the new permissions. It then attempts to open that file to check its contents are expected, but it unable to do so because the test container isn't running with the right user / group to read the file. Suspect that this is probably mostly a test harness artifact, although in theory in real clusters other agents on the node (i.e., container runtimes) do need to read this file so will need to have permissions to do so. |
Thanks for the reply @caseydavenport. I was able to deploy the Calico pods with the permission change on my system which was successful in which any resource that needed access to the file was able to get it (if they had the necessary permissions) How else would you suggest I test this to ensure it doesn't affect other agents in real clusters, so that we can verify that this might just be a test harness conflict? |
I don't think we can guarantee this, so will have to live with the risk (or keep the permissions as they are). To mitigate this, the thing to do is probably to look at the most popular container runtimes and kuberentes cluster installers to see how the runtimes are configured and if they will by default have permissions to access the CNI config file. I am not too worried about this aspect. We do need to get the tests passing, though. For that we probably need to adjust the group that the tests are running under such that the test code can read the generated configuration file. |
Please re-review |
/sem-approve |
@@ -268,7 +268,7 @@ PuB/TL+u2y+iQUyXxLy3 | |||
}) | |||
|
|||
It("Should parse and output a templated config", func() { | |||
err := runCniContainer(tempDir, true) | |||
err := runCniContainer(tempDir, true, "-u", "0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still seeing the same permissions error it seems.
I'm not sure that setting -u 0
is right.
The problem is that the install test runs as a binary on the host:
Lines 247 to 257 in f543e75
# We pre-build the test binary so that we can run it outside a container and allow it | |
# to interact with docker. | |
pkg/install/install.test: pkg/install/*.go | |
$(DOCKER_RUN) $(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \ | |
cd /go/src/$(PACKAGE_NAME) && \ | |
go test ./pkg/install -c --tags install_test -o ./pkg/install/install.test' | |
.PHONY: test-install-cni | |
## Test the install | |
test-install-cni: run-k8s-apiserver image pkg/install/install.test | |
cd pkg/install && CONTAINER_NAME=$(CNI_PLUGIN_IMAGE):latest-$(ARCH) CERTS_PATH=$(CERTS_PATH) ./install.test |
So, expectFileContents
isn't being run as a privileged user (which is desirable). We may need to consider other changes for this.
Perhaps we need to make the permissions used by install.go
configurable, so the test code can set it to something more permissive (but defaults to 600 for production clusters).
Thanks @missa-wndrvr ! |
@missa-wndrvr @caseydavenport can we take this PR in? We are also waiting for this patch |
/sem-approve |
Looks like the PR is failing code formatting checks - running
|
Thanks @caseydavenport for the quick response. @missa-wndrvr would you please push the change or if you need help I can do it as well? |
Hello @kashifest, sorry I got caught up with other things. Please go ahead, and thank you! |
Removing "merge-when-ready" label due to new commits |
/sem-approve |
Pushed a formatting fix. |
@caseydavenport the PR now shows that is has 214 commits ? |
@kashifest oh shoot. I must have messed up the merge! I'll fix it 😆 |
CNI-related CIS Benchmarks include: 1.1.9 Ensure that the Container Network Interface file permissions are set to 600 or more restrictive. Tests: - Running "make test" in cni-plugin directory successfully - Delpoying Calico-node and Calico-Kube-controllers pods successfully - Ensure /etc/cni/net.d/10-calico.conflist file permissions is set to 600
Testing if running the failed tasks as root would give permission to read the CNI config file.
Allow the configuration of the CNI config file's permission mode. This will satisfy the CNI file permissions set by CIS Benchmarks. Also, allowing the unit test code to read the config file with no restriction.
7deac09
to
bbd2919
Compare
Removing "merge-when-ready" label due to new commits |
/sem-approve |
thanks a lot @caseydavenport for the quick response. |
* CNI file permissions based on CIS Benchmarks CNI-related CIS Benchmarks include: 1.1.9 Ensure that the Container Network Interface file permissions are set to 600 or more restrictive. Tests: - Running "make test" in cni-plugin directory successfully - Delpoying Calico-node and Calico-Kube-controllers pods successfully - Ensure /etc/cni/net.d/10-calico.conflist file permissions is set to 600 * CNI file permissions based on CIS Benchmarks Testing if running the failed tasks as root would give permission to read the CNI config file. * Configurable CNI config file permission Allow the configuration of the CNI config file's permission mode. This will satisfy the CNI file permissions set by CIS Benchmarks. Also, allowing the unit test code to read the config file with no restriction. * Fix formatting --------- Co-authored-by: Casey Davenport <[email protected]>
CNI-related CIS Benchmarks include:
1.1.9 Ensure that the Container Network Interface file
permissions are set to 600 or more restrictive.
Tests:
Related issues/PRs
#7461
Todos
Release Note
Reminder for the reviewer
Make sure that this PR has the correct labels and milestone set.
Every PR needs one
docs-*
label.docs-pr-required
: This change requires a change to the documentation that has not been completed yet.docs-completed
: This change has all necessary documentation completed.docs-not-required
: This change has no user-facing impact and requires no docs.Every PR needs one
release-note-*
label.release-note-required
: This PR has user-facing changes. Most PRs should have this label.release-note-not-required
: This PR has no user-facing changes.Other optional labels:
cherry-pick-candidate
: This PR should be cherry-picked to an earlier release. For bug fixes only.needs-operator-pr
: This PR is related to install and requires a corresponding change to the operator.