Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with OPA: use rego rules #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Integration with OPA: use rego rules #12

wants to merge 7 commits into from

Conversation

alban
Copy link
Member

@alban alban commented May 15, 2021

Integration with OPA: use rego rules

The Seccomp Agent can be configured by a ConfigMap containing rules in the rego language from OPA.

How to use

Example of rules in policies.rego:

    package syscall.authz

    action[{"passthrough": passthrough, "reason": reason}] {
        input.syscall = "execve"

        passthrough := true
        reason := "execve are always accepted"
    }
    action[{"handler": handler, "reason": reason, "suffix": suffix}] {
        input.syscall = "mkdir"
        input.pod.namespace = "default"
        input.pod.name = "mynotifypod"
        startswith(input.arg0, "foo")

        handler := "mkdir"
        reason := "directories can start with foo"
        suffix := "-{{.Namespace}}-{{.Pod}}-{{.Container}}"
    }
    action[{"handler": handler, "reason": reason, "suffix": suffix}] {
        input.syscall = "mkdir"
        input.pod.namespace = "default"
        input.pod.name = "mynotifypod"
        endswith(input.arg0, "bar")

        handler := "mkdir"
        reason := "directories can end with bar"
        suffix := "-{{.Namespace}}-{{.Pod}}-{{.Container}}"
    }
    action[{"handler": handler, "reason": reason}] {
        input.syscall = "mount"
        allowedfs := {"proc", "tmpfs"}
        allowedfs[input.arg2]
        input.pod.namespace = "default"
        input.pod.name = "mynotifypod"

        handler := "mount"
        reason := "mounting specific filesystems is allowed"
    }

Testing done

The behaviour of the mkdir and mount syscalls below follow the rules expressed in rego:

$ kubectl exec -ti mynotifypod -- /bin/sh
/ # mkdir foo-A
/ # ls -ld foo-A-default-mynotifypod-container1/
drwxr-xr-x    2 root     root          4096 May 15 16:47 foo-A-default-mynotifypod-container1/
/ # mkdir B-bar
/ # mkdir none
mkdir: can't create directory 'none': Function not implemented
/ # mount -t tmpfs tmpfs root
/ # mount -t cgroup cgroup root
mount: mounting cgroup on root failed: Function not implemented
/ # 

This includes an example of handler that returns a different error each
time in a cycle. For this, we need to keep a state on the filter to
remember the previous error returned.

    f.AddHandler("chmod", handlers.ErrorSeq())

Signed-off-by: Alban Crequy <[email protected]>
Signed-off-by: Alban Crequy <[email protected]>
It allows to try seccomp in a shell without starting a new container.

sudo ./seccompagent -resolver demo-basic &
sudo ./seccompshell -seccomp-policy /var/lib/kubelet/seccomp/notify.json /bin/bash

Signed-off-by: Alban Crequy <[email protected]>
Based on Rodrigo's commit cf3fb66

To reference the new commit I just run:
        go mod edit -replace=github.com/opencontainers/runtime-spec=github.com/kinvolk/runtime-spec@58798e75e9803d99bff5837ff39e9afe2e2efec8
        go mod vendor

And commited the changes.

Signed-off-by: Alban Crequy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant