...

Source file src/github.com/opencontainers/runc/features.go

Documentation: github.com/opencontainers/runc

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/opencontainers/runc/libcontainer/capabilities"
     8  	"github.com/opencontainers/runc/libcontainer/configs"
     9  	"github.com/opencontainers/runc/libcontainer/seccomp"
    10  	"github.com/opencontainers/runc/libcontainer/specconv"
    11  	"github.com/opencontainers/runc/types/features"
    12  	"github.com/opencontainers/runtime-spec/specs-go"
    13  	"github.com/urfave/cli"
    14  )
    15  
    16  var featuresCommand = cli.Command{
    17  	Name:      "features",
    18  	Usage:     "show the enabled features",
    19  	ArgsUsage: "",
    20  	Description: `Show the enabled features.
    21     The result is parsable as a JSON.
    22     See https://pkg.go.dev/github.com/opencontainers/runc/types/features for the type definition.
    23     The types are experimental and subject to change.
    24  `,
    25  	Action: func(context *cli.Context) error {
    26  		if err := checkArgs(context, 0, exactArgs); err != nil {
    27  			return err
    28  		}
    29  
    30  		tru := true
    31  
    32  		feat := features.Features{
    33  			OCIVersionMin: "1.0.0",
    34  			OCIVersionMax: specs.Version,
    35  			Annotations: map[string]string{
    36  				features.AnnotationRuncVersion:           version,
    37  				features.AnnotationRuncCommit:            gitCommit,
    38  				features.AnnotationRuncCheckpointEnabled: "true",
    39  			},
    40  			Hooks:        configs.KnownHookNames(),
    41  			MountOptions: specconv.KnownMountOptions(),
    42  			Linux: &features.Linux{
    43  				Namespaces:   specconv.KnownNamespaces(),
    44  				Capabilities: capabilities.KnownCapabilities(),
    45  				Cgroup: &features.Cgroup{
    46  					V1:          &tru,
    47  					V2:          &tru,
    48  					Systemd:     &tru,
    49  					SystemdUser: &tru,
    50  				},
    51  				Apparmor: &features.Apparmor{
    52  					Enabled: &tru,
    53  				},
    54  				Selinux: &features.Selinux{
    55  					Enabled: &tru,
    56  				},
    57  			},
    58  		}
    59  
    60  		if seccomp.Enabled {
    61  			feat.Linux.Seccomp = &features.Seccomp{
    62  				Enabled:   &tru,
    63  				Actions:   seccomp.KnownActions(),
    64  				Operators: seccomp.KnownOperators(),
    65  				Archs:     seccomp.KnownArchs(),
    66  			}
    67  			major, minor, patch := seccomp.Version()
    68  			feat.Annotations[features.AnnotationLibseccompVersion] = fmt.Sprintf("%d.%d.%d", major, minor, patch)
    69  		}
    70  
    71  		enc := json.NewEncoder(context.App.Writer)
    72  		enc.SetIndent("", "    ")
    73  		return enc.Encode(feat)
    74  	},
    75  }
    76  

View as plain text