-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: grantseltzer <[email protected]>
- Loading branch information
1 parent
3911802
commit a3f3066
Showing
11 changed files
with
167 additions
and
166 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Coming soon - the pkg/entitltements library written in C | ||
Compile with: `gcc -o karnTest ./karn.c ./karn.so` | ||
|
||
See example usage directory |
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,5 @@ | ||
If you are using Karn as a library for enforcing seccomp you must have: | ||
|
||
- libseccomp-dev [debian-like](https://launchpad.net/ubuntu/+source/libseccomp) / [centos-like](https://rpmfind.net/linux/rpm2html/search.php?query=libseccomp-devel) | ||
|
||
If you are using Karn to generate OCI compliant seccomp profiles to pass to containers, there are no external dependencies. |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
|
||
## Quick Start | ||
|
||
* [Library](#library) | ||
* [Containers](#containers) | ||
|
||
#### Library | ||
Let's say you're writing a simple HTTP webserver in go: | ||
|
||
``` | ||
package main | ||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
func main() { | ||
http.HandleFunc("/", HelloServer) | ||
http.ListenAndServe(":8080", nil) | ||
} | ||
func HelloServer(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "I can modprobe if you exploit me, %s!", r.URL.Path[1:]) | ||
} | ||
``` | ||
|
||
This program just handles incoming HTTP requests on a network sockets. I didn't include anything exploitable here for simplicity but try to imagine the possibility of an application vulnerablity. | ||
|
||
The only relevant sounding entitlement is `NetworkConnection`. Let's apply it: | ||
|
||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
Karn "github.com/grantseltzer/Karn/go/pkg/entitlements" | ||
) | ||
|
||
func main() { | ||
|
||
neededEntitlements := []Karn.Entitlement{ | ||
"NetworkConnection" | ||
} | ||
|
||
err := Karn.ApplyEntitlements(neededEntitlements) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
http.HandleFunc("/", HelloServer) | ||
http.ListenAndServe(":8080", nil) | ||
} | ||
|
||
func HelloServer(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "I can modprobe if you exploit me, %s!", r.URL.Path[1:]) | ||
} | ||
``` | ||
|
||
From here you wouldn't notice any difference in your applications runtime, except now it has a lot less system calls that it can use! | ||
|
||
#### Containers | ||
|
||
Let's use the same example as above. This time, we're running the application inside a container. In that case it's better to pass a seccomp profile to the container runtime instead of inside the application. This way the seccomp rules will be applied to every process inside the container. | ||
|
||
We can build the karn CLI with a simple `make`. | ||
|
||
From there, we're going to create the profile and then pass it with the container when we start it. | ||
|
||
```bash | ||
[*] ./bin/karn network_connection > seccomp_profile.json | ||
|
||
[*] cat seccomp_profile | ||
{ | ||
"defaultAction": "SCMP_ACT_ALLOW", | ||
"architectures": [ | ||
"SCMP_ARCH_X86", | ||
"SCMP_ARCH_X86_64" | ||
], | ||
"syscalls": [ | ||
{ | ||
"names": [ | ||
"adjtimex", | ||
"clock_adjtime", | ||
"clock_settime", | ||
"settimeofday", | ||
"stime", | ||
"pivot_root", | ||
"kexec_file_load", | ||
"kexec_load", | ||
"ioperm", | ||
"iopl", | ||
"quotactl", | ||
"execve", | ||
"execveat", | ||
"fork", | ||
"vfork", | ||
"swapon", | ||
"swapoff", | ||
"mount", | ||
"umount", | ||
"umount2", | ||
"sysfs", | ||
"_sysctl", | ||
"personality", | ||
"ustat", | ||
"nfsservctl", | ||
"vm86", | ||
"uselib", | ||
"vm86old", | ||
"reboot", | ||
"add_key", | ||
"request_key", | ||
"keyctl", | ||
"unshare", | ||
"setns", | ||
"mknod", | ||
"get_mempolicy", | ||
"set_mempolicy", | ||
"move_pages", | ||
"mbind", | ||
"acct", | ||
"ptrace", | ||
"lookup_dcookie", | ||
"bpf", | ||
"perf_event_open", | ||
"process_vm_readv", | ||
"process_vm_writev", | ||
"create_module", | ||
"delete_module", | ||
"finit_module", | ||
"get_kernel_syms", | ||
"init_module", | ||
"query_module", | ||
"chown", | ||
"fchown", | ||
"fchownat", | ||
"lchown" | ||
], | ||
"action": "SCMP_ACT_ERRNO" | ||
} | ||
] | ||
} | ||
|
||
[*] docker build # (building your container with your application) | ||
|
||
[*] docker run --rm -d --security-opt seccomp=./seccomp_profile.json <your_image> <you_app_command_line> | ||
``` |
This file was deleted.
Oops, something went wrong.
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