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

Allow kubelet_t to create a sock file kubelet_var_lib_t #329

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Sep 16, 2024

No description provided.

Copy link

We were not able to find or create Copr project packit/containers-container-selinux-329 specified in the config with the following error:

Packit received HTTP 500 Internal Server Error from Copr Service. Check the Copr status page: https://copr.fedorainfracloud.org/status/stats/, or ask for help in Fedora Build System matrix channel: https://matrix.to/#/#buildsys:fedoraproject.org.

Unless the HTTP status code above is >= 500, please check your configuration for:

  1. typos in owner and project name (groups need to be prefixed with @)
  2. whether the project name doesn't contain not allowed characters (only letters, digits, underscores, dashes and dots must be used)
  3. whether the project itself exists (Packit creates projects only in its own namespace)
  4. whether Packit is allowed to build in your Copr project
  5. whether your Copr project/group is not private

@rhatdan
Copy link
Member Author

rhatdan commented Sep 16, 2024

@lsm5 ANy idea what is blowing up with rpm-builds?

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link

Tests failed. @containers/packit-build please check.

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link

Tests failed. @containers/packit-build please check.

@Tal-or
Copy link

Tal-or commented Sep 17, 2024

@rhatdan After testing it locally on my nodes I got the following error under the pods:

  Warning  Failed          8s                 kubelet            Error: container create failed: time="2024-09-17T21:56:46Z" level=error msg="runc create failed: unable to start container process: error during container init: write /proc/self/attr/keycreate: invalid argument"

The pods are running with the kubelet_var_lib_t context
However maybe I was doing something wrong while testing it.
This is how I tested it:

  1. cloned the branch with the changes
  2. make
  3. convert the container.pp to container.cil
  4. copying all the rules that are dealing with kubelet_var_lib_t to the existing container.cil on my system
  5. installing the modified container.cil with sudo semodule -i container.cil

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

My bad it the pod was suppose to be running as container_device_plugin_t.
So I did.
But the pod resources API socket is still created as container_var_lib_t

But as I said in my previous comment, maybe i'm testing it wrong because I didn't manage to build the package and fully load it on my system.

@lsm5
Copy link
Member

lsm5 commented Sep 18, 2024

My bad it the pod was suppose to be running as container_device_plugin_t. So I did. But the pod resources API socket is still created as container_var_lib_t

But as I said in my previous comment, maybe i'm testing it wrong because I didn't manage to build the package and fully load it on my system.

@Tal-or would you be able to install the package built in the CI copr jobs. See https://copr.fedorainfracloud.org/coprs/packit/containers-container-selinux-329/build/8024924/

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

My bad it the pod was suppose to be running as container_device_plugin_t. So I did. But the pod resources API socket is still created as container_var_lib_t
But as I said in my previous comment, maybe i'm testing it wrong because I didn't manage to build the package and fully load it on my system.

@Tal-or would you be able to install the package built in the CI copr jobs. See https://copr.fedorainfracloud.org/coprs/packit/containers-container-selinux-329/build/8024924/

Thank you @lsm5 are those builds compatible with RHCOS ?

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

Thank you @lsm5 I managed to install the package, using: https://download.copr.fedorainfracloud.org/results/packit/containers-container-selinux-329/epel-9-x86_64/08024926-container-selinux/

@rhatdan We're still having an issue with transitioning the socket from container_var_lib_t to kubelet_var_lib_t:

[root@cnfdf08 kubelet]# ls -Z pod-resources/
system_u:object_r:container_var_lib_t:s0 kubelet.sock

If i'm running restorecon the file gets the correct label.

This are the rules I extracted from the cil file:

(typetransition kubelet_t container_var_lib_t sock_file "kubelet.sock" kubelet_var_lib_t)
(typetransition kubelet_t var_lib_t sock_file "kubelet.sock" kubelet_var_lib_t)

@rhatdan
Copy link
Member Author

rhatdan commented Sep 18, 2024

Can you remove the kubelet.sock and restart the service to see if it gets created with the wrong label?

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

Can you remove the kubelet.sock and restart the service to see if it gets created with the wrong label?

It does created with the wrong label. I checked that.

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

[root@cnfdf08 kubelet]# systemctl stop kubelet
[root@cnfdf08 kubelet]# rm -rf pod-resources
[root@cnfdf08 kubelet]# systemctl start kubelet
[root@cnfdf08 kubelet]# ls -Z pod-resources/
system_u:object_r:container_var_lib_t:s0 kubelet.sock

@Tal-or
Copy link

Tal-or commented Sep 18, 2024

I think I found a way:
we should replace:

filetrans_pattern(kubelet_t, container_var_lib_t, kubelet_var_lib_t, sock_file, "kubelet.sock")

with

filetrans_pattern(kubelet_t, container_var_lib_t, kubelet_var_lib_t, dir, "pod-resources")

this transition works and kubelet.sock will inherent kubelet_var_lib_t type from its parent directory i.e pod-resources.
There are no other files in the pod-resources directory so no other files will be affected.

We want to allow container_device_plugin_t to communicate
with kublet_t over a kubelet_var_lib_t socket.

Signed-off-by: Daniel J Walsh <[email protected]>
@Tal-or
Copy link

Tal-or commented Sep 19, 2024

@rhatdan I tested and verified locally on my system and it works as expected.
From my POV we can merge this PR. Thank you very much

@rhatdan rhatdan merged commit 4550c12 into containers:main Sep 19, 2024
14 checks passed
Tal-or added a commit to k8stopologyawareschedwg/deployer that referenced this pull request Sep 24, 2024
Tal-or added a commit to k8stopologyawareschedwg/deployer that referenced this pull request Sep 24, 2024
podresources API context has changed to kubelet_var_lib_t:
 containers/container-selinux#329

Adjust the custom policy to allow access to this new file context.

Signed-off-by: Talor Itzhak <[email protected]>
Tal-or added a commit to k8stopologyawareschedwg/deployer that referenced this pull request Sep 25, 2024
podresources API context has changed to kubelet_var_lib_t:
 containers/container-selinux#329

Adjust the custom policy to allow access to this new file context.

Signed-off-by: Talor Itzhak <[email protected]>
Tal-or added a commit to k8stopologyawareschedwg/deployer that referenced this pull request Sep 25, 2024
podresources API context has changed to kubelet_var_lib_t:
 containers/container-selinux#329

Adjust the custom policy to allow access to this new file context.

Signed-off-by: Talor Itzhak <[email protected]>
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