-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add runc features
command
#3296
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/opencontainers/runc/libcontainer/capabilities" | ||
"github.com/opencontainers/runc/libcontainer/configs" | ||
"github.com/opencontainers/runc/libcontainer/seccomp" | ||
"github.com/opencontainers/runc/libcontainer/specconv" | ||
"github.com/opencontainers/runc/types/features" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var featuresCommand = cli.Command{ | ||
Name: "features", | ||
Usage: "show the enabled features", | ||
ArgsUsage: "", | ||
Description: `Show the enabled features. | ||
The result is parsable as a JSON. | ||
See https://pkg.go.dev/github.com/opencontainers/runc/types/features for the type definition. | ||
`, | ||
Action: func(context *cli.Context) error { | ||
if err := checkArgs(context, 0, exactArgs); err != nil { | ||
return err | ||
} | ||
|
||
tru := true | ||
|
||
feat := features.Features{ | ||
OCIVersionMin: "1.0.0", | ||
OCIVersionMax: specs.Version, | ||
Annotations: map[string]string{ | ||
features.AnnotationRuncVersion: version, | ||
features.AnnotationRuncCommit: gitCommit, | ||
features.AnnotationRuncCheckpointEnabled: "true", | ||
}, | ||
Hooks: configs.KnownHookNames(), | ||
MountOptions: specconv.KnownMountOptions(), | ||
Linux: &features.Linux{ | ||
Namespaces: specconv.KnownNamespaces(), | ||
Capabilities: capabilities.KnownCapabilities(), | ||
Cgroup: &features.Cgroup{ | ||
V1: &tru, | ||
V2: &tru, | ||
Systemd: &tru, | ||
SystemdUser: &tru, | ||
}, | ||
Apparmor: &features.Apparmor{ | ||
Enabled: &tru, | ||
}, | ||
Selinux: &features.Selinux{ | ||
Enabled: &tru, | ||
}, | ||
}, | ||
} | ||
|
||
if seccomp.Enabled { | ||
feat.Linux.Seccomp = &features.Seccomp{ | ||
Enabled: &tru, | ||
Actions: seccomp.KnownActions(), | ||
Operators: seccomp.KnownOperators(), | ||
Archs: seccomp.KnownArchs(), | ||
} | ||
major, minor, patch := seccomp.Version() | ||
feat.Annotations[features.AnnotationLibseccompVersion] = fmt.Sprintf("%d.%d.%d", major, minor, patch) | ||
} | ||
|
||
enc := json.NewEncoder(context.App.Writer) | ||
enc.SetIndent("", " ") | ||
return enc.Encode(feat) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Package features provides the JSON structure that is printed by `runc features` (since runc v1.1.0). | ||
package features | ||
|
||
// Features represents the supported features of the runtime. | ||
type Features struct { | ||
// OCIVersionMin is the minimum OCI Runtime Spec version recognized by the runtime, e.g., "1.0.0". | ||
OCIVersionMin string `json:"ociVersionMin,omitempty"` | ||
|
||
// OCIVersionMax is the maximum OCI Runtime Spec version recognized by the runtime, e.g., "1.0.2-dev". | ||
OCIVersionMax string `json:"ociVersionMax,omitempty"` | ||
|
||
// Hooks is the list of the recognized hook names, e.g., "createRuntime". | ||
// Nil value means "unknown", not "no support for any hook". | ||
Hooks []string `json:"hooks,omitempty"` | ||
|
||
// MountOptions is the list of the recognized mount options, e.g., "ro". | ||
// Nil value means "unknown", not "no support for any mount option". | ||
MountOptions []string `json:"mountOptions,omitempty"` | ||
|
||
// Linux is specific to Linux. | ||
Linux *Linux `json:"linux,omitempty"` | ||
|
||
// Annotations contains implementation-specific annotation strings, | ||
// such as the implementation version, and third-party extensions. | ||
Annotations map[string]string `json:"annotations,omitempty"` | ||
} | ||
|
||
// Linux is specific to Linux. | ||
type Linux struct { | ||
// Namespaces is the list of the recognized namespaces, e.g., "mount". | ||
// Nil value means "unknown", not "no support for any namespace". | ||
Namespaces []string `json:"namespaces,omitempty"` | ||
|
||
// Capabilities is the list of the recognized capabilities , e.g., "CAP_SYS_ADMIN". | ||
// Nil value means "unknown", not "no support for any capability". | ||
Capabilities []string `json:"capabilities,omitempty"` | ||
|
||
Cgroup *Cgroup `json:"cgroup,omitempty"` | ||
Seccomp *Seccomp `json:"seccomp,omitempty"` | ||
Apparmor *Apparmor `json:"apparmor,omitempty"` | ||
Selinux *Selinux `json:"selinux,omitempty"` | ||
} | ||
|
||
// Seccomp represents the "seccomp" field. | ||
type Seccomp struct { | ||
// Enabled is true if seccomp support is compiled in. | ||
// Nil value means "unknown", not "false". | ||
Enabled *bool `json:"enabled,omitempty"` | ||
|
||
// Actions is the list of the recognized actions, e.g., "SCMP_ACT_NOTIFY". | ||
// Nil value means "unknown", not "no support for any action". | ||
Actions []string `json:"actions,omitempty"` | ||
|
||
// Operators is the list of the recognized actions, e.g., "SCMP_CMP_NE". | ||
// Nil value means "unknown", not "no support for any operator". | ||
Operators []string `json:"operators,omitempty"` | ||
|
||
// Operators is the list of the recognized archs, e.g., "SCMP_ARCH_X86_64". | ||
// Nil value means "unknown", not "no support for any arch". | ||
Archs []string `json:"archs,omitempty"` | ||
} | ||
|
||
// Apparmor represents the "apparmor" field. | ||
type Apparmor struct { | ||
// Enabled is true if AppArmor support is compiled in. | ||
// Unrelated to whether the host supports AppArmor or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
Enabled *bool `json:"enabled,omitempty"` | ||
} | ||
|
||
// Selinux represents the "selinux" field. | ||
type Selinux struct { | ||
// Enabled is true if SELinux support is compiled in. | ||
// Unrelated to whether the host supports SELinux or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
Enabled *bool `json:"enabled,omitempty"` | ||
} | ||
|
||
// Cgroup represents the "cgroup" field. | ||
type Cgroup struct { | ||
// V1 represents whether Cgroup v1 support is compiled in. | ||
// Unrelated to whether the host uses cgroup v1 or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
V1 *bool `json:"v1,omitempty"` | ||
|
||
// V2 represents whether Cgroup v2 support is compiled in. | ||
// Unrelated to whether the host uses cgroup v2 or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
V2 *bool `json:"v2,omitempty"` | ||
|
||
// Systemd represents whether systemd-cgroup support is compiled in. | ||
// Unrelated to whether the host uses systemd or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
Systemd *bool `json:"systemd,omitempty"` | ||
|
||
// SystemdUser represents whether user-scoped systemd-cgroup support is compiled in. | ||
// Unrelated to whether the host uses systemd or not. | ||
// Nil value means "unknown", not "false". | ||
// Always true in the current version of runc. | ||
SystemdUser *bool `json:"systemdUser,omitempty"` | ||
} | ||
|
||
const ( | ||
// AnnotationRuncVersion represents the version of runc, e.g., "1.2.3", "1.2.3+dev", "1.2.3-rc.4.", "1.2.3-rc.4+dev". | ||
// Third party implementations such as crun and runsc MAY use this annotation to report the most compatible runc version, | ||
// however, parsing this annotation value is discouraged. | ||
AnnotationRuncVersion = "org.opencontainers.runc.version" | ||
|
||
// AnnotationRuncCommit corresponds to the output of `git describe --dirty --long --always` in the runc repo. | ||
// Third party implementations such as crun and runsc SHOULD NOT use this annotation, as their repo is different from the runc repo. | ||
// Parsing this annotation value is discouraged. | ||
AnnotationRuncCommit = "org.opencontainers.runc.commit" | ||
|
||
// AnnotationRuncCheckpointEnabled is set to "true" if CRIU-based checkpointing is supported. | ||
// Unrelated to whether the host supports CRIU or not. | ||
// Always set to "true" in the current version of runc. | ||
// This is defined as an annotation because checkpointing is a runc-specific feature that is not defined in the OCI Runtime Spec. | ||
// Third party implementations such as crun and runsc MAY use this annotation. | ||
AnnotationRuncCheckpointEnabled = "org.opencontainers.runc.checkpoint.enabled" | ||
|
||
// AnnotationLibseccompVersion is the version of libseccomp, e.g., "2.5.1". | ||
// Note that the runtime MAY support seccomp even when this annotation is not present. | ||
AnnotationLibseccompVersion = "io.github.seccomp.libseccomp.version" | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to mention here that the output is subject to change, which will be slightly more visible than the changelog. But we can add that later.