Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3f0aafb
Add initial command line spec
julz Sep 2, 2015
577f991
Wrap to one sentence per line
wking Sep 15, 2015
ff5ae1d
Use a Markdown list for flags and output
wking Sep 15, 2015
4dfe30b
'sh' syntax highlighting for fenced code blocks
wking Sep 15, 2015
259bbb7
Drop colon from "Operations:" header
wking Sep 15, 2015
efaef2e
Fix "process exit code" -> "process's exit code"
wking Sep 15, 2015
969c763
Split standard streams and exit codes into their own entries
wking Sep 15, 2015
60cddc4
Introduce the funC placeholder
wking Sep 15, 2015
a7f5aa9
Link to runtime.json too
wking Sep 15, 2015
9d97d39
Add --config and --runtime options
wking Sep 15, 2015
11da397
Add an overall usage template and a section on global options
wking Sep 15, 2015
ffa124c
Add a 'version' command
wking Sep 15, 2015
5033c59
Add an --id option to 'start'
wking Sep 15, 2015
f3a1c08
Shift config.json and runtime.json into the 'start' section
wking Sep 15, 2015
9751a36
Add an 'exec' command for launching a process in an existing container
wking Sep 15, 2015
dd38d9d
Add a 'signal' command for signalling containers
wking Sep 15, 2015
1261380
Add a link to lifecycle docs for cleanup if main process dies
wking Sep 15, 2015
1c32342
Add 'pause' and 'resume' commands
wking Sep 15, 2015
d41ab07
Document LISTEN_FDS for passing open file descriptors
wking Sep 17, 2015
5afcaca
Add license and DCO information for contributions
crosbymichael Jul 2, 2015
d00530d
CONTRIBUTING: Put contributing information where GitHub likes it
wking Dec 2, 2015
ffdd704
README: Document the project and scope
wking Dec 2, 2015
3606bcf
Punt to the operating system for character encodings
wking Dec 2, 2015
1cbcac6
Shift version description to top of section
wking Dec 3, 2015
933b55d
Strip trailing whitespace
wking Dec 3, 2015
b922732
Drop exec, pause, resume, and signal
wking Dec 3, 2015
839b6ee
Use imperative phrasing for command summaries
wking Dec 5, 2015
0d0c8db
start: Remove start-scoped config.json and runtime.json references
wking Dec 5, 2015
e9a6625
Clarity for commands vs global options
mikebrow Dec 7, 2015
3f348cd
start: Change --config and --runtime to --bundle
wking Dec 9, 2015
e41ffc1
Use RFC 2119's keywords (MUST, MAY, ...)
wking Dec 3, 2015
2fc4e03
runtime: Fix closing bracket in posix-locale-encoding reference
wking Jun 22, 2016
7704531
runtime: Drop 'sh' highlighting from fenced code blocks
wking Jun 22, 2016
b6d22e8
runtime: Use headers for examples
wking Jun 22, 2016
60148f0
runtime: Add a 'state' command
wking Jun 22, 2016
b7429c8
runtime: RFC 2119 SHOULDs in the "Character encodings" section
wking Jun 22, 2016
7f11bd8
README: Update links and text
wking Feb 8, 2017
5729695
*: "OCI Runtime Command Line Interface"
wking Feb 8, 2017
c44520e
runtime: Semantically version this specification
wking Feb 8, 2017
a65fe1e
runtime: Drop 'sh' highlighting from fenced code blocks
wking Feb 8, 2017
5fc039d
runtime: Fix "MUST not" -> "MUST NOT"
wking Feb 8, 2017
5d0e44c
runtime: Address unspecified commands and options
wking Feb 8, 2017
4c7901c
runtime: Drop the 'version' command
wking Feb 8, 2017
6819bc9
runtime: Four-space indents for nested lists
wking Feb 8, 2017
5c87cc6
runtime: Add a 'kill' command
wking Feb 9, 2017
6375ad0
runtime: Link to the spec's 'bundle' docs
wking Feb 9, 2017
3d50871
runtime: Move start's --id to a positional parameter
wking Feb 9, 2017
56c906d
runtime: "application" -> "container"
wking Feb 9, 2017
5ace459
runtime: Split 'create' and 'start' (and add 'delete')
wking Feb 9, 2017
6f5d033
runtime: Add --pid-file to 'create'
wking Feb 9, 2017
394fa4f
runtime: Add --console-socket for terminal handling
wking Feb 9, 2017
74ca403
runtime: Mention TIOCSTI privilege escalation
wking Feb 9, 2017
a26d73b
runtime: Replace '--console-socket PATH' with '$LISTEN_FDS + 3'
wking Feb 9, 2017
26440a5
runtime: Replace '$LISTEN_FDS + 3' with '--console-socket FD'
wking Feb 9, 2017
63bfd58
Merge branch 'runtime-spec-513'
wking Feb 9, 2017
32244e6
runtime: Document RFC 2119 wording
wking Feb 10, 2017
7941be4
runtime: Define "unspecified", "undefined", and "implementation-defined"
wking Feb 10, 2017
be7de4f
runtime: Add compliance language
wking Feb 15, 2017
d3b41c1
command-line-interface: Rename from runtime.md to avoid collisions
wking Jul 6, 2016
215d47e
Remove files that duplicate runtime-spec content (LICENSE, etc.)
wking Jul 6, 2016
124fdc0
Merge branch 'runtime-tools' of git://github.com/wking/oci-command-li…
wking Feb 15, 2017
6551b2d
docs/command-line-interface: Move command line API into position
wking Feb 10, 2017
2ce4a5d
docs/runtime-compliance-testing: Document list of supported APIs
wking Feb 15, 2017
ebae480
api/socket: Add JSON Schema and Go types for the command-line API soc…
wking Feb 10, 2017
a2725b4
docs/command-line-interface: Add "NOT RECOMMENDED" to RFC 2119 keywords
wking Apr 11, 2017
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
23 changes: 23 additions & 0 deletions api/socket/socket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package socket

// Message is the normal data for messages passed on the console socket.
type Message struct {
// Type of message being passed
Type string `json:"type"`
}

// TerminalRequest is the normal data for messages passing a pseudoterminal master.
type TerminalRequest struct {
Message

// Container ID for the container whose pseudoterminal master is being set.
Container string `json:"container"`
}

// Response is the normal data for response messages.
type Response struct {
Message

// Message is a phrase describing the response.
Message string `json:"message,omitempty"`
}
274 changes: 274 additions & 0 deletions docs/command-line-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
# OCI Runtime Command Line Interface

This file defines the OCI Runtime Command Line Interface version 1.0.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe add a sentence stating that this interface is specified as a test harness for compliance testing and runtimes wishing to submit for OCI runtime compliance must implement this interface for testing to be possible

Copy link
Contributor Author

@wking wking Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe add a sentence stating that this interface is specified as a test harness for compliance testing…

Done with b5deac1afdf059, borrowing from the very similar approach I'd taken in opencontainers/runtime-spec#513.

It is one of potentially several [runtime APIs supported by the runtime compliance test suite](runtime-compliance-testing.md#supported-apis).

## Notation

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119][rfc2119].

The key words "unspecified", "undefined", and "implementation-defined" are to be interpreted as described in the [rationale for the C99 standard][c99-unspecified].

## Compliance

This specification targets compliance criteria according to the role of a participant in runtime invocation.
Requirements are placed on both runtimes and runtime callers, depending on what behavior is being constrained by the requirement.
An implementation is compliant if it satisfies all the applicable MUST, REQUIRED, and SHALL requirements.
An implementation is not compliant if it fails to satisfy one or more of the applicable MUST, REQUIRED, and SHALL requirements.

## Versioning

The command line interface is versioned with [SemVer v2.0.0][semver].
The command line interface version is independent of the OCI Runtime Specification as a whole (which is tied to the [configuration format][runtime-spec-version].
For example, if a caller is compliant with version 1.1 of the command line interface, they are compatible with all runtimes that support any 1.1 or later release of the command line interface, but are not compatible with a runtime that supports 1.0 and not 1.1.

## Global usage

The runtime MUST provide an executable (called `funC` in the following examples).
That executable MUST support commands with the following template:

```
$ funC [global-options] <COMMAND> [command-specific-options] <command-specific-arguments>
```

## Global options

None are required, but the runtime MAY support options that start with at least one hyphen.
Global options MAY take positional arguments (e.g. `--log-level debug`).
Command names MUST NOT start with hyphens.
The option parsing MUST be such that `funC <COMMAND>` is unambiguously an invocation of `<COMMAND>` (even for commands not specified in this document).
If the runtime is invoked with an unrecognized command, it MUST exit with a nonzero exit code and MAY log a warning to stderr.
Beyond the above rules, the behavior of the runtime in the presence of commands and options not specified in this document is unspecified.

## Character encodings

This API specification does not cover character encodings, but runtimes SHOULD conform to their native operating system.
For example, POSIX systems define [`LANG` and related environment variables][posix-lang] for [declaring][posix-locale-encoding] [locale-specific character encodings][posix-encoding], so a runtime in an `en_US.UTF-8` locale SHOULD write its [state](#state) to stdout in [UTF-8][].

## Commands

### create

[Create][create] a container from a [bundle directory][bundle].

* *Arguments*
* *`<ID>`* Set the container ID to create.
* *Options*
* *`--bundle <PATH>`* Override the path to the [bundle directory][bundle] (defaults to the current working directory).
* *`--console-socket <FD>`* The runtime MUST pass the [pseudoterminal master][posix_openpt.3] through the open socket at file descriptor `<FD>`; the protocol is [described below](#console-socket).
* *`--pid-file <PATH>`* The runtime MUST write the container PID to this path.
* *Standard streams:*
* If [`process.terminal`][process] is true:
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
* *stdout:* The handling of stdout is unspecified.
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
* If [`process.terminal`][process] is not true:
* *stdin:* The runtime MUST pass its stdin file descriptor through to the container process without manipulation or modification.
"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.

When using a container to drop privileges, note that providing a privileged terminal's file descriptor may allow the container to [execute privileged operations via `TIOCSTI`][TIOCSTI-security] or other [TTY ioctls][tty_ioctl.4].
On Linux, [`TIOCSTI` requires `CAP_SYS_ADMIN`][capabilities.7] unless the target terminal is the caller's [controlling terminal][controlling-terminal].
* *stdout:* The runtime MUST pass its stdout file descriptor through to the container process without manipulation or modification.
* *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.
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.
* *Environment variables*
* *`LISTEN_FDS`:* The number of file descriptors passed.
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].
* *Exit code:* Zero if the container was successfully created and non-zero on errors.

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

#### Console socket

The [`AF_UNIX`][unix-socket] used by [`--console-socket`](#create) handles request and response messages between a runtime and server.
The socket type MUST be [`SOCK_SEQPACKET`][socket-types] or [`SOCK_STREAM`][socket-types].
The server MUST send a single response for each runtime request.
The [normal data][socket-queue] ([`msghdr.msg_iov*`][socket.h]) of all messages MUST be [UTF-8][] [JSON](glossary.md#json).

There are [JSON Schemas](../schema/README.md#oci-runtime-command-line-interface) and [Go bindings](../api/socket/socket.go) for the messages specified in this section.

##### Requests

All requests MUST contain a **`type`** property whose value MUST one of the following strings:

* `terminal`, if the request is passing a [pseudoterminal master][posix_openpt.3].
When `type` is `terminal`, the request MUST also contain the following properties:

* **`container`** (string, REQUIRED) The container ID, as set by [create](#create).

The message's [ancillary data][socket-queue] (`msg_control*`) MUST contain at least one [`cmsghdr`][socket.h]).
The first `cmsghdr` MUST have:

* `cmsg_type` set to [`SOL_SOCKET`][socket.h],
* `cmsg_level` set to [`SCM_RIGHTS`][socket.h],
* `cmsg_len` greater than or equal to `CMSG_LEN(sizeof(int))`, and
* `((int*)CMSG_DATA(cmsg))[0]` set to the pseudoterminal master file descriptor.

##### Responses

All responses MUST contain a **`type`** property whose value MUST be one of the following strings:

* `success`, if the request was successfully processed.
* `error`, if the request was not successfully processed.

In addition, responses MAY contain any of the following properties:

* **`message`** (string, OPTIONAL) A phrase describing the response.

#### Example

```
# in a bundle directory with a process that echos "hello" and exits 42
$ test -t 1 && echo 'stdout is a terminal'
stdout is a terminal
$ funC create hello-1 <&- >stdout 2>stderr
$ echo $?
0
$ wc stdout
0 0 0 stdout
$ funC start hello-1
$ echo $?
0
$ cat stdout
hello
$ block-on-exit-and-collect-exit-code hello-1
$ echo $?
42
$ funC delete hello-1
$ echo $?
0
```

#### Container process exit

The [example's](#example) `block-on-exit-and-collect-exit-code` is platform-specific and is not specified in this document.
On Linux, it might involve an ancestor process which had set [`PR_SET_CHILD_SUBREAPER`][prctl.2] and collected the container PID [from the state][state], or a process that was [ptracing][ptrace.2] the container process for [`exit_group`][exit_group.2], although both of those race against the container process exiting before the watcher is monitoring.

### start

[Start][start] the user-specified code from [`process`][process].

* *Arguments*
* *`<ID>`* The container to start.
* *Standard streams:*
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
* *stdout:* The handling of stdout is unspecified.
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
* *Exit code:* Zero if the container was successfully started and non-zero on errors.

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

See [create](#example) for an example.

### state

[Request][state-request] the container [state][state].

* *Arguments*
* *`<ID>`* The container whose state is being requested.
* *Standard streams:*
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
* *stdout:* The runtime MUST print the [state JSON][state] to its stdout.
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
* *Exit code:* Zero if the state was successfully written to stdout and non-zero on errors.

#### Example

```
$ funC create sleeper-1
$ funC state sleeper-1
{
"ociVersion": "1.0.0-rc1",
"id": "sleeper-1",
"status": "created",
"pid": 4422,
"bundlePath": "/containers/sleeper",
"annotations" {
"myKey": "myValue"
}
}
$ echo $?
0
```

### kill

[Send a signal][kill] to the container process.

* *Arguments*
* *`<ID>`* The container being signaled.
* *Options*
* *`--signal <SIGNAL>`* The signal to send (defaults to `TERM`).
The runtime MUST support `TERM` and `KILL` signals with [the POSIX semantics][posix-signals].
The runtime MAY support additional signal names.
On platforms that support [POSIX signals][posix-signals], the runtime MUST implement this command using POSIX signals.
On platforms that do not support POSIX signals, the runtime MAY implement this command with alternative technology as long as `TERM` and `KILL` retain their POSIX semantics.
Runtime authors on non-POSIX platforms SHOULD submit documentation for their TERM implementation to this specificiation, so runtime callers can configure the container process to gracefully handle the signals.
* *Standard streams:*
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
* *stdout:* The handling of stdout is unspecified.
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
* *Exit code:* Zero if the signal was successfully sent to the container process and non-zero on errors.
Successfully sent does not mean that the signal was successfully received or handled by the container process.

#### Example

```
# in a bundle directory where the container process ignores TERM
$ funC create sleeper-1
$ funC start sleeper-1
$ funC kill sleeper-1
$ echo $?
0
$ funC kill --signal KILL sleeper-1
$ echo $?
0
```

### delete

[Release](#delete) container resources after the container process has exited.

* *Arguments*
* *`<ID>`* The container to delete.
* *Standard streams:*
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
* *stdout:* The handling of stdout is unspecified.
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
* *Exit code:* Zero if the container was successfully deleted and non-zero on errors.

See [create](#example) for an example.

[bundle]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/bundle.md
[c99-unspecified]: http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf#page=18
[capabilities.7]: http://man7.org/linux/man-pages/man7/capabilities.7.html
[controlling-terminal]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_03
[create]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#create
[delete]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#delete
[exit_group.2]: http://man7.org/linux/man-pages/man2/exit_group.2.html
[ioctl.3]: http://pubs.opengroup.org/onlinepubs/9699919799/
[kill]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#kill
[kill.2]: http://man7.org/linux/man-pages/man2/kill.2.html
[process]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#process
[posix-encoding]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap06.html#tag_06_02
[posix-lang]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
[posix-locale-encoding]: http://www.unicode.org/reports/tr35/#Bundle_vs_Item_Lookup
[posix_openpt.3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html
[posix-signals]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html#tag_13_42_03
[prctl.2]: http://man7.org/linux/man-pages/man2/prctl.2.html
[ptrace.2]: http://man7.org/linux/man-pages/man2/ptrace.2.html
[semver]: http://semver.org/spec/v2.0.0.html
[socket-queue]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_11
[socket-types]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_06
[socket.h]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
[standard-streams]: https://github.com/opencontainers/specs/blob/v0.1.1/runtime-linux.md#file-descriptors
[start]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#start
[state]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#state
[state-request]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#query-state
[systemd-listen-fds]: http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html
[rfc2119]: https://tools.ietf.org/html/rfc2119
[runtime-spec-version]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#specification-version
[TIOCSTI-security]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=628843
[tty_ioctl.4]: http://man7.org/linux/man-pages/man4/tty_ioctl.4.html
[unix-socket]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_17
[UTF-8]: http://www.unicode.org/versions/Unicode8.0.0/ch03.pdf
9 changes: 9 additions & 0 deletions docs/runtime-compliance-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Runtime compliance testing

## Supported APIs

In order to be tested for [compliance][], runtimes MUST support at least one of the following APIs:

* Version 1.0.0 of the [OCI Runtime Command Line Interface](command-line-interface.md).

[compliance]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/spec.md#notational-conventions
14 changes: 14 additions & 0 deletions schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# JSON schema

This directory contains [JSON Schema][json-schema] for validating JSON covered by local specifications.
The runtime specification includes [a generic command line tool][validate] which may be used to validate JSON with these schemas.

## OCI Runtime Command Line Interface

The [Runtime Command Line Interface](../docs/command-line-interface.md) defines:

* [Terminal requests](../docs/command-line-interface.md#requests), which may be validated against [`socket-terminal-request.json`](socket-terminal-request.json).
* [Responses](../docs/command-line-interface.md#reqponses), which may be validated against [`socket-response.json`](socket-response.json).

[json-schema]: http://json-schema.org/
[validate]: https://github.com/opencontainers/runtime-spec/tree/v1.0.0-rc5/schema#utility
24 changes: 24 additions & 0 deletions schema/socket-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "Open Container Runtime Socket Response Schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://opencontainers.org/schema/runtime/socket/response",
"type": "object",
"properties": {
"type": {
"id": "https://opencontainers.org/schema/runtime/socket/response/type",
"type": "string",
"enum": [
"success",
"error"
]
},
"message": {
"id": "https://opencontainers.org/schema/runtime/socket/response/message",
"description": "A phrase describing the response.",
"type": "string"
}
},
"required": [
"type"
]
}
24 changes: 24 additions & 0 deletions schema/socket-terminal-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "Open Container Runtime Socket Terminal Request Schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://opencontainers.org/schema/runtime/socket/terminal-request",
"type": "object",
"properties": {
"type": {
"id": "https://opencontainers.org/schema/runtime/socket/terminal/request/type",
"type": "string",
"enum": [
"terminal"
]
},
"container": {
"id": "https://opencontainers.org/schema/runtime/state/id",
"description": "the container's ID",
"type": "string"
}
},
"required": [
"type",
"container"
]
}