Skip to content

Commit e6c6667

Browse files
authored
Merge pull request containerd#159 from mikebrow/apparmor-feature
Adds support for AppArmor
2 parents 06548ae + c3e3ed5 commit e6c6667

File tree

131 files changed

+15796
-8051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+15796
-8051
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
- sudo apt-get install btrfs-tools
1515
- sudo apt-get install libseccomp2/trusty-backports
1616
- sudo apt-get install libseccomp-dev/trusty-backports
17+
- sudo apt-get install libapparmor-dev
1718
- sudo apt-get install socat
1819
- docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
1920

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ help:
4242
@echo " * 'clean' - Clean artifacts"
4343
@echo " * 'verify' - Execute the source code verification tools"
4444
@echo " * 'install.tools' - Install tools used by verify"
45-
@echo " * 'install.deps' - Install dependencies of cri-containerd (containerd, runc, cni)"
45+
@echo " * 'install.deps' - Install dependencies of cri-containerd (containerd, runc, cni) Note: BUILDTAGS defaults to 'seccomp apparmor' for runc build"
4646
@echo " * 'uninstall' - Remove installed binaries from system locations"
4747
@echo " * 'version' - Print current cri-containerd release version"
4848

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ will also do our best to update `cri-containerd` to the latest releases of these
2626
specifications as appropriate.
2727
### Install Dependencies
2828
1. Install runc dependencies.
29-
* runc requires installation of the libsecomp development library appropriate for your distribution. `libseccomp-dev` (Ubuntu, Debian) / `libseccomp-devel` (Fedora, CentOS, RHEL). On releases of Ubuntu <=Trusty and Debian <=jessie a backport version of
30-
`libsecomp-dev` is required. See [travis.yml](.travis.yml) for an example on
31-
trusty.
29+
* runc requires installation of the libsecomp development library appropriate
30+
for your distribution. `libseccomp-dev` (Ubuntu, Debian) / `libseccomp-devel`
31+
(Fedora, CentOS, RHEL). On releases of Ubuntu <=Trusty and Debian <=jessie a
32+
backport version of `libsecomp-dev` is required. See [travis.yml](.travis.yml)
33+
for an example on trusty. To use apparmor on Debian, Ubuntu, and related
34+
distributions runc requires the installation of `libapparmor-dev`.
3235
2. Install containerd dependencies.
3336
* containerd requires installation of a btrfs development library. `btrfs-tools`(Ubuntu, Debian) / `btrfs-progs-devel`(Fedora, CentOS, RHEL)
3437
3. Install other dependencies:

hack/install-deps.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ go get -d ${RUNC_PKG}/...
4141
cd ${GOPATH}/src/${RUNC_PKG}
4242
git fetch --all
4343
git checkout ${RUNC_VERSION}
44-
make
44+
BUILDTAGS=${BUILDTAGS:-seccomp apparmor}
45+
make BUILDTAGS="$BUILDTAGS"
4546
sudo make install
4647
which runc
4748

hack/test-e2e-node.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ source $(dirname "${BASH_SOURCE[0]}")/test-utils.sh
2020

2121
DEFAULT_SKIP="\[Flaky\]|\[Slow\]|\[Serial\]"
2222
DEFAULT_SKIP+="|querying\s\/stats\/summary"
23-
DEFAULT_SKIP+="|AppArmor"
2423
DEFAULT_SKIP+="|pull\sfrom\sprivate\sregistry\swith\ssecret"
2524

2625
# FOCUS focuses the test to run.

hack/versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
RUNC_VERSION=e775f0fba3ea329b8b766451c892c41a3d49594d
22
CNI_VERSION=v0.6.0
3-
CONTAINERD_VERSION=f05281743e5ac9ad11c6e19a72be7a903eab79f5
3+
CONTAINERD_VERSION=c1c2aafffec89aefaff2ba80b81be2277b2903dd
44
CRITEST_VERSION=d452f7fe9ef7ccc5ec63a8306cf838510cb83441
5-
KUBERNETES_VERSION=493ee8b28560c118cebd2165ba9ef0959cfa2bc3
5+
KUBERNETES_VERSION=aa9417ce910a7f508c9e8575263c2b280343a704

pkg/server/container_create.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/containerd/containerd"
25+
"github.com/containerd/containerd/contrib/apparmor"
2526
"github.com/golang/glog"
2627
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2728
"github.com/opencontainers/runc/libcontainer/devices"
@@ -37,6 +38,17 @@ import (
3738
"github.com/kubernetes-incubator/cri-containerd/pkg/util"
3839
)
3940

41+
const (
42+
// profileNamePrefix is the prefix for loading profiles on a localhost. Eg. AppArmor localhost/profileName.
43+
profileNamePrefix = "localhost/" // TODO (mikebrow): get localhost/ & runtime/default from CRI kubernetes/kubernetes#51747
44+
// runtimeDefault indicates that we should use or create a runtime default apparmor profile.
45+
runtimeDefault = "runtime/default"
46+
// appArmorDefaultProfileName is name to use when creating a default apparmor profile.
47+
appArmorDefaultProfileName = "cri-containerd.apparmor.d"
48+
// appArmorEnabled is a flag for globally enabling/disabling apparmor profiles for containers.
49+
appArmorEnabled = true // TODO (mikebrow): make these apparmor defaults configurable
50+
)
51+
4052
// CreateContainer creates a new container in the given PodSandbox.
4153
func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (_ *runtime.CreateContainerResponse, retErr error) {
4254
config := r.GetConfig()
@@ -156,6 +168,23 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
156168
if username := config.GetLinux().GetSecurityContext().GetRunAsUsername(); username != "" {
157169
specOpts = append(specOpts, containerd.WithUsername(username))
158170
}
171+
// Set apparmor profile, (privileged or not) if apparmor is enabled
172+
if appArmorEnabled {
173+
appArmorProf := config.GetLinux().GetSecurityContext().GetApparmorProfile()
174+
switch appArmorProf {
175+
case runtimeDefault:
176+
// TODO (mikebrow): delete created apparmor default profile
177+
specOpts = append(specOpts, apparmor.WithDefaultProfile(appArmorDefaultProfileName))
178+
case "":
179+
// TODO (mikebrow): handle no apparmor profile case see kubernetes/kubernetes#51746
180+
default:
181+
// Require and Trim default profile name prefix
182+
if !strings.HasPrefix(appArmorProf, profileNamePrefix) {
183+
return nil, fmt.Errorf("invalid apparmor profile %q", appArmorProf)
184+
}
185+
specOpts = append(specOpts, apparmor.WithProfile(strings.TrimPrefix(appArmorProf, profileNamePrefix)))
186+
}
187+
}
159188
opts = append(opts,
160189
containerd.WithSpec(spec, specOpts...),
161190
containerd.WithRuntime(defaultRuntime, nil),
@@ -264,9 +293,7 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint3
264293
return nil, fmt.Errorf("failed to set capabilities %+v: %v",
265294
securityContext.GetCapabilities(), err)
266295
}
267-
268-
// TODO(random-liu): [P2] Add apparmor and seccomp.
269-
296+
// TODO(random-liu): [P2] Add seccomp not privileged only.
270297
}
271298

272299
g.SetProcessSelinuxLabel(processLabel)
@@ -275,7 +302,7 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint3
275302
// TODO: Figure out whether we should set no new privilege for sandbox container by default
276303
g.SetProcessNoNewPrivileges(securityContext.GetNoNewPrivs())
277304

278-
// TODO(random-liu): [P1] Set selinux options.
305+
// TODO(random-liu): [P1] Set selinux options (privileged or not).
279306

280307
g.SetRootReadonly(securityContext.GetReadonlyRootfs())
281308

pkg/server/sandbox_run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ func (c *criContainerdService) generateSandboxContainerSpec(id string, config *r
294294
g.AddLinuxSysctl(key, value)
295295
}
296296

297-
// TODO(random-liu): [P2] Set apparmor and seccomp from annotations.
297+
// TODO(random-liu): [P2] Set seccomp
298+
299+
// Note: LinuxSandboxSecurityContext does not currently provide an apparmor profile
298300

299301
g.SetLinuxResourcesCPUShares(uint64(defaultSandboxCPUshares))
300302
g.SetProcessOOMScoreAdj(int(defaultSandboxOOMAdj))

vendor.conf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ github.com/syndtr/gocapability e7cb7fa329f456b3855136a2642b197bad7366ba
4747
github.com/ugorji/go ded73eae5db7e7a0ef6f55aace87a2873c5d2b74
4848
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
4949
golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
50-
golang.org/x/sys 739734461d1c916b6c72a63d7efda2b27edb369f
50+
golang.org/x/sys b892924b68aa53038e8a55b255ee0d8391e8eec5
5151
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4
5252
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
5353
google.golang.org/grpc v1.3.0
5454
gopkg.in/inf.v0 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
5555
gopkg.in/yaml.v2 53feefa2559fb8dfa8d81baad31be332c97d6c77
56-
k8s.io/api c0bcfdc3597be1a899c9f0b4e3d1b2e023b5148f
57-
k8s.io/apimachinery dc1f89aff9a7509782bde3b68824c8043a3e58cc
58-
k8s.io/apiserver 149fc2228647cea28b0670c240ec582e985e8eda
59-
k8s.io/client-go 2103a0e46b61d837aca715a6da810783527a4974
60-
k8s.io/kubernetes 493ee8b28560c118cebd2165ba9ef0959cfa2bc3
56+
k8s.io/api f30e293246921de7f4ee46bb65b8762b2f890fc4
57+
k8s.io/apimachinery b166f81f5c4c88402ae23a0d0944c6ad08bffd3b
58+
k8s.io/apiserver b2a8ad67a002d27c8945573abb80b4be543f2a1f
59+
k8s.io/client-go db8228460e2de17f5d3a9a453f61dde0ba86545a
60+
k8s.io/kubernetes aa9417ce910a7f508c9e8575263c2b280343a704
6161
k8s.io/utils 1f5ba483856f60b34bb29864d4129a8065d1c83b
62+
k8s.io/kube-openapi 2fbf05e337e56c983d9df1220b9e67cf132a1669 https://github.com/kubernetes/kube-openapi.git

vendor/github.com/containerd/containerd/contrib/apparmor/apparmor.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)