Skip to content

Commit

Permalink
buildkit: Apply apparmor profile
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 authored and Tibor Vass committed Jan 28, 2021
1 parent 4afe620 commit 611eb6f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions builder/builder-next/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Opt struct {
Rootless bool
IdentityMapping *idtools.IdentityMapping
DNSConfig config.DNSConfig
ApparmorProfile string
}

// Builder can build using BuildKit backend
Expand Down
2 changes: 1 addition & 1 deletion builder/builder-next/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {

dns := getDNSConfig(opt.DNSConfig)

exec, err := newExecutor(root, opt.DefaultCgroupParent, opt.NetworkController, dns, opt.Rootless, opt.IdentityMapping)
exec, err := newExecutor(root, opt.DefaultCgroupParent, opt.NetworkController, dns, opt.Rootless, opt.IdentityMapping, opt.ApparmorProfile)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion builder/builder-next/executor_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const networkName = "bridge"

func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dnsConfig *oci.DNSConfig, rootless bool, idmap *idtools.IdentityMapping) (executor.Executor, error) {
func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dnsConfig *oci.DNSConfig, rootless bool, idmap *idtools.IdentityMapping, apparmorProfile string) (executor.Executor, error) {
networkProviders := map[pb.NetMode]network.Provider{
pb.NetMode_UNSET: &bridgeProvider{NetworkController: net, Root: filepath.Join(root, "net")},
pb.NetMode_HOST: network.NewHostProvider(),
Expand All @@ -38,6 +38,7 @@ func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dn
NoPivot: os.Getenv("DOCKER_RAMDISK") != "",
IdentityMapping: idmap,
DNS: dnsConfig,
ApparmorProfile: apparmorProfile,
}, networkProviders)
}

Expand Down
2 changes: 1 addition & 1 deletion builder/builder-next/executor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/moby/buildkit/executor/oci"
)

func newExecutor(_, _ string, _ libnetwork.NetworkController, _ *oci.DNSConfig, _ bool, _ *idtools.IdentityMapping) (executor.Executor, error) {
func newExecutor(_, _ string, _ libnetwork.NetworkController, _ *oci.DNSConfig, _ bool, _ *idtools.IdentityMapping, _ string) (executor.Executor, error) {
return &winExecutor{}, nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func newRouterOptions(config *config.Config, d *daemon.Daemon) (routerOptions, e
Rootless: d.Rootless(),
IdentityMapping: d.IdentityMapping(),
DNSConfig: config.DNSConfig,
ApparmorProfile: daemon.DefaultApparmorProfile(),
})
if err != nil {
return opts, err
Expand Down
8 changes: 8 additions & 0 deletions daemon/apparmor_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const (
defaultAppArmorProfile = "docker-default"
)

// DefaultApparmorProfile returns the name of the default apparmor profile
func DefaultApparmorProfile() string {
if apparmor.IsEnabled() {
return defaultAppArmorProfile
}
return ""
}

func ensureDefaultAppArmorProfile() error {
if apparmor.IsEnabled() {
loaded, err := aaprofile.IsLoaded(defaultAppArmorProfile)
Expand Down
5 changes: 5 additions & 0 deletions daemon/apparmor_default_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ package daemon // import "github.com/docker/docker/daemon"
func ensureDefaultAppArmorProfile() error {
return nil
}

// DefaultApparmorProfile returns an empty string.
func DefaultApparmorProfile() string {
return ""
}

0 comments on commit 611eb6f

Please sign in to comment.