mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
Merge pull request #97 from justincormack/ambient
Add support for ambient capabilities
This commit is contained in:
commit
5f49f6695a
@ -414,6 +414,8 @@ func filesystem(m Moby, tw *tar.Writer) error {
|
|||||||
Name: root,
|
Name: root,
|
||||||
Typeflag: tar.TypeDir,
|
Typeflag: tar.TypeDir,
|
||||||
Mode: dirMode,
|
Mode: dirMode,
|
||||||
|
Uid: int(f.UID),
|
||||||
|
Gid: int(f.GID),
|
||||||
}
|
}
|
||||||
err := tw.WriteHeader(hdr)
|
err := tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -423,36 +425,30 @@ func filesystem(m Moby, tw *tar.Writer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
addedFiles[f.Path] = true
|
addedFiles[f.Path] = true
|
||||||
|
hdr := &tar.Header{
|
||||||
|
Name: f.Path,
|
||||||
|
Mode: mode,
|
||||||
|
Uid: int(f.UID),
|
||||||
|
Gid: int(f.GID),
|
||||||
|
}
|
||||||
if f.Directory {
|
if f.Directory {
|
||||||
if f.Contents != nil {
|
if f.Contents != nil {
|
||||||
return errors.New("Directory with contents not allowed")
|
return errors.New("Directory with contents not allowed")
|
||||||
}
|
}
|
||||||
hdr := &tar.Header{
|
hdr.Typeflag = tar.TypeDir
|
||||||
Name: f.Path,
|
|
||||||
Typeflag: tar.TypeDir,
|
|
||||||
Mode: mode,
|
|
||||||
}
|
|
||||||
err := tw.WriteHeader(hdr)
|
err := tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if f.Symlink != "" {
|
} else if f.Symlink != "" {
|
||||||
hdr := &tar.Header{
|
hdr.Typeflag = tar.TypeSymlink
|
||||||
Name: f.Path,
|
hdr.Linkname = f.Symlink
|
||||||
Typeflag: tar.TypeSymlink,
|
|
||||||
Mode: mode,
|
|
||||||
Linkname: f.Symlink,
|
|
||||||
}
|
|
||||||
err := tw.WriteHeader(hdr)
|
err := tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hdr := &tar.Header{
|
hdr.Size = int64(len(contents))
|
||||||
Name: f.Path,
|
|
||||||
Mode: mode,
|
|
||||||
Size: int64(len(contents)),
|
|
||||||
}
|
|
||||||
err := tw.WriteHeader(hdr)
|
err := tw.WriteHeader(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -27,15 +27,7 @@ type Moby struct {
|
|||||||
Onboot []Image
|
Onboot []Image
|
||||||
Services []Image
|
Services []Image
|
||||||
Trust TrustConfig
|
Trust TrustConfig
|
||||||
Files []struct {
|
Files []File
|
||||||
Path string
|
|
||||||
Directory bool
|
|
||||||
Symlink string
|
|
||||||
Contents *string
|
|
||||||
Source string
|
|
||||||
Optional bool
|
|
||||||
Mode string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrustConfig is the type of a content trust config
|
// TrustConfig is the type of a content trust config
|
||||||
@ -44,11 +36,25 @@ type TrustConfig struct {
|
|||||||
Org []string
|
Org []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File is the type of a file specification
|
||||||
|
type File struct {
|
||||||
|
Path string
|
||||||
|
Directory bool
|
||||||
|
Symlink string
|
||||||
|
Contents *string
|
||||||
|
Source string
|
||||||
|
Optional bool
|
||||||
|
Mode string
|
||||||
|
UID uint32 `yaml:"uid" json:"uid"`
|
||||||
|
GID uint32 `yaml:"gid" json:"gid"`
|
||||||
|
}
|
||||||
|
|
||||||
// Image is the type of an image config
|
// Image is the type of an image config
|
||||||
type Image struct {
|
type Image struct {
|
||||||
Name string `yaml:"name" json:"name"`
|
Name string `yaml:"name" json:"name"`
|
||||||
Image string `yaml:"image" json:"image"`
|
Image string `yaml:"image" json:"image"`
|
||||||
Capabilities *[]string `yaml:"capabilities" json:"capabilities,omitempty"`
|
Capabilities *[]string `yaml:"capabilities" json:"capabilities,omitempty"`
|
||||||
|
Ambient *[]string `yaml:"ambient" json:"ambient,omitempty"`
|
||||||
Mounts *[]specs.Mount `yaml:"mounts" json:"mounts,omitempty"`
|
Mounts *[]specs.Mount `yaml:"mounts" json:"mounts,omitempty"`
|
||||||
Binds *[]string `yaml:"binds" json:"binds,omitempty"`
|
Binds *[]string `yaml:"binds" json:"binds,omitempty"`
|
||||||
Tmpfs *[]string `yaml:"tmpfs" json:"tmpfs,omitempty"`
|
Tmpfs *[]string `yaml:"tmpfs" json:"tmpfs,omitempty"`
|
||||||
@ -619,25 +625,13 @@ func ConfigInspectToOCI(yaml Image, inspect types.ImageInspect) (specs.Spec, err
|
|||||||
|
|
||||||
// TODO user, cgroup namespaces
|
// TODO user, cgroup namespaces
|
||||||
|
|
||||||
caps := assignStrings(label.Capabilities, yaml.Capabilities)
|
// Capabilities
|
||||||
for _, capability := range caps {
|
capCheck := map[string]bool{}
|
||||||
if capability == "none" || capability == "all" {
|
for _, capability := range allCaps {
|
||||||
continue
|
capCheck[capability] = true
|
||||||
}
|
|
||||||
|
|
||||||
found := false
|
|
||||||
for _, ac := range allCaps {
|
|
||||||
if ac == capability {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
return oci, fmt.Errorf("unknown capability: %s", capability)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
boundingSet := map[string]bool{}
|
||||||
|
caps := assignStrings(label.Capabilities, yaml.Capabilities)
|
||||||
if len(caps) == 1 {
|
if len(caps) == 1 {
|
||||||
switch cap := strings.ToLower(caps[0]); cap {
|
switch cap := strings.ToLower(caps[0]); cap {
|
||||||
case "none":
|
case "none":
|
||||||
@ -646,6 +640,31 @@ func ConfigInspectToOCI(yaml Image, inspect types.ImageInspect) (specs.Spec, err
|
|||||||
caps = allCaps[:]
|
caps = allCaps[:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, capability := range caps {
|
||||||
|
if !capCheck[capability] {
|
||||||
|
return oci, fmt.Errorf("unknown capability: %s", capability)
|
||||||
|
}
|
||||||
|
boundingSet[capability] = true
|
||||||
|
}
|
||||||
|
ambient := assignStrings(label.Ambient, yaml.Ambient)
|
||||||
|
if len(ambient) == 1 {
|
||||||
|
switch cap := strings.ToLower(ambient[0]); cap {
|
||||||
|
case "none":
|
||||||
|
ambient = []string{}
|
||||||
|
case "all":
|
||||||
|
ambient = allCaps[:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, capability := range ambient {
|
||||||
|
if !capCheck[capability] {
|
||||||
|
return oci, fmt.Errorf("unknown capability: %s", capability)
|
||||||
|
}
|
||||||
|
boundingSet[capability] = true
|
||||||
|
}
|
||||||
|
bounding := []string{}
|
||||||
|
for capability := range boundingSet {
|
||||||
|
bounding = append(bounding, capability)
|
||||||
|
}
|
||||||
|
|
||||||
rlimitsString := assignStrings(label.Rlimits, yaml.Rlimits)
|
rlimitsString := assignStrings(label.Rlimits, yaml.Rlimits)
|
||||||
rlimits := []specs.LinuxRlimit{}
|
rlimits := []specs.LinuxRlimit{}
|
||||||
@ -727,11 +746,11 @@ func ConfigInspectToOCI(yaml Image, inspect types.ImageInspect) (specs.Spec, err
|
|||||||
Env: env,
|
Env: env,
|
||||||
Cwd: cwd,
|
Cwd: cwd,
|
||||||
Capabilities: &specs.LinuxCapabilities{
|
Capabilities: &specs.LinuxCapabilities{
|
||||||
Bounding: caps,
|
Bounding: bounding,
|
||||||
Effective: caps,
|
Effective: caps,
|
||||||
Inheritable: caps,
|
Inheritable: bounding,
|
||||||
Permitted: caps,
|
Permitted: bounding,
|
||||||
Ambient: []string{},
|
Ambient: ambient,
|
||||||
},
|
},
|
||||||
Rlimits: rlimits,
|
Rlimits: rlimits,
|
||||||
NoNewPrivileges: assignBool(label.NoNewPrivileges, yaml.NoNewPrivileges),
|
NoNewPrivileges: assignBool(label.NoNewPrivileges, yaml.NoNewPrivileges),
|
||||||
|
@ -24,7 +24,9 @@ var schema = string(`
|
|||||||
"contents": {"type": "string"},
|
"contents": {"type": "string"},
|
||||||
"source": {"type": "string"},
|
"source": {"type": "string"},
|
||||||
"optional": {"type": "boolean"},
|
"optional": {"type": "boolean"},
|
||||||
"mode": {"type": "string"}
|
"mode": {"type": "string"},
|
||||||
|
"uid": {"type": "integer"},
|
||||||
|
"gid": {"type": "integer"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
@ -65,6 +67,7 @@ var schema = string(`
|
|||||||
"name": {"type": "string"},
|
"name": {"type": "string"},
|
||||||
"image": {"type": "string"},
|
"image": {"type": "string"},
|
||||||
"capabilities": { "$ref": "#/definitions/strings" },
|
"capabilities": { "$ref": "#/definitions/strings" },
|
||||||
|
"ambient": { "$ref": "#/definitions/strings" },
|
||||||
"mounts": { "$ref": "#/definitions/mounts" },
|
"mounts": { "$ref": "#/definitions/mounts" },
|
||||||
"binds": { "$ref": "#/definitions/strings" },
|
"binds": { "$ref": "#/definitions/strings" },
|
||||||
"tmpfs": { "$ref": "#/definitions/strings" },
|
"tmpfs": { "$ref": "#/definitions/strings" },
|
||||||
|
Loading…
Reference in New Issue
Block a user