Skip to content

Regression from chroot; service account cert left behind #45

Closed

Description

@jlebon
$ oc logs machine-config-daemon-4jf24
I0905 20:35:05.283801       1 start.go:42] Version: 0.0.0-106-ge7b9b06d
I0905 20:35:05.283899       1 client_builder.go:49] Using in-cluster kube client config
I0905 20:35:05.284150       1 start.go:66] chrooting into rootMount /rootfs
I0905 20:35:05.284164       1 start.go:72] moving to / inside the chroot
panic: open /var/run/secrets/kubernetes.io/serviceaccount/ca.crt: no such file or directory
goroutine 1 [running]:
github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1.NewForConfigOrDie(0xc4200f2e00, 0xc42032cfb0)
        /code/go/src/github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfiguration.openshift.io_client.go:59 +0x65
github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned.NewForConfigOrDie(0xc4200f2e00, 0x117d329)
        /code/go/src/github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/clientset.go:69 +0x49
github.com/openshift/machine-config-operator/cmd/common.(*ClientBuilder).MachineConfigClientOrDie(0xc42009a658, 0x117d329, 0x15, 0x0, 0x0)
        /code/go/src/github.com/openshift/machine-config-operator/cmd/common/client_builder.go:21 +0x50
main.runStartCmd(0x19da300, 0xc4202e6960, 0x0, 0x2)
        /code/go/src/github.com/openshift/machine-config-operator/cmd/machine-config-daemon/start.go:80 +0x3de
github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra.(*Command).execute(0x19da300, 0xc4202e68c0, 0x2, 0x2, 0x19da300, 0xc4202e68c0)
        /code/go/src/github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra/command.go:766 +0x2c1
github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x19da0a0, 0x0, 0xc4200e1f78, 0x403dfc)
        /code/go/src/github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra/command.go:852 +0x30a
github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra.(*Command).Execute(0x19da0a0, 0xc4200e1f60, 0x0)
        /code/go/src/github.com/openshift/machine-config-operator/vendor/github.com/spf13/cobra/command.go:800 +0x2b
main.main()
        /code/go/src/github.com/openshift/machine-config-operator/cmd/machine-config-daemon/main.go:27 +0x31

Looks like we need to copy the cert before we chroot.

Though this raises the higher level question of how much will chroot() affect how well we mesh with Kubernetes. (How common is it to do an early chroot() on the main process in Kube containers?)

Activity

  1. jlebon commented on Sep 5, 2018

    @jlebon
    MemberAuthor

    This is a bit late, though looking at the original threads that spawned this change (#17 and #24), ISTM like the main reason for doing an early chroot was to work around the symlink-over-bind-mount issue, right?

    For systemd units specifically, could we not use the systemd D-Bus API directly? And then if the need comes up otherwise to resolve symlinks, we can just do one-off chroot invocations instead? This is also closer to how Ignition itself works, i.e. only chrooting when it needs to; and given that we're handling Ignition configs here too, I suspect we should be able to also do without an early chroot, right? (Again, I should've brought this up earlier during those discussions, sorry!)

  2. sdemos commented on Sep 5, 2018

    @sdemos
    Contributor

    (How common is it to do an early chroot() on the main process in Kube containers?)

    I have to guess that it's not common at all.

    For systemd units specifically, could we not use the systemd D-Bus API directly? And then if the need comes up otherwise to resolve symlinks, we can just do one-off chroot invocations instead?

    Another possible solution would be to chroot after getting all the info we need from kubernetes, and right before the files and units are evaluated. Not sure which is better. Are there semantic differences between a manual symlink and calling the dbus api?

    /cc @ashcrow @lucab since they were also part of the precipitating discussion on this topic.

  3. lucab commented on Sep 6, 2018

    @lucab

    I'll try to answer all the questions to the best of my knowledge.

    Looks like we need to copy the cert before we chroot.

    If I understood this suggestion correctly, I fear this would clone k8s objects and leak them to the host filesystem. That seems to introduce lifecycle/GC and confidentiality concerns to me.

    How common is it to do an early chroot() on the main process in Kube containers

    I've never seen this. On the other hand many software are just plainly broken when doing path-resolution over a rootfs bind-mount, because they were not designed to run in a container (e.g. kubelet, node-exporter), so I wouldn't take this as a useful datapoint.

    main reason for doing an early chroot was to work around the symlink-over-bind-mount issue, right?

    Yes. The general topic is "symlinks/path resolution over a rootfs bind-mounts".

    For systemd units specifically, could we not use the systemd D-Bus API directly?

    Likely yes, for the specific case where you have a D-Bus API to perform the change you need.

    And then if the need comes up otherwise to resolve symlinks, we can just do one-off chroot invocations instead?

    You don't know beforehand if you need to "resolve symlinks". Every time you open/stat a file, its path could be crossing a number of absolute/relative symlinks; those targets are not aware of your bind-mount prefix. Also, chroot is process-wide so it will also affect other running goroutines (if any).

    I suspect we should be able to also do without an early chroot, right

    Likely yes, but this is a daemon design point so it should take into account what the rest of the process is doing in parallel, otherwise the same problem will exist as a race.
    Also, ignition is not a heavy-parallel and long-running process and doesn't consume many external configuration files, so it is probably not a good design reference here.

    Another possible solution would be to chroot after getting all the info we need from kubernetes

    Same as above, in order for this to work you need to guarantee that nothing else in your program is trying to do file accesses while you are chrooted.
    I didn't check if that happens in practice, but some lazy-loading that come to mind could be around k8s config/token (e.g. if there are inotify watches for updated file), TLS CA bundle (which is read from container /etc, but I don't know at which point), procfs (e.g. if anything is trying to introspect or gather metric on the process itself, mount table, etc.).

  4. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member

    For systemd units specifically, could we not use the systemd D-Bus API directly?

    Likely yes, for the specific case where you have a D-Bus API to perform the change you need.

    It is possible with the right mounts. But keep in mind that the MCD also drops files in different locations. We would still need to chroot (or something similar).

    Another possible solution would be to chroot after getting all the info we need from kubernetes

    Same as above, in order for this to work you need to guarantee that nothing else in your program is trying to do file accesses while you are chrooted.
    I didn't check if that happens in practice, but some lazy-loading that come to mind could be around k8s config/token (e.g. if there are inotify watches for updated file), TLS CA bundle (which is read from container /etc, but I don't know at which point), procfs (e.g. if anything is trying to introspect or gather metric on the process itself, mount table, etc.).

    I'm more in favor of this path as long as we verify @lucab's notes.

  5. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member

    /assign ashcrow

  6. jlebon commented on Sep 6, 2018

    @jlebon
    MemberAuthor

    You don't know beforehand if you need to "resolve symlinks". Every time you open/stat a file, its path could be crossing a number of absolute/relative symlinks; those targets are not aware of your bind-mount prefix. Also, chroot is process-wide so it will also affect other running goroutines (if any).

    My argument was that Ignition is also subject to this, but it has managed fine (or did this bite some users?). Of course the difference is that at the time Ignition runs, there's no live system running under /sysroot; it's just a plain partition mount and so the state of the disk is in a much more controlled state. So overall, I do agree that the analogy doesn't apply.

  7. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member

    @jlebon can you verify #46 fixed this and close this issue if so?

  8. sdemos commented on Sep 6, 2018

    @sdemos
    Contributor

    @ashcrow did you also investigate the effects of this on possible kubernetes lazy-loading and other problems that @lucab brought up in his comment? I didn't see any followups and I'm curious what the outcome was on how this change effects that.

  9. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member

    @sdemos I didn't dive into the kubernetes client code to see if it was doing anything fancy to reload itself on file changes. I can do so though. I took @lucab's note more as a 'it's a possibility that something does something fancy' though I may have misunderstood.

  10. sdemos commented on Sep 6, 2018

    @sdemos
    Contributor

    I was just wondering because you mentioned it as something to verify but I didn't see anything and was curious.

  11. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member

    @sdemos fair point. I'm taking a gander now :-)

  12. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member
    • A quick skim through of the client code shows that the config is loaded and then used. I don't see any inotify or other reloading
    • The cert loading is now happening before we chroot
    • There is reference to /proc in apimachinery/pkg/util/net/interface.go which is used in transport/round_trippers.go, transport/cache.go, rest/request.go, and kubernetes/typed/core/v1/service_expansion.go. I'll check these locations and report back.
  13. ashcrow commented on Sep 6, 2018

    @ashcrow
    Member
    • transport/round_trippers.go uses CloneRequest which isn't using mounts
    • transport/cache.go uses SetTransportDefaults which isn't using mounts
    • rest/requests.go uses IsProbableEOF, IsConnectionReset, neither of which use mounts
    • kubernetes/typed/core/v1/service_expansion.go uses JoinSchemeNamePort which does not use mounts

    Of course I can't promise this will always be the case, or that I didn't miss a call which calls a call which calls a 🐢 🐢 🐢 ... :-)

  14. sdemos commented on Sep 18, 2018

    @sdemos
    Contributor

    this was fixed in #46.

    I don't have a close button though, which seems like a silly restriction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions