Skip to content

Commit 0127ef5

Browse files
committed
official seccomp support
1 parent 43bd5a2 commit 0127ef5

File tree

4 files changed

+157
-61
lines changed

4 files changed

+157
-61
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Just because the hack day is over doesn't mean the project is done :-) The proje
66

77
IRC (freenode): \#dockerslim
88

9-
## WIP
9+
## NEW
1010

11-
Docker 1.10 updates haven't been merged yet. Use Docker 1.8 or 1.9.
11+
Official seccomp support Docker 1.10
1212

1313
## DEMO VIDEO
1414

@@ -54,7 +54,7 @@ Yes! Either way, you should test your Docker images.
5454

5555
You don't need to read the language spec and lots of books :-) Go through the [Tour of Go](https://tour.golang.org/welcome/1) and optionally read [50 Shades of Go](http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/) and you'll be ready to contribute!
5656

57-
### What's the best application for DockerSlim
57+
### What's the best application for DockerSlim?
5858

5959
DockerSlim will work for any dockerized application; however, DockerSlim automates app interactions for applications with an HTTP API. You can use DockerSlim even if your app doesn't have an HTTP API. You'll need to interact with your application manually to make sure DockerSlim can observe your application behavior.
6060

@@ -72,7 +72,7 @@ Example: `./docker-slim info 6f74095b68c9`
7272

7373
The demo run on Mac OS X, but you can build a linux version. Note that these steps are different from the steps in the demo video.
7474

75-
0. Get the docker-slim [binaries](https://github.com/cloudimmunity/docker-slim/releases/download/v1.9/dist_mac.zip). Unzip them and optionally add their directory to your PATH environment variable if you want to use the app from other locations.
75+
0. Get the docker-slim [binaries](https://github.com/cloudimmunity/docker-slim/releases/download/v1.11/dist_mac.zip). Unzip them and optionally add their directory to your PATH environment variable if you want to use the app from other locations.
7676

7777
The extracted directory contains two binaries:
7878

@@ -128,10 +128,15 @@ If you'd like to see the artifacts without running `docker-slim` you can take a
128128
* a reverse engineered Dockerfile (`Dockerfile.fat`)
129129
* a container report file (`creport.json`)
130130
* a sample AppArmor profile (which will be named based on your original image name)
131-
* and a sample Seccomp profile (for the upcoming Docker release)
131+
* and a sample Seccomp profile
132132

133133
If you don't want to create a minified image and only want to "reverse engineer" the Dockerfile you can use the `info` command.
134134

135+
## USING AUTO-GENERATED SECCOMP PROFILES
136+
137+
You can use the generated profile with your original image or with the minified image DockerSlim created:
138+
139+
`docker run --security-opt seccomp:path_to/my-sample-node-app-seccomp.json -p 8000:8000 my/sample-node-app.slim`
135140

136141
## BUILD PROCESS
137142

@@ -249,7 +254,7 @@ The minified `sample_app` docker image now works! We turned a 430MB node.js app
249254
* Refactor the time-based container monitoring phase [DONE].
250255
* Automated interaction with the target container (requires app code analysis) [WIP;DONE - simple version].
251256
* Auto-generate AppArmor profiles [WIP].
252-
* Auto-generate Seccomp filters [WIP].
257+
* Auto-generate Seccomp filters [USABLE :)].
253258
* Split "monitor" from "launcher" (as it's supposed to work :-))
254259
* Add scripting language dependency discovery to the "scanner" app.
255260
* Support additional command line parameters to specify CMD, VOLUME, ENV info.

master/security/apparmor/apparmor.go

100644100755
Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,43 @@ func GenProfile(artifactLocation string, profileName string) error {
6969
profileData := appArmorProfileData{ProfileName: profileName}
7070

7171
for _, aprops := range creport.Image.Files {
72-
if aprops.Flags["X"] {
73-
profileData.ExeFileRules = append(profileData.ExeFileRules,
74-
appArmorFileRule{
75-
FilePath: aprops.FilePath,
76-
PermSet: report.PermSetFromFlags(aprops.Flags),
77-
})
78-
} else if aprops.Flags["W"] {
79-
profileData.WriteFileRules = append(profileData.WriteFileRules,
80-
appArmorFileRule{
81-
FilePath: aprops.FilePath,
82-
PermSet: report.PermSetFromFlags(aprops.Flags),
83-
})
84-
} else if aprops.Flags["R"] {
72+
if aprops == nil {
73+
continue
74+
}
75+
if aprops.Flags == nil {
76+
//default to "R" (todo: double check flag creation...)
8577
profileData.ReadFileRules = append(profileData.ReadFileRules,
8678
appArmorFileRule{
8779
FilePath: aprops.FilePath,
88-
PermSet: report.PermSetFromFlags(aprops.Flags),
80+
PermSet: "r",
8981
})
9082
} else {
91-
//logrus.Printf("docker-slim: genAppArmorProfile - other artifact => %v\n", aprops)
92-
//note: most are Symlinks
93-
//&{Symlink /lib/x86_64-linux-gnu/libc.so.6 ---------- Lrwxrwxrwx libc-2.19.so map[] 12 }
94-
//todo: double check this file:
95-
//&{File /etc/ld.so.cache ---------- -rw-r--r-- map[] data 15220 ca4491d92fac4500148a18bd9cada91b49e08701 }
96-
//-rw-r--r-- 1 user group 15K Month 1 20:14 ld.so.cache
83+
if aprops.Flags["X"] {
84+
profileData.ExeFileRules = append(profileData.ExeFileRules,
85+
appArmorFileRule{
86+
FilePath: aprops.FilePath,
87+
PermSet: report.PermSetFromFlags(aprops.Flags),
88+
})
89+
} else if aprops.Flags["W"] {
90+
profileData.WriteFileRules = append(profileData.WriteFileRules,
91+
appArmorFileRule{
92+
FilePath: aprops.FilePath,
93+
PermSet: report.PermSetFromFlags(aprops.Flags),
94+
})
95+
} else if aprops.Flags["R"] {
96+
profileData.ReadFileRules = append(profileData.ReadFileRules,
97+
appArmorFileRule{
98+
FilePath: aprops.FilePath,
99+
PermSet: report.PermSetFromFlags(aprops.Flags),
100+
})
101+
} else {
102+
//logrus.Printf("docker-slim: genAppArmorProfile - other artifact => %v\n", aprops)
103+
//note: most are Symlinks
104+
//&{Symlink /lib/x86_64-linux-gnu/libc.so.6 ---------- Lrwxrwxrwx libc-2.19.so map[] 12 }
105+
//todo: double check this file:
106+
//&{File /etc/ld.so.cache ---------- -rw-r--r-- map[] data 15220 ca4491d92fac4500148a18bd9cada91b49e08701 }
107+
//-rw-r--r-- 1 user group 15K Month 1 20:14 ld.so.cache
108+
}
97109
}
98110
}
99111

master/security/seccomp/seccomp.go

100644100755
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ func archNameToSeccompArch(name string) specs.Arch {
2525
return "unknown"
2626
}
2727

28+
var extraCalls = []string{
29+
"openat",
30+
"getdents64",
31+
"capget",
32+
"capset",
33+
"chdir",
34+
"setuid",
35+
"setgroups",
36+
"setgid",
37+
"prctl",
38+
"fchown",
39+
"getppid",
40+
"getpid",
41+
"getuid",
42+
"getgid",
43+
}
44+
2845
func GenProfile(artifactLocation string, profileName string) error {
2946
containerReportFileName := "creport.json"
3047
containerReportFilePath := filepath.Join(artifactLocation, containerReportFileName)
@@ -51,6 +68,12 @@ func GenProfile(artifactLocation string, profileName string) error {
5168
Architectures: []specs.Arch{archNameToSeccompArch(creport.Monitors.Pt.ArchName)},
5269
}
5370

71+
for _, xcall := range extraCalls {
72+
if _, ok := creport.Monitors.Pt.SyscallStats[xcall]; !ok {
73+
creport.Monitors.Pt.SyscallStats[xcall] = report.SyscallStatInfo{Name: xcall}
74+
}
75+
}
76+
5477
for _, scInfo := range creport.Monitors.Pt.SyscallStats {
5578
profile.Syscalls = append(profile.Syscalls, &specs.Syscall{
5679
Name: scInfo.Name,

0 commit comments

Comments
 (0)