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

seccomp: Sync fields with runtime-spec fields #42604

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion profiles/seccomp/seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (

// Seccomp represents the config for a seccomp profile for syscall restriction.
type Seccomp struct {
DefaultAction specs.LinuxSeccompAction `json:"defaultAction"`
DefaultAction specs.LinuxSeccompAction `json:"defaultAction"`
DefaultErrnoRet *uint `json:"defaultErrnoRet,omitempty"`
rata marked this conversation as resolved.
Show resolved Hide resolved
ListenerPath string `json:"listenerPath,omitempty"`
ListenerMetadata string `json:"listenerMetadata,omitempty"`

// Architectures is kept to maintain backward compatibility with the old
// seccomp profile.
Architectures []specs.Arch `json:"architectures,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions profiles/seccomp/seccomp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func setupSeccomp(config *Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, error)
}

newConfig.DefaultAction = config.DefaultAction
newConfig.DefaultErrnoRet = config.DefaultErrnoRet
newConfig.ListenerPath = config.ListenerPath
newConfig.ListenerMetadata = config.ListenerMetadata

Loop:
// Loop through all syscall blocks and convert them to libcontainer format after filtering them
Expand Down
41 changes: 41 additions & 0 deletions profiles/seccomp/seccomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,47 @@ func TestLoadProfile(t *testing.T) {
assert.DeepEqual(t, expected, *p)
}

func TestLoadProfileWithDefaultErrnoRet(t *testing.T) {
var profile = []byte(`{
"defaultAction": "SCMP_ACT_ERRNO",
"defaultErrnoRet": 6
}`)
rs := createSpec()
p, err := LoadProfile(string(profile), &rs)
if err != nil {
t.Fatal(err)
}

expectedErrnoRet := uint(6)
expected := specs.LinuxSeccomp{
DefaultAction: "SCMP_ACT_ERRNO",
DefaultErrnoRet: &expectedErrnoRet,
}

assert.DeepEqual(t, expected, *p)
}

func TestLoadProfileWithListenerPath(t *testing.T) {
var profile = []byte(`{
"defaultAction": "SCMP_ACT_ERRNO",
"listenerPath": "/var/run/seccompaget.sock",
"listenerMetadata": "opaque-metadata"
}`)
rs := createSpec()
p, err := LoadProfile(string(profile), &rs)
if err != nil {
t.Fatal(err)
}

expected := specs.LinuxSeccomp{
DefaultAction: "SCMP_ACT_ERRNO",
ListenerPath: "/var/run/seccompaget.sock",
ListenerMetadata: "opaque-metadata",
}

assert.DeepEqual(t, expected, *p)
}

// TestLoadLegacyProfile tests loading a seccomp profile in the old format
// (before https://github.com/docker/docker/pull/24510)
func TestLoadLegacyProfile(t *testing.T) {
Expand Down