-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
275 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package apparmor | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
ECSDefaultProfileName = "ecs-default" | ||
appArmorProfileDir = "/etc/apparmor.d" | ||
) | ||
|
||
const ecsDefaultProfile = ` | ||
#include <tunables/global> | ||
profile ecs-default flags=(attach_disconnected,mediate_deleted) { | ||
#include <abstractions/base> | ||
network, | ||
capability, | ||
file, | ||
umount, | ||
# Host (privileged) processes may send signals to container processes. | ||
signal (receive) peer=unconfined, | ||
# Container processes may send signals amongst themselves. | ||
signal (send,receive) peer=ecs-default, | ||
# ECS agent requires DBUS send | ||
dbus (send) bus=system, | ||
deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir) | ||
# deny write to files not in /proc/<number>/** or /proc/sys/** | ||
deny @{PROC}/{[^1-9],[^1-9][^0-9],[^1-9s][^0-9y][^0-9s],[^1-9][^0-9][^0-9][^0-9/]*}/** w, | ||
deny @{PROC}/sys/[^k]** w, # deny /proc/sys except /proc/sys/k* (effectively /proc/sys/kernel) | ||
deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w, # deny everything except shm* in /proc/sys/kernel/ | ||
deny @{PROC}/sysrq-trigger rwklx, | ||
deny @{PROC}/kcore rwklx, | ||
deny mount, | ||
deny /sys/[^f]*/** wklx, | ||
deny /sys/f[^s]*/** wklx, | ||
deny /sys/fs/[^c]*/** wklx, | ||
deny /sys/fs/c[^g]*/** wklx, | ||
deny /sys/fs/cg[^r]*/** wklx, | ||
deny /sys/firmware/** rwklx, | ||
deny /sys/kernel/security/** rwklx, | ||
# suppress ptrace denials when using 'docker ps' or using 'ps' inside a container | ||
ptrace (trace,read,tracedby,readby) peer=ecs-default, | ||
} | ||
` | ||
|
||
// LoadDefaultProfile ensures the default profile to be loaded with the given name. | ||
// Returns nil error if the profile is already loaded. | ||
func LoadDefaultProfile(profileName string) error { | ||
yes, err := isLoaded(profileName) | ||
if err != nil { | ||
return err | ||
} | ||
if yes { | ||
return nil | ||
} | ||
|
||
f, err := os.Create(filepath.Join(appArmorProfileDir, profileName)) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString(ecsDefaultProfile) | ||
if err != nil { | ||
return err | ||
} | ||
path := f.Name() | ||
|
||
if err := load(path); err != nil { | ||
return fmt.Errorf("load apparmor profile %s: %w", path, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright The docker Authors. | ||
Copyright The Moby Authors. | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package apparmor | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
exec "golang.org/x/sys/execabs" | ||
) | ||
|
||
// NOTE: This code is copied from <github.com/docker/docker/profiles/apparmor>. | ||
// If you plan to make any changes, please make sure they are also sent | ||
// upstream. | ||
|
||
func load(path string) error { | ||
out, err := aaParser("-Kr", path) | ||
if err != nil { | ||
return fmt.Errorf("parser error(%q): %w", strings.TrimSpace(out), err) | ||
} | ||
return nil | ||
} | ||
|
||
func aaParser(args ...string) (string, error) { | ||
out, err := exec.Command("apparmor_parser", args...).CombinedOutput() | ||
return string(out), err | ||
} | ||
|
||
func isLoaded(name string) (bool, error) { | ||
f, err := os.Open("/sys/kernel/security/apparmor/profiles") | ||
if err != nil { | ||
return false, err | ||
} | ||
defer f.Close() | ||
r := bufio.NewReader(f) | ||
for { | ||
p, err := r.ReadString('\n') | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
return false, err | ||
} | ||
if strings.HasPrefix(p, name+" ") { | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ecs-init/vendor/github.com/containerd/containerd/pkg/apparmor/apparmor.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
ecs-init/vendor/github.com/containerd/containerd/pkg/apparmor/apparmor_linux.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.