Skip to content

Commit 483dfbf

Browse files
committed
Add Seccomp Notify support
This adds the specification for Seccomp Userspace Notification and the Golang bindings. This contains: - A new OCI hook "sendSeccompFd" used to pass the seccompfd to an external seccomp agent via the hook. - Additional fields for the container state to give information about the file descriptors passed for seccomp. This was discussed in the OCI Weekly Discussion on September 16th, 2020, see: - https://hackmd.io/El8Dd2xrTlCaCG59ns5cwg#September-16-2020 - https://docs.google.com/document/d/1xHw5GQjMj6ZKR-40aKmTWZRkvlPuzMGQRu-YpOFQc30/edit Documentation for this feature: - https://www.kernel.org/doc/html/v5.0/userspace-api/seccomp_filter.html#userspace-notification - man pages: seccomp_user_notif.2 at https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/log/?h=seccomp_user_notif - brauner's blog: https://brauner.github.io/2020/07/23/seccomp-notify.html This PR is an alternative proposal to PR 1038. Signed-off-by: Alban Crequy <[email protected]>
1 parent e6143ca commit 483dfbf

File tree

8 files changed

+47
-5
lines changed

8 files changed

+47
-5
lines changed

config-linux.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ The following parameters can be specified to set up seccomp:
642642
* `SCMP_ACT_TRACE`
643643
* `SCMP_ACT_ALLOW`
644644
* `SCMP_ACT_LOG`
645+
* `SCMP_ACT_NOTIFY`
645646

646647
* **`errnoRet`** *(uint, OPTIONAL)* - the errno return code to use.
647648
Some actions like `SCMP_ACT_ERRNO` and `SCMP_ACT_TRACE` allow to specify the errno

config.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ For POSIX platforms, the configuration structure supports `hooks` for configurin
412412
* Entries in the array have the same schema as `createRuntime` entries.
413413
* The value of `path` MUST resolve in the [runtime namespace](glossary.md#runtime-namespace).
414414
* The `poststop` hooks MUST be executed in the [runtime namespace](glossary.md#runtime-namespace).
415+
* **`sendSeccompFd`** (array of objects, OPTIONAL) is an array of [`sendSeccompFd` hooks](#sendseccompfd).
416+
* Entries in the array have the same schema as `createRuntime` entries.
417+
* The value of `path` MUST resolve in the [runtime namespace](glossary.md#runtime-namespace).
418+
* The `sendSeccompFd` hooks MUST be executed in the [runtime namespace](glossary.md#runtime-namespace).
419+
* The [state](runtime.md#state) passed to hooks over stdin contains an additional payload with the seccomp file descriptor.
415420

416421
Hooks allow users to specify programs to run before or after various lifecycle events.
417422
Hooks MUST be called in the listed order.
@@ -476,6 +481,16 @@ Cleanup or debugging functions are examples of such a hook.
476481
The `poststop` hooks' path MUST resolve in the [runtime namespace](glossary.md#runtime-namespace).
477482
The `poststop` hooks MUST be executed in the [runtime namespace](glossary.md#runtime-namespace).
478483

484+
### <a name="configHooksSendSeccompFd" />SendSeccompFd
485+
486+
The `sendSeccompFd` hooks is only called if the seccomp policy contains `SCMP_ACT_NOTIFY`.
487+
488+
The `sendSeccompFd` hooks MUST be called after the [`start`](runtime.md#start) operation is called and after the seccomp policy is installed but [before the user-specified program command is executed](runtime.md#lifecycle).
489+
The goal of this hook is to pass the seccomp file descriptor to a seccomp agent.
490+
491+
The `sendSeccompFd` hooks' path MUST resolve in the [runtime namespace](glossary.md#runtime-namespace).
492+
The `peccompFdoststop` hooks MUST be executed in the [runtime namespace](glossary.md#runtime-namespace).
493+
479494
### Summary
480495

481496
See the below table for a summary of hooks and when they are called:
@@ -488,6 +503,7 @@ See the below table for a summary of hooks and when they are called:
488503
| `startContainer` | container | After the start operation is called but before the user-specified program command is executed. |
489504
| `poststart` | runtime | After the user-specified process is executed but before the start operation returns. |
490505
| `poststop` | runtime | After the container is deleted but before the delete operation returns. |
506+
| `sendSeccompFd` | runtime | After the start operation is called but before the user-specified program command is executed. |
491507

492508
### Example
493509

@@ -536,6 +552,13 @@ See the below table for a summary of hooks and when they are called:
536552
"path": "/usr/sbin/cleanup.sh",
537553
"args": ["cleanup.sh", "-f"]
538554
}
555+
],
556+
"sendSeccompFd": [
557+
{
558+
"path": "/usr/bin/seccomp-agent",
559+
"args": ["seccomp-agent", "--allow-mknods=/dev/null,/dev/net/tun"],
560+
"env": [ "key1=value1"]
561+
}
539562
]
540563
}
541564
```

runtime.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The state of a container includes the following properties:
2929
This is provided so that consumers can find the container's configuration and root filesystem on the host.
3030
* **`annotations`** (map, OPTIONAL) contains the list of annotations associated with the container.
3131
If no annotations were provided then this property MAY either be absent or an empty map.
32+
* **`seccomp`** (map, OPTIONAL) contains additional TODO.
3233

3334
The state MAY include additional properties.
3435

schema/config-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
},
2727
"poststop": {
2828
"$ref": "defs.json#/definitions/ArrayOfHooks"
29+
},
30+
"sendSeccompFd": {
31+
"$ref": "defs.json#/definitions/ArrayOfHooks"
2932
}
3033
}
3134
},

schema/defs-linux.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"SCMP_ACT_ERRNO",
6161
"SCMP_ACT_TRACE",
6262
"SCMP_ACT_ALLOW",
63-
"SCMP_ACT_LOG"
63+
"SCMP_ACT_LOG",
64+
"SCMP_ACT_NOTIFY"
6465
]
6566
},
6667
"SeccompFlag": {

schema/test/config/good/spec-example.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@
191191
"-f"
192192
]
193193
}
194+
],
195+
"sendSeccompFd": [
196+
{
197+
"path": "/usr/bin/seccomp-agent",
198+
"args": ["seccomp-agent", "--allow-mknods=/dev/null,/dev/net/tun"],
199+
"env": [ "key1=value1"]
200+
}
194201
]
195202
},
196203
"linux": {

specs-go/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ type Hooks struct {
134134
// CreateRuntime is a list of hooks to be run after the container has been created but before pivot_root or any equivalent operation has been called
135135
// It is called in the Runtime Namespace
136136
CreateRuntime []Hook `json:"createRuntime,omitempty"`
137+
// SendSeccompFd is a list of hooks to be run after a new seccomp fd is created
138+
// It is called in the Runtime Namespace
139+
SendSeccompFd []Hook `json:"sendSeccompFd,omitempty"`
137140
// CreateContainer is a list of hooks to be run after the container has been created but before pivot_root or any equivalent operation has been called
138141
// It is called in the Container Namespace
139142
CreateContainer []Hook `json:"createContainer,omitempty"`
@@ -646,6 +649,7 @@ const (
646649
ActTrace LinuxSeccompAction = "SCMP_ACT_TRACE"
647650
ActAllow LinuxSeccompAction = "SCMP_ACT_ALLOW"
648651
ActLog LinuxSeccompAction = "SCMP_ACT_LOG"
652+
ActNotify LinuxSeccompAction = "SCMP_ACT_NOTIFY"
649653
)
650654

651655
// LinuxSeccompOperator used to match syscall arguments in Seccomp

specs-go/state.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ type ContainerState string
55

66
const (
77
// StateCreating indicates that the container is being created
8-
StateCreating ContainerState = "creating"
8+
StateCreating ContainerState = "creating"
99

1010
// StateCreated indicates that the runtime has finished the create operation
11-
StateCreated ContainerState = "created"
11+
StateCreated ContainerState = "created"
1212

1313
// StateRunning indicates that the container process has executed the
1414
// user-specified program but has not exited
15-
StateRunning ContainerState = "running"
15+
StateRunning ContainerState = "running"
1616

1717
// StateStopped indicates that the container process has exited
18-
StateStopped ContainerState = "stopped"
18+
StateStopped ContainerState = "stopped"
1919
)
2020

2121
// State holds information about the runtime state of the container.
@@ -32,4 +32,6 @@ type State struct {
3232
Bundle string `json:"bundle"`
3333
// Annotations are key values associated with the container.
3434
Annotations map[string]string `json:"annotations,omitempty"`
35+
36+
SeccompFd int `json:"seccompFd"`
3537
}

0 commit comments

Comments
 (0)