|
| 1 | +// +build linux |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright The containerd Authors. |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package apparmor |
| 20 | + |
| 21 | +import ( |
| 22 | + "io/ioutil" |
| 23 | + "os" |
| 24 | + "sync" |
| 25 | +) |
| 26 | + |
| 27 | +var ( |
| 28 | + appArmorSupported bool |
| 29 | + checkAppArmor sync.Once |
| 30 | +) |
| 31 | + |
| 32 | +// hostSupports returns true if apparmor is enabled for the host, if |
| 33 | +// apparmor_parser is enabled, and if we are not running docker-in-docker. |
| 34 | +// |
| 35 | +// It is a modified version of libcontainer/apparmor.IsEnabled(), which does not |
| 36 | +// check for apparmor_parser to be present, or if we're running docker-in-docker. |
| 37 | +func hostSupports() bool { |
| 38 | + checkAppArmor.Do(func() { |
| 39 | + // see https://github.com/docker/docker/commit/de191e86321f7d3136ff42ff75826b8107399497 |
| 40 | + if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" { |
| 41 | + if _, err = os.Stat("/sbin/apparmor_parser"); err == nil { |
| 42 | + buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") |
| 43 | + appArmorSupported = err == nil && len(buf) > 1 && buf[0] == 'Y' |
| 44 | + } |
| 45 | + } |
| 46 | + }) |
| 47 | + return appArmorSupported |
| 48 | +} |
0 commit comments