Skip to content

selinux configs and volume for microshift-containerized - #457

Merged
husky-parul merged 2 commits into
openshift:mainfrom
husky-parul:containerized
Jan 20, 2022
Merged

selinux configs and volume for microshift-containerized#457
husky-parul merged 2 commits into
openshift:mainfrom
husky-parul:containerized

Conversation

@husky-parul

@husky-parul husky-parul commented Nov 15, 2021

Copy link
Copy Markdown
Contributor

Signed-off-by: Parul Singh parsingh@redhat.com

Which issue(s) this PR addresses:
For podman deployment:

  • systemd unit file for starting and managing microshift-containerized.

Closes #434, #433, #432

@openshift-ci
openshift-ci Bot requested review from copejon and rootfs November 15, 2021 19:56
@husky-parul husky-parul added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 15, 2021
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 15, 2021
@husky-parul
husky-parul marked this pull request as draft November 15, 2021 20:33
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 15, 2021
@husky-parul

Copy link
Copy Markdown
Contributor Author

podman systemd file was created out of following command.

sudo podman run --sdnotify=container --label io.containers.autoupdate=registry  --network=host --privileged -d \
            --rm --name microshift \
            -v /var/run/crio/crio.sock:/var/run/crio/crio.sock:rw,rshared \
            -v microshift-data:/var/lib/microshift:rw,rshared \
            -v /var/lib/kubelet:/var/lib/kubelet:rw,rshared \
            -v /var/log:/var/log \
            -e KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig \
            quay.io/microshift/microshift:latest

The volumes mounted are:

-v /var/run/crio/crio.sock:/var/run/crio/crio.sock:rw,rshared \
-v microshift-data:/var/lib/microshift:rw,rshared \
-v /var/lib/kubelet:/var/lib/kubelet:rw,rshared \
-v /var/log:/var/log \

packaging/systemd/microshift-containerized created /var/lib/microshift that gets mounted as microshift-data volume.
packaging/systemd/microshift-containerized-configure-selinux configure selinux policies. Both scripts are run in ExecStartPre

@husky-parul

Copy link
Copy Markdown
Contributor Author

@rootfs @oglok how are these two secrets created? openshift-ingress/router-certs-default and openshift-dns/dns-default-metrics-tls

microshift-containerized is behaving differently (with same selinux configurations) when mounting host-dir vs host-vol

When a host-vol microshift-data is used, pods openshift-dns/dns-default-b5kwm andopenshift-ingress/router-default-6c96f6bc66-4hnf9are failing because secrets openshift-ingress/router-certs-default and openshift-dns/dns-default-metrics-tls are not present in the respective namespaces.
(however, they are present in the name space when host-dir )

so

sudo podman run --sdnotify=container --label io.containers.autoupdate=registry  --network=host --privileged -d \
            --rm --name microshift \
            -v /var/run/crio/crio.sock:/var/run/crio/crio.sock:rw,rshared \
            -v /var/lib/microshift:/var/lib/microshift:rw,rshared \
            -v /var/lib/kubelet:/var/lib/kubelet:rw,rshared \
            -v /var/log:/var/log \
            -e KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig \
            quay.io/microshift/microshift:latest

But this doesn't

sudo podman run --sdnotify=container --label io.containers.autoupdate=registry  --network=host --privileged -d \
            --rm --name microshift \
            -v /var/run/crio/crio.sock:/var/run/crio/crio.sock:rw,rshared \
            -v /var/lib/containers:/var/lib/containers:rw,rshared \
            -v microshift-data:/var/lib/microshift:rw,rshared \
            -v /var/lib/kubelet:/var/lib/kubelet:rw,rshared \
            -v /var/log:/var/log \
            -e KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig \
            quay.io/microshift/microshift:latest

The only difference is host-dir vs host-vol

@cooktheryan

Copy link
Copy Markdown
Contributor

A little more information. There are some subtle differences in the mounts when doing podman inspect microshift

standard directory mount

"/var/lib/microshift:/var/lib/microshift:rw,rshared,rbind",

podman volume

"microshift-data:/var/lib/microshift:rw,rshared,nosuid,nodev,rbind",

@husky-parul

Copy link
Copy Markdown
Contributor Author

I have narrowed down to the serving secrets dns-default-metrics-tls
and router-certs-default are not created by services dns-default and router-internal-default respectively in podman named volume deployment. Same behavior with selinux on/off. The filesystem, permissions and labels are identical for both host-dir and host-vol.

@husky-parul

husky-parul commented Nov 24, 2021

Copy link
Copy Markdown
Contributor Author
cat /run/crun/*/config.json | jq . > /tmp/config_dir.json  # using podman host_dir mount
cat /run/crun/*/config.json | jq . > /tmp/config_vol.json  # using podman named volume mount

diff --color -Naur /tmp/config_dir.json /tmp/config_vol.json 
--- /tmp/config_dir.json        2021-11-24 13:01:39.314831482 -0500
+++ /tmp/config_vol.json        2021-11-24 13:10:36.436976929 -0500
@@ -207,21 +207,11 @@
     "oomScoreAdj": 0
   },
   "root": {
-    "path": "/var/lib/containers/storage/overlay/a9f020ec061f95a33276a901f419e9e97f0d70db8ac1be5984726f5c55393cb8/merged"
+    "path": "/var/lib/containers/storage/overlay/9e08a7c709dca5c09d54c57682dd9890e7510409e75ece238b94647b11dbdc59/merged"
   },
   "hostname": "fedora.local.com",
   "mounts": [
     {
-      "destination": "/proc",
-      "type": "proc",
-      "source": "proc",
-      "options": [
-        "nosuid",
-        "noexec",
-        "nodev"
-      ]
-    },
-    {
       "destination": "/sys",
       "type": "sysfs",
       "source": "sysfs",
@@ -234,6 +224,16 @@
       ]
     },
     {
+      "destination": "/proc",
+      "type": "proc",
+      "source": "proc",
+      "options": [
+        "nosuid",
+        "noexec",
+        "nodev"
+      ]
+    },
+    {
       "destination": "/dev",
       "type": "tmpfs",
       "source": "tmpfs",
@@ -245,28 +245,18 @@
       ]
     },
     {
-      "destination": "/run/.containerenv",
+      "destination": "/etc/resolv.conf",
       "type": "bind",
-      "source": "/run/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/.containerenv",
+      "source": "/run/containers/storage/overlay-containers/09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08/userdata/resolv.conf",
       "options": [
         "bind",
         "rprivate"
       ]
     },
     {
-      "destination": "/var/log",
-      "type": "bind",
-      "source": "/var/log",
-      "options": [
-        "rw",
-        "rprivate",
-        "rbind"
-      ]
-    },
-    {
       "destination": "/dev/shm",
       "type": "bind",
-      "source": "/var/lib/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/shm",
+      "source": "/dev/shm",
       "options": [
         "bind",
         "rprivate"
@@ -296,9 +286,19 @@
       ]
     },
     {
+      "destination": "/var/log",
+      "type": "bind",
+      "source": "/var/log",
+      "options": [
+        "rw",
+        "rprivate",
+        "rbind"
+      ]
+    },
+    {
       "destination": "/etc/hostname",
       "type": "bind",
-      "source": "/run/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/hostname",
+      "source": "/run/containers/storage/overlay-containers/09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08/userdata/hostname",
       "options": [
         "bind",
         "rprivate"
@@ -307,25 +307,25 @@
     {
       "destination": "/etc/hosts",
       "type": "bind",
-      "source": "/run/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/hosts",
+      "source": "/run/containers/storage/overlay-containers/09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08/userdata/hosts",
       "options": [
         "bind",
         "rprivate"
       ]
     },
     {
-      "destination": "/run/secrets",
+      "destination": "/run/.containerenv",
       "type": "bind",
-      "source": "/run/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/run/secrets",
+      "source": "/run/containers/storage/overlay-containers/09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08/userdata/.containerenv",
       "options": [
         "bind",
         "rprivate"
       ]
     },
     {
-      "destination": "/etc/resolv.conf",
+      "destination": "/run/secrets",
       "type": "bind",
-      "source": "/run/containers/storage/overlay-containers/25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043/userdata/resolv.conf",
+      "source": "/run/containers/storage/overlay-containers/09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08/userdata/run/secrets",
       "options": [
         "bind",
         "rprivate"
@@ -345,19 +345,21 @@
       ]
     },
     {
-      "destination": "/var/lib/kubelet",
+      "destination": "/var/lib/microshift",
       "type": "bind",
-      "source": "/var/lib/kubelet",
+      "source": "/var/lib/containers/storage/volumes/microshift-data/_data",
       "options": [
         "rw",
         "rshared",
+        "nosuid",
+        "nodev",
         "rbind"
       ]
     },
     {
-      "destination": "/var/lib/microshift",
+      "destination": "/var/lib/kubelet",
       "type": "bind",
-      "source": "/var/lib/microshift",
+      "source": "/var/lib/kubelet",
       "options": [
         "rw",
         "rshared",
@@ -379,7 +381,7 @@
   ],
   "annotations": {
     "io.container.manager": "libpod",
-    "io.kubernetes.cri-o.Created": "2021-11-24T12:58:30.125590012-05:00",
+    "io.kubernetes.cri-o.Created": "2021-11-24T13:08:06.096394928-05:00",
     "io.kubernetes.cri-o.TTY": "false",
     "io.podman.annotations.autoremove": "TRUE",
     "io.podman.annotations.init": "FALSE",
@@ -399,15 +401,12 @@
         "limit": 2048
       }
     },
-    "cgroupsPath": "machine.slice:libpod:25ec623774d9071640cf64a913b59819f01f91ac0e13b1ce60ab1629e731a043",
+    "cgroupsPath": "machine.slice:libpod:09428ba251ee0e1677a9ba689265f2b6350992a219b3188b0e27ca7a8c550d08",
     "namespaces": [
       {
         "type": "pid"
       },
       {
-        "type": "ipc"
-      },
-      {
         "type": "uts"
       },
       {
[root@fedora ~]# 

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
ExecStartPre=/bin/bash /usr/bin/microshift-containerized-configure-selinux # not autogenerated
ExecStartPre=/bin/bash /usr/bin/microshift-containerized-configure-selinux # not autogenerated

We should not do this, it's a lengthy process. ( installing, compiling, etc...)

Let's assume that people will download the rpms for microshift via dnf, which will include both microshift-containerized + the selinux modules compiled.

We can keep the script available just in case.

Suggested change
ExecStartPre=/bin/bash /usr/bin/microshift-containerized-configure-selinux # not autogenerated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still has

-v /var/lib/microshift:/var/lib/microshift:rw,rshared
right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. We are going ahead with /var/lib/microshift:/var/lib/microshift:rw,rshared instead of microshift-data:/var/lib/microshift:rw,rshared

Comment thread packaging/systemd/microshift-containerized-configure-selinux Outdated

@mangelajo mangelajo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

see comments.

@husky-parul husky-parul added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Dec 1, 2021
@husky-parul
husky-parul marked this pull request as ready for review December 1, 2021 18:12
@husky-parul
husky-parul requested a review from mangelajo December 1, 2021 18:12
@husky-parul

Copy link
Copy Markdown
Contributor Author

@mangelajo Ready for review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we fold this file completely into the microshift-containerized.service, such that the UX is like we document in https://microshift.io/docs/getting-started/ ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this file still needed / up-to-date?

If we're running containerized, only the crio.sock should be bind-mounted from the host (plus the /var/lib/microshift datadir if we're using hostdir instead of voliumes). So why do we still need to create these other dirs and adjust SELinux policies?

@husky-parul husky-parul Dec 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need to adjust the selinux anymore. From @mangelajo comment
"Let's assume that people will download the rpms for microshift via dnf, which will include both microshift-containerized + the selinux modules compiled."
.It was based on the assumption that the users didn't download the rpms and would be only using the microshift-containerized.service. I will remove the files as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait... I think we're confusing deployment models here:
The containerised deployment is for users who want to deploy MIcroShift at runtime on top of a R4E container host. That is, they cannot dynamically install an .RPM (that would need to be baked into the rpm-ostree).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, they can't dynamically install it, but if you want to bake it, then we need it also to be in the RPM?.

In any case I don't think we should be running make for the selinux files on installation, or downloading seliux-policy-devel etc... in that case we should probably provide the selinux compiled policy, if that's standard across kernel versions, which I don't know.

May be the container itself should be built by installing the RPM we have?, then the user just downloads the .service file? Can we install an selinux policy from inside a privileged container?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to this, can’t just people install an rpm? We made a subpackage for the microshift container service which will also pull the selinux defs: https://developers.redhat.com/blog/2020/03/12/how-to-customize-fedora-coreos-for-dedicated-workloads-with-ostree

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I meant is we have two deployment models:

  1. The .rpm-based installation, which is for embedding into rpm-ostrees and runs MicroShift as binary on the host / non-containerized. We have corresponding SELinux rules for that.
  2. The containerized deployment, which is for users who don't want to embed into an rpm-ostree but instead use a container host and add/remove MicroShift at runtime - without reboot. This is where it doesn't make sense to install the sytemd unit via an .rpm. Instead, it'll need to be created via configuration management resp. from the application management agent.

@copejon

copejon commented Dec 1, 2021

Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 1, 2021
@husky-parul

Copy link
Copy Markdown
Contributor Author

@fzdarsky consolidated everything in microshift-containerized.service
needs ok to test

@husky-parul
husky-parul requested a review from fzdarsky December 6, 2021 18:43
@husky-parul husky-parul added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 6, 2021
@cooktheryan

Copy link
Copy Markdown
Contributor

/retest

3 similar comments
@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@cooktheryan

Copy link
Copy Markdown
Contributor

/retest

@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@fzdarsky

Copy link
Copy Markdown
Contributor

@cooktheryan From what I gathered from the community meeting, the systemd file is not supposed to do anything except for starting and managing the lifecycle so I am moving the mkdir -p /var/libe/kubelet to docs.

@husky-parul I think having this in the ExecStartPre instead of the doc is fine as it's part of the pre-reqs for starting.
Anyway, let's get this merged and possibly add in a follow-up?

/lgtm

@openshift-ci openshift-ci Bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 18, 2022
Signed-off-by: Parul <parsingh@redhat.com>
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 18, 2022
Signed-off-by: Parul <parsingh@redhat.com>
@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@fzdarsky

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jan 18, 2022
@fzdarsky

Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 18, 2022
@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

5 similar comments
@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@cooktheryan

Copy link
Copy Markdown
Contributor

/retest

@husky-parul

Copy link
Copy Markdown
Contributor Author

/retest

@cooktheryan

Copy link
Copy Markdown
Contributor

/LGTM

@openshift-ci

openshift-ci Bot commented Jan 20, 2022

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cooktheryan, fzdarsky

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [cooktheryan,fzdarsky]

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

@cooktheryan

Copy link
Copy Markdown
Contributor

Woot woot!!!!!

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. lgtm 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] setup selinux and env before starting microshift container via systemd

5 participants