Warn if kernel does not support overlay with selinux
| ... | ... |
@@ -3,6 +3,7 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "bufio" |
|
| 6 | 7 |
"bytes" |
| 7 | 8 |
"fmt" |
| 8 | 9 |
"io/ioutil" |
| ... | ... |
@@ -647,11 +648,56 @@ func configureMaxThreads(config *Config) error {
|
| 647 | 647 |
return nil |
| 648 | 648 |
} |
| 649 | 649 |
|
| 650 |
+func overlaySupportsSelinux() (bool, error) {
|
|
| 651 |
+ f, err := os.Open("/proc/kallsyms")
|
|
| 652 |
+ if err != nil {
|
|
| 653 |
+ if os.IsNotExist(err) {
|
|
| 654 |
+ return false, nil |
|
| 655 |
+ } |
|
| 656 |
+ return false, err |
|
| 657 |
+ } |
|
| 658 |
+ defer f.Close() |
|
| 659 |
+ |
|
| 660 |
+ var symAddr, symType, symName, text string |
|
| 661 |
+ |
|
| 662 |
+ s := bufio.NewScanner(f) |
|
| 663 |
+ for s.Scan() {
|
|
| 664 |
+ if err := s.Err(); err != nil {
|
|
| 665 |
+ return false, err |
|
| 666 |
+ } |
|
| 667 |
+ |
|
| 668 |
+ text = s.Text() |
|
| 669 |
+ if _, err := fmt.Sscanf(text, "%s %s %s", &symAddr, &symType, &symName); err != nil {
|
|
| 670 |
+ return false, fmt.Errorf("Scanning '%s' failed: %s", text, err)
|
|
| 671 |
+ } |
|
| 672 |
+ |
|
| 673 |
+ // Check for presence of symbol security_inode_copy_up. |
|
| 674 |
+ if symName == "security_inode_copy_up" {
|
|
| 675 |
+ return true, nil |
|
| 676 |
+ } |
|
| 677 |
+ } |
|
| 678 |
+ return false, nil |
|
| 679 |
+} |
|
| 680 |
+ |
|
| 650 | 681 |
// configureKernelSecuritySupport configures and validates security support for the kernel |
| 651 | 682 |
func configureKernelSecuritySupport(config *Config, driverName string) error {
|
| 652 | 683 |
if config.EnableSelinuxSupport {
|
| 653 | 684 |
if !selinuxEnabled() {
|
| 654 | 685 |
logrus.Warn("Docker could not enable SELinux on the host system")
|
| 686 |
+ return nil |
|
| 687 |
+ } |
|
| 688 |
+ |
|
| 689 |
+ if driverName == "overlay" || driverName == "overlay2" {
|
|
| 690 |
+ // If driver is overlay or overlay2, make sure kernel |
|
| 691 |
+ // supports selinux with overlay. |
|
| 692 |
+ supported, err := overlaySupportsSelinux() |
|
| 693 |
+ if err != nil {
|
|
| 694 |
+ return err |
|
| 695 |
+ } |
|
| 696 |
+ |
|
| 697 |
+ if !supported {
|
|
| 698 |
+ logrus.Warnf("SELinux is not supported with the %s graph driver on this kernel", driverName)
|
|
| 699 |
+ } |
|
| 655 | 700 |
} |
| 656 | 701 |
} else {
|
| 657 | 702 |
selinuxSetDisabled() |