Skip to content

Commit 394fa4f

Browse files
committed
runtime: Add --console-socket for terminal handling
Based on work by Aleksa in opencontainers/runc#1018, this commit makes the following choices: * SOCK_SEQPACKET instead of SOCK_STREAM, because this is a message-based protocol, so it seems more natural to use a message-oriented socket type. * A string 'type' field for all messages, so we can add additional message types in the future without breaking backwards compatibility (new console-socket servers will still support old clients). Aleksa favored splitting this identifier into an integer 'type' and 'version' fields [runc-socket-type-version], but I don't see the point if they're both opaque integers without internal structure. And I expect this protocol to be stable enough that it's not worth involving SemVer and its structured versioning. * Response messages, so the client can tell whether the request was received and processed successfully or not. That gives the client a way to bail out if, for example, the server does not support the 'terminal' message type. Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent 6f5d033 commit 394fa4f

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

runtime.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,62 @@ For example, POSIX systems define [`LANG` and related environment variables][pos
4242
* *Options*
4343
* *`--bundle <PATH>`* Override the path to the [bundle directory][bundle] (defaults to the current working directory).
4444
* *`--pid-file <PATH>`* The runtime MUST write the container PID to this path.
45+
* *`--console-socket <PATH>`* The runtime MUST pass the [pseudoterminal master][posix_openpt.3] through the socket at `<PATH>`; the protocol is [described below](#console-socket).
4546
* *Standard streams:*
46-
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
47-
* *stdout:* The handling of stdout is unspecified.
48-
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
47+
* If [`process.terminal`][process] is true:
48+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
49+
* *stdout:* The handling of stdout is unspecified.
50+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
51+
* If [`process.terminal`][process] is not true:
52+
* *stdin:* The runtime MUST pass its stdin file descriptor through to the container process without manipulation or modification.
53+
"Without manipulation or modification" means that the runtime MUST not seek on the file descriptor, or close it, or read or write to it, or [`ioctl`][ioctl.3] it, or perform any other action on it besides passing it through to the container process.
54+
* *stdout:* The runtime MUST pass its stdout file descriptor through to the container process without manipulation or modification.
55+
* *stderr:* When `create` exists with a zero code, the runtime MUST pass its stderr file descriptor through to the container process without manipulation or modification.
56+
When `create` exits with a non-zero code, the runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
4957
* *Environment variables*
5058
* *`LISTEN_FDS`:* The number of file descriptors passed.
51-
For example, `LISTEN_FDS=2` would mean that the runtime MUST pass file descriptors 3 and 4 to the container process (in addition to the [standard streams][standard-streams]) to support [socket activation][systemd-listen-fds].
59+
For example, `LISTEN_FDS=2` would mean that the runtime MUST pass file descriptors 3 and 4 to the container process (in addition to the standard streams) to support [socket activation][systemd-listen-fds].
5260
* *Exit code:* Zero if the container was successfully created and non-zero on errors.
5361

5462
Callers MAY block on this command's successful exit to trigger post-create activity.
5563

64+
#### Console socket
65+
66+
The [`AF_UNIX`][unix-socket] used by [`--console-socket`](#create) handles request and response messages between a runtime and server.
67+
The socket type MUST be [`SOCK_SEQPACKET`][socket-types].
68+
The server MUST send a single response for each runtime request.
69+
The [normal data][socket-queue] ([`msghdr.msg_iov*`][socket.h]) of all messages MUST be [UTF-8][] [JSON](glossary.md#json).
70+
71+
There are [JSON Schemas](schema/README.md) and [Go bindings](specs-go/socket/socket.go) for the messages specified in this section.
72+
73+
##### Requests
74+
75+
All requests MUST contain a **`type`** property whose value MUST one of the following strings:
76+
77+
* `terminal`, if the request is passing a [pseudoterminal master][posix_openpt.3].
78+
When `type` is `terminal`, the request MUST also contain the following properties:
79+
80+
* **`container`** (string, REQUIRED) The container ID, as set by [create](#create).
81+
82+
The message's [ancillary data][socket-queue] (`msg_control*`) MUST contain at least one [`cmsghdr`][socket.h]).
83+
The first `cmsghdr` MUST have:
84+
85+
* `cmsg_type` set to [`SOL_SOCKET`][socket.h],
86+
* `cmsg_level` set to [`SCM_RIGHTS`][socket.h],
87+
* `cmsg_len` greater than or equal to `CMSG_LEN(sizeof(int))`, and
88+
* `((int*)CMSG_DATA(cmsg))[0]` set to the pseudoterminal master file descriptor.
89+
90+
##### Responses
91+
92+
All responses MUST contain a **`type`** property whose value MUST be one of the following strings:
93+
94+
* `success`, if the request was successfully processed.
95+
* `error`, if the request was not successfully processed.
96+
97+
In addition, responses MAY contain any of the following properties:
98+
99+
* **`message`** (string, OPTIONAL) A phrase describing the response.
100+
56101
#### Example
57102

58103
```
@@ -181,20 +226,26 @@ See [create](#example) for an example.
181226
[create]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#create
182227
[delete]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#delete
183228
[exit_group.2]: http://man7.org/linux/man-pages/man2/exit_group.2.html
229+
[ioctl.3]: http://pubs.opengroup.org/onlinepubs/9699919799/
184230
[kill]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#kill
185231
[kill.2]: http://man7.org/linux/man-pages/man2/kill.2.html
186232
[process]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#process
187233
[posix-encoding]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap06.html#tag_06_02
188234
[posix-lang]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
189235
[posix-locale-encoding]: http://www.unicode.org/reports/tr35/#Bundle_vs_Item_Lookup
236+
[posix_openpt.3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html
190237
[posix-signals]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html#tag_13_42_03
191238
[prctl.2]: http://man7.org/linux/man-pages/man2/prctl.2.html
192239
[ptrace.2]: http://man7.org/linux/man-pages/man2/ptrace.2.html
193240
[semver]: http://semver.org/spec/v2.0.0.html
241+
[socket-queue]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_11
242+
[socket-types]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_06
243+
[socket.h]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
194244
[standard-streams]: https://github.com/opencontainers/specs/blob/v0.1.1/runtime-linux.md#file-descriptors
195245
[start]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#start
196246
[state]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#state
197247
[state-request]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#query-state
198248
[systemd-listen-fds]: http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html
199249
[runtime-spec-version]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#specification-version
250+
[unix-socket]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_17
200251
[UTF-8]: http://www.unicode.org/versions/Unicode8.0.0/ch03.pdf

0 commit comments

Comments
 (0)