2016-10-10 09:57:40 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2017-03-22 17:58:35 +00:00
|
|
|
"github.com/opencontainers/selinux/go-selinux"
|
2017-01-17 00:20:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Default paths if none are specified
|
|
|
|
const (
|
2017-05-12 13:36:15 +00:00
|
|
|
crioRoot = "/var/lib/containers/storage"
|
|
|
|
crioRunRoot = "/var/run/containers/storage"
|
|
|
|
conmonPath = "/usr/local/libexec/crio/conmon"
|
2016-10-18 14:48:33 +00:00
|
|
|
pauseImage = "kubernetes/pause"
|
|
|
|
pauseCommand = "/pause"
|
|
|
|
defaultTransport = "docker://"
|
2017-05-12 13:36:15 +00:00
|
|
|
seccompProfilePath = "/etc/crio/seccomp.json"
|
|
|
|
apparmorProfileName = "crio-default"
|
2016-10-18 14:48:33 +00:00
|
|
|
cniConfigDir = "/etc/cni/net.d/"
|
|
|
|
cniBinDir = "/opt/cni/bin/"
|
2017-01-17 00:20:35 +00:00
|
|
|
cgroupManager = "cgroupfs"
|
2016-10-10 09:57:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the entire set of configuration values that can be set for
|
|
|
|
// the server. This is intended to be loaded from a toml-encoded config file.
|
|
|
|
type Config struct {
|
|
|
|
RootConfig
|
|
|
|
APIConfig
|
|
|
|
RuntimeConfig
|
|
|
|
ImageConfig
|
2016-12-17 11:23:07 +00:00
|
|
|
NetworkConfig
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This structure is necessary to fake the TOML tables when parsing,
|
|
|
|
// while also not requiring a bunch of layered structs for no good
|
|
|
|
// reason.
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// RootConfig represents the root of the "crio" TOML config table.
|
2016-10-10 09:57:40 +00:00
|
|
|
type RootConfig struct {
|
2016-10-18 14:48:33 +00:00
|
|
|
// Root is a path to the "root directory" where data not
|
2016-10-10 09:57:40 +00:00
|
|
|
// explicitly handled by other options will be stored.
|
|
|
|
Root string `toml:"root"`
|
|
|
|
|
2016-10-18 14:48:33 +00:00
|
|
|
// RunRoot is a path to the "run directory" where state information not
|
|
|
|
// explicitly handled by other options will be stored.
|
|
|
|
RunRoot string `toml:"runroot"`
|
|
|
|
|
|
|
|
// Storage is the name of the storage driver which handles actually
|
|
|
|
// storing the contents of containers.
|
|
|
|
Storage string `toml:"storage_driver"`
|
2016-10-10 09:57:40 +00:00
|
|
|
|
2016-10-18 14:48:33 +00:00
|
|
|
// StorageOption is a list of storage driver specific options.
|
|
|
|
StorageOptions []string `toml:"storage_option"`
|
2016-10-21 09:58:54 +00:00
|
|
|
|
|
|
|
// LogDir is the default log directory were all logs will go unless kubelet
|
|
|
|
// tells us to put them somewhere else.
|
|
|
|
LogDir string `toml:"log_dir"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// APIConfig represents the "crio.api" TOML config table.
|
2016-10-10 09:57:40 +00:00
|
|
|
type APIConfig struct {
|
|
|
|
// Listen is the path to the AF_LOCAL socket on which cri-o will listen.
|
|
|
|
// This may support proto://addr formats later, but currently this is just
|
|
|
|
// a path.
|
|
|
|
Listen string `toml:"listen"`
|
2017-06-12 22:31:16 +00:00
|
|
|
|
|
|
|
// StreamAddress is the IP address on which the stream server will listen.
|
|
|
|
StreamAddress string `toml:"stream_address"`
|
|
|
|
|
|
|
|
// StreamPort is the port on which the stream server will listen.
|
|
|
|
StreamPort string `toml:"stream_port"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// RuntimeConfig represents the "crio.runtime" TOML config table.
|
2016-10-10 09:57:40 +00:00
|
|
|
type RuntimeConfig struct {
|
2017-05-12 13:36:15 +00:00
|
|
|
// Runtime is a path to the OCI runtime which crio will be using. Currently
|
2016-10-10 09:57:40 +00:00
|
|
|
// the only known working choice is runC, simply because the OCI has not
|
|
|
|
// yet merged a CLI API (so we assume runC's API here).
|
|
|
|
Runtime string `toml:"runtime"`
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// RuntimeHostPrivileged is a path to the OCI runtime which crio will be
|
2017-02-20 23:33:01 +00:00
|
|
|
// using for host privileged operations.
|
|
|
|
RuntimeHostPrivileged string `toml:"runtime_host_privileged"`
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
// Conmon is the path to conmon binary, used for managing the runtime.
|
|
|
|
Conmon string `toml:"conmon"`
|
|
|
|
|
2016-10-17 07:44:27 +00:00
|
|
|
// ConmonEnv is the environment variable list for conmon process.
|
|
|
|
ConmonEnv []string `toml:"conmon_env"`
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
// SELinux determines whether or not SELinux is used for pod separation.
|
|
|
|
SELinux bool `toml:"selinux"`
|
2016-11-23 09:41:48 +00:00
|
|
|
|
|
|
|
// SeccompProfile is the seccomp json profile path which is used as the
|
|
|
|
// default for the runtime.
|
|
|
|
SeccompProfile string `toml:"seccomp_profile"`
|
2016-11-30 08:19:36 +00:00
|
|
|
|
|
|
|
// ApparmorProfile is the apparmor profile name which is used as the
|
|
|
|
// default for the runtime.
|
|
|
|
ApparmorProfile string `toml:"apparmor_profile"`
|
2016-12-19 23:01:27 +00:00
|
|
|
|
|
|
|
// CgroupManager is the manager implementation name which is used to
|
|
|
|
// handle cgroups for containers.
|
|
|
|
CgroupManager string `toml:"cgroup_manager"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// ImageConfig represents the "crio.image" TOML config table.
|
2016-10-10 09:57:40 +00:00
|
|
|
type ImageConfig struct {
|
2016-10-18 14:48:33 +00:00
|
|
|
// DefaultTransport is a value we prefix to image names that fail to
|
|
|
|
// validate source references.
|
|
|
|
DefaultTransport string `toml:"default_transport"`
|
|
|
|
// PauseImage is the name of an image which we use to instantiate infra
|
|
|
|
// containers.
|
|
|
|
PauseImage string `toml:"pause_image"`
|
|
|
|
// PauseCommand is the path of the binary we run in an infra
|
|
|
|
// container that's been instantiated using PauseImage.
|
|
|
|
PauseCommand string `toml:"pause_command"`
|
|
|
|
// SignaturePolicyPath is the name of the file which decides what sort
|
|
|
|
// of policy we use when deciding whether or not to trust an image that
|
|
|
|
// we've pulled. Outside of testing situations, it is strongly advised
|
|
|
|
// that this be left unspecified so that the default system-wide policy
|
|
|
|
// will be used.
|
|
|
|
SignaturePolicyPath string `toml:"signature_policy"`
|
2017-06-08 13:45:34 +00:00
|
|
|
// InsecureRegistries is a list of registries that must be contacted w/o
|
|
|
|
// TLS verification.
|
|
|
|
InsecureRegistries []string `toml:"insecure_registries"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// NetworkConfig represents the "crio.network" TOML config table
|
2016-12-17 11:23:07 +00:00
|
|
|
type NetworkConfig struct {
|
|
|
|
// NetworkDir is where CNI network configuration files are stored.
|
|
|
|
NetworkDir string `toml:"network_dir"`
|
|
|
|
|
|
|
|
// PluginDir is where CNI plugin binaries are stored.
|
|
|
|
PluginDir string `toml:"plugin_dir"`
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
// tomlConfig is another way of looking at a Config, which is
|
|
|
|
// TOML-friendly (it has all of the explicit tables). It's just used for
|
|
|
|
// conversions.
|
|
|
|
type tomlConfig struct {
|
|
|
|
Ocid struct {
|
|
|
|
RootConfig
|
|
|
|
API struct{ APIConfig } `toml:"api"`
|
|
|
|
Runtime struct{ RuntimeConfig } `toml:"runtime"`
|
|
|
|
Image struct{ ImageConfig } `toml:"image"`
|
2016-12-17 11:23:07 +00:00
|
|
|
Network struct{ NetworkConfig } `toml:"network"`
|
2017-05-12 13:36:15 +00:00
|
|
|
} `toml:"crio"`
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tomlConfig) toConfig(c *Config) {
|
|
|
|
c.RootConfig = t.Ocid.RootConfig
|
|
|
|
c.APIConfig = t.Ocid.API.APIConfig
|
|
|
|
c.RuntimeConfig = t.Ocid.Runtime.RuntimeConfig
|
|
|
|
c.ImageConfig = t.Ocid.Image.ImageConfig
|
2016-12-17 11:23:07 +00:00
|
|
|
c.NetworkConfig = t.Ocid.Network.NetworkConfig
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tomlConfig) fromConfig(c *Config) {
|
|
|
|
t.Ocid.RootConfig = c.RootConfig
|
|
|
|
t.Ocid.API.APIConfig = c.APIConfig
|
|
|
|
t.Ocid.Runtime.RuntimeConfig = c.RuntimeConfig
|
|
|
|
t.Ocid.Image.ImageConfig = c.ImageConfig
|
2016-12-17 11:23:07 +00:00
|
|
|
t.Ocid.Network.NetworkConfig = c.NetworkConfig
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FromFile populates the Config from the TOML-encoded file at the given path.
|
|
|
|
// Returns errors encountered when reading or parsing the files, or nil
|
|
|
|
// otherwise.
|
|
|
|
func (c *Config) FromFile(path string) error {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t := new(tomlConfig)
|
|
|
|
t.fromConfig(c)
|
|
|
|
|
|
|
|
_, err = toml.Decode(string(data), t)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.toConfig(c)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToFile outputs the given Config as a TOML-encoded file at the given path.
|
|
|
|
// Returns errors encountered when generating or writing the file, or nil
|
|
|
|
// otherwise.
|
|
|
|
func (c *Config) ToFile(path string) error {
|
|
|
|
var w bytes.Buffer
|
|
|
|
e := toml.NewEncoder(&w)
|
|
|
|
|
|
|
|
t := new(tomlConfig)
|
|
|
|
t.fromConfig(c)
|
|
|
|
|
|
|
|
if err := e.Encode(*t); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.WriteFile(path, w.Bytes(), 0644)
|
|
|
|
}
|
2017-01-17 00:20:35 +00:00
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
// DefaultConfig returns the default configuration for crio.
|
2017-01-17 00:20:35 +00:00
|
|
|
func DefaultConfig() *Config {
|
|
|
|
return &Config{
|
|
|
|
RootConfig: RootConfig{
|
2017-05-12 13:36:15 +00:00
|
|
|
Root: crioRoot,
|
|
|
|
RunRoot: crioRunRoot,
|
|
|
|
LogDir: "/var/log/crio/pods",
|
2017-01-17 00:20:35 +00:00
|
|
|
},
|
|
|
|
APIConfig: APIConfig{
|
2017-06-12 22:31:16 +00:00
|
|
|
Listen: "/var/run/crio.sock",
|
|
|
|
StreamAddress: "",
|
|
|
|
StreamPort: "10010",
|
2017-01-17 00:20:35 +00:00
|
|
|
},
|
|
|
|
RuntimeConfig: RuntimeConfig{
|
2017-02-20 23:33:01 +00:00
|
|
|
Runtime: "/usr/bin/runc",
|
|
|
|
RuntimeHostPrivileged: "",
|
|
|
|
Conmon: conmonPath,
|
2017-01-17 00:20:35 +00:00
|
|
|
ConmonEnv: []string{
|
|
|
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
|
|
},
|
2017-03-22 17:58:35 +00:00
|
|
|
SELinux: selinux.GetEnabled(),
|
2017-01-17 00:20:35 +00:00
|
|
|
SeccompProfile: seccompProfilePath,
|
|
|
|
ApparmorProfile: apparmorProfileName,
|
|
|
|
CgroupManager: cgroupManager,
|
|
|
|
},
|
|
|
|
ImageConfig: ImageConfig{
|
2016-10-18 14:48:33 +00:00
|
|
|
DefaultTransport: defaultTransport,
|
|
|
|
PauseImage: pauseImage,
|
|
|
|
PauseCommand: pauseCommand,
|
|
|
|
SignaturePolicyPath: "",
|
2017-01-17 00:20:35 +00:00
|
|
|
},
|
|
|
|
NetworkConfig: NetworkConfig{
|
|
|
|
NetworkDir: cniConfigDir,
|
|
|
|
PluginDir: cniBinDir,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|