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

Add "--selinux-enabled" flag for Docker #9334

Merged
merged 4 commits into from
Jun 16, 2020

Conversation

hakman
Copy link
Member

@hakman hakman commented Jun 11, 2020

https://success.docker.com/article/how-to-set-selinux-file-contexts-when-using-a-custom-docker-data-root

I don't thin the current solution does what is expected based on the Docker docs: https://docs.docker.com/engine/reference/commandline/dockerd/#docker-runtime-execution-options

This PR should work better for the desired use case. On my ubuntu box I see this message:

Jun 11 10:21:46 ip-10-4-211-22 dockerd[4928]: time="2020-06-11T10:21:46.664002518Z"
level=warning msg="Docker could not enable SELinux on the host system"

Ref: kubernetes/test-infra#17902

/cc @bertinatto @rifelpet

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. area/api labels Jun 11, 2020
@hakman
Copy link
Member Author

hakman commented Jun 11, 2020

I also set the default log level to "info" as it was already in docs. It is not very verbose, but should help us track various issues easier in testing.

// LogLevel is the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
LogLevel *string `json:"logLevel,omitempty" flag:"log-level"`

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 11, 2020
@bertinatto
Copy link
Member

bertinatto commented Jun 11, 2020

On my ubuntu box I see this message:

Jun 11 10:21:46 ip-10-4-211-22 dockerd[4928]: time="2020-06-11T10:21:46.664002518Z"
level=warning msg="Docker could not enable SELinux on the host system"

Just to confirm, is SELinux installed and enabled in your Ubuntu box? It's not installed by default in Ubuntu, and apparently the package migh be broken: https://wiki.ubuntu.com/SELinux

The --selinux-enabled docker flag will only work if SELinux is enabled on the host. I'm not sure about Ubuntu, but it works as expected in my Fedora box (using upstream docker):

$ sudo setenforce 1
$ mkdir /tmp/blah

$ ps aux | ag dockerd
root      189228  0.3  0.2 1608692 90776 ?       Ssl  12:59   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --selinux-enabled
fbertina  190176  0.0  0.0   3384  1844 pts/1    S+   13:02   0:00 ag dockerd

(notice the --selinux-enabled above)

$ docker run --rm -it -v /tmp/blah:/tmp/blah centos bash -c "ls -lZ /tmp/blah"
ls: cannot open directory '/tmp/blah': Permission denied

(SELinux blocked the access)

$ sudo vim /usr/lib/systemd/system/docker.service

(removed --selinux-enabled)

$ sudo systemctl daemon-reload && sudo systemctl restart docker 

$ ps aux | ag dockerd
root      190552  7.6  0.2 1460972 84044 ?       Ssl  13:07   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
fbertina  190723  0.0  0.0   3384  1956 pts/1    S+   13:07   0:00 ag dockerd

$ docker run --rm -it -v /tmp/blah:/tmp/blah centos bash -c "ls -lZ /tmp/blah"
total 0

$ docker version
Client: Docker Engine - Community
 Version:           19.03.11
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        42e35e61f3
 Built:             Mon Jun  1 09:14:45 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.11
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       42e35e61f3
  Built:            Mon Jun  1 09:12:44 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

@bertinatto
Copy link
Member

Jun 11 10:21:46 ip-10-4-211-22 dockerd[4928]: time="2020-06-11T10:21:46.664002518Z"
level=warning msg="Docker could not enable SELinux on the host system"

Apparently this message was returned because it failed this check:

https://github.com/moby/moby/blob/3aac5f0bbb5ccaeb9081ef710aae2459cbc87fa7/daemon/daemon_unix.go#L867

Which leads to this code, that verifies that SELinux was not enabled on the host (it looks for selinuxfs mount in /proc/filesystems:

https://github.com/opencontainers/selinux/blob/b5f337853c0fbc29cf112ade767460c33a64d938/go-selinux/selinux_linux.go#L134

@hakman
Copy link
Member Author

hakman commented Jun 11, 2020

The point of the message was to show that the flag is applied. A bit harder to enable SELinux on Ubuntu, I guess.

@hakman
Copy link
Member Author

hakman commented Jun 11, 2020

Doesn't seem to work to well on a CentOS 7 box either:

Jun 11 11:58:37 ip-10-4-211-152.eu-central-1.compute.internal dockerd[897]: time="2020-06-11T11:58:37.517424146Z" level=error
msg="Handler for POST /v1.40/containers/77b8d55b2714ea9e170c61ea09ac8bdae9b892ef9048c6eabff02876a8f75d4a
start returned error: OCI runtime create failed: selinux label is specified in config, but selinux is disabled or not supported: unknown"

@hakman
Copy link
Member Author

hakman commented Jun 11, 2020

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 11, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2020
@hakman
Copy link
Member Author

hakman commented Jun 12, 2020

Tracked down the previous error to an incompatibility between Docker and containerd and will be fixed in a separate PR.
This is ready for review.
/hold cancel

Copy link
Member

@bertinatto bertinatto left a comment

Choose a reason for hiding this comment

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

Thank you @hakman!

I'm not familiar with the code base, but I reviewed the changes and they LGTM.

@rifelpet
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 16, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hakman, rifelpet

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

The pull request process is described here

Needs approval from an approver in each of these files:

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2020
@hakman
Copy link
Member Author

hakman commented Jun 16, 2020

@bertinatto you should update the test to use this flag instead.
Once #9346 or some other solution is accepted, SELinux should start working.

@k8s-ci-robot k8s-ci-robot merged commit 2a73c9d into kubernetes:master Jun 16, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jun 16, 2020
@hakman hakman deleted the docker-selinux branch July 1, 2020 03:12
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. area/api cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants