Skip to content
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

Merge v1.0.0.rc1 into master #181

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d07fade
Merge pull request #148 from wking/makefile-clean-man-page
Jul 26, 2016
ee4d82c
Merge pull request #149 from wking/generate-output-remove-unuseful-de…
Jul 26, 2016
0d42f0c
Merge pull request #150 from wking/pointer-receivers
Jul 26, 2016
71fd99c
Merge pull request #151 from wking/move-default-cap-to-validate
Jul 26, 2016
1862ec6
Godeps: Roll runtime-spec back to v1.0.0-rc1
wking Jul 26, 2016
6acca9e
Merge pull request #153 from wking/v1.0.0.rc1-godep
Jul 26, 2016
4aa0071
generate: Remove superfluous err check from Save
wking Jul 28, 2016
bbe46e2
Check pointer fields of g.spec
Jul 24, 2016
5295830
Check CAP_LAST_CAP while setting privileged
Jul 21, 2016
3968a06
generate: fix tmpfs adding based on manpage
Jul 27, 2016
30e2ea2
Merge pull request #163 from wking/check-pointer-fields
Jul 28, 2016
5067a2e
Merge pull request #165 from wking/generate-fix-tmpfs-adding
Jul 28, 2016
28ddd80
Merge pull request #164 from wking/privileged-cap-list
Jul 28, 2016
928bf89
generate: remove unnecessary spec initialization
Jul 28, 2016
e5bcb77
generate: fix capability.List() for cap_last_cap not exist
Jul 27, 2016
11f1b12
Add Travis CI badge to README
caniszczyk Jul 28, 2016
3a58f65
Merge pull request #171 from wking/generate-fix-cap_last_cap
Jul 29, 2016
8f9f38f
Merge pull request #172 from wking/generate-remove-unnecessary-init-spec
Jul 29, 2016
c186f4f
Merge pull request #173 from wking/add-travis-ci-badge
Jul 29, 2016
f72c7f5
Merge pull request #161 from wking/superfluous-err-check
Aug 3, 2016
b45bebd
Merge commit '6acca9e'
wking Aug 3, 2016
eac0762
Merge commit '30e2ea2'
wking Aug 3, 2016
f43eacf
Modify generate API
Jul 28, 2016
fe62695
remove unnecessary return error value
Jul 29, 2016
36ccd5c
change param type of AddProcessAdditionalGid
Jul 29, 2016
ed659ab
generate: optimize namespace setup log and fix manpage
Jul 28, 2016
ff90d01
update urfave/cli package to v1.18.0
Aug 2, 2016
21ce013
Merge pull request #179 from wking/urfave-cli-v1.18.0
Aug 3, 2016
217ce82
Merge pull request #177 from wking/generate-api-cleanup
Aug 3, 2016
207e26c
Merge pull request #178 from wking/generate-namespace-optimize-fix-ma…
Aug 3, 2016
119586e
completions: update based on generate help message
Jul 28, 2016
2a8f316
Merge pull request #182 from wking/completion-update-for-generate
Aug 3, 2016
56a65bd
generate: fix mount-cgroups bug
Jul 27, 2016
52c9e15
Merge pull request #183 from wking/generate-fix-mount-cgroup-bug
Aug 4, 2016
de97cc8
support setting oom_score_adj
Aug 2, 2016
ea1d5dd
Merge pull request #185 from wking/set-oom_score_adj
Aug 5, 2016
a336a00
add label manpage and fix help
Aug 15, 2016
f4bba5a
validation: add linux resource check
Aug 17, 2016
8eab016
Merge pull request #198 from wking/add-linux-resources-validation
Aug 22, 2016
d020606
add namespace check for uid/gid mappings
Aug 23, 2016
3309d87
Merge pull request #201 from wking/add-namespace-check-for-mappings
Aug 26, 2016
b6d953a
man/ocitools.1: Replace "**...(1)**" with "**...**(1)"
wking Aug 31, 2016
3091c7e
Merge pull request #190 from wking/man-add-label-and-fix-help
Sep 1, 2016
975c97f
Merge pull request #202 from wking/no-bold-man-section
Sep 1, 2016
4fcbcb4
Merge branch 'v1.0.0.rc1'
wking Sep 1, 2016
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
7 changes: 6 additions & 1 deletion cmd/ocitools/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var generateFlags = []cli.Flag{
cli.StringFlag{Name: "mount-label", Usage: "selinux mount context label"},
cli.StringSliceFlag{Name: "tmpfs", Usage: "mount tmpfs"},
cli.StringSliceFlag{Name: "args", Usage: "command to run in the container"},
cli.StringSliceFlag{Name: "env", Usage: "add environment variable"},
cli.StringSliceFlag{Name: "env", Usage: "add environment variable e.g. key=value"},
cli.StringFlag{Name: "cgroups-path", Usage: "specify the path to the cgroups"},
cli.StringFlag{Name: "mount-cgroups", Value: "no", Usage: "mount cgroups (rw,ro,no)"},
cli.StringSliceFlag{Name: "bind", Usage: "bind mount directories src:dest:(rw,ro)"},
Expand All @@ -58,6 +58,7 @@ var generateFlags = []cli.Flag{
cli.StringSliceFlag{Name: "seccomp-errno", Usage: "specifies syscalls to be added to list that returns an error"},
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"},
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
}

var generateCommand = cli.Command{
Expand Down Expand Up @@ -319,6 +320,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
g.AddLinuxGIDMapping(hid, cid, size)
}

if context.IsSet("oom-score-adj") {
g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj"))
}

var sd string
var sa, ss []string

Expand Down
38 changes: 31 additions & 7 deletions cmd/ocitools/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,7 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
ipcExists := false
mountExists := false
netExists := false

if len(spec.Linux.UIDMappings) > 5 {
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
}
if len(spec.Linux.GIDMappings) > 5 {
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
}
userExists := false

for index := 0; index < len(spec.Linux.Namespaces); index++ {
if !namespaceValid(spec.Linux.Namespaces[index]) {
Expand All @@ -336,10 +330,20 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
netExists = true
} else if spec.Linux.Namespaces[index].Type == rspec.MountNamespace {
mountExists = true
} else if spec.Linux.Namespaces[index].Type == rspec.UserNamespace {
userExists = true
}
}
}

if (len(spec.Linux.UIDMappings) > 0 || len(spec.Linux.GIDMappings) > 0) && !userExists {
msgs = append(msgs, "UID/GID mappings requires a new User namespace to be specified as well")
} else if len(spec.Linux.UIDMappings) > 5 {
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
} else if len(spec.Linux.GIDMappings) > 5 {
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
}

for k := range spec.Linux.Sysctl {
if strings.HasPrefix(k, "net.") && !netExists {
msgs = append(msgs, fmt.Sprintf("Sysctl %v requires a new Network namespace to be specified as well", k))
Expand All @@ -361,6 +365,11 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
}
}

if spec.Linux.Resources != nil {
ms := checkLinuxResources(*spec.Linux.Resources, hostCheck)
msgs = append(msgs, ms...)
}

if spec.Linux.Seccomp != nil {
ms := checkSeccomp(*spec.Linux.Seccomp)
msgs = append(msgs, ms...)
Expand All @@ -381,6 +390,21 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
return
}

func checkLinuxResources(r rspec.Resources, hostCheck bool) (msgs []string) {
logrus.Debugf("check linux resources")

if r.Memory != nil {
if r.Memory.Limit != nil && r.Memory.Swap != nil && uint64(*r.Memory.Limit) > uint64(*r.Memory.Swap) {
msgs = append(msgs, fmt.Sprintf("Minimum memoryswap should be larger than memory limit"))
}
if r.Memory.Limit != nil && r.Memory.Reservation != nil && uint64(*r.Memory.Reservation) > uint64(*r.Memory.Limit) {
msgs = append(msgs, fmt.Sprintf("Minimum memory limit should be larger than memory reservation"))
}
}

return
}

func checkSeccomp(s rspec.Seccomp) (msgs []string) {
logrus.Debugf("check seccomp")

Expand Down
16 changes: 9 additions & 7 deletions completions/bash/ocitools
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ _ocitools_generate() {
--cap-add
--cap-drop
--cgroup
--cgroup-path
--cwd
--env
--gid
Expand All @@ -283,25 +284,31 @@ _ocitools_generate() {
--hostname
--help
--ipc
--label
--mount
--mount-cgroups
--mount-label
--network
--os
--output
--pid
--poststart
--poststop
--prestart
--root-propagation
--rootfs
--seccomp-default
--seccomp-allow
--seccomp-arch
--seccomp-default
--seccomp-errno
--seccomp-syscalls
--selinux-label
--mount-label
--sysctl
--tmplate
--tmpfs
--uid
--uidmappings
--user
--uts
"

Expand Down Expand Up @@ -330,11 +337,6 @@ _ocitools_generate() {
return
;;

--seccomp-default)
__ocitools_complete_seccomp_actions
return
;;

--root-propagation)
__ocitools_complete_propagations
return
Expand Down
13 changes: 8 additions & 5 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ func (g *Generator) Save(w io.Writer) error {
}

_, err = w.Write(data)
if err != nil {
return err
}

return nil
return err
}

// SaveToFile writes the spec into a file.
Expand Down Expand Up @@ -362,6 +358,12 @@ func (g *Generator) SetLinuxMountLabel(label string) {
g.spec.Linux.MountLabel = label
}

// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj.
func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) {
g.initSpecLinuxResources()
g.spec.Linux.Resources.OOMScoreAdj = &adj
}

// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
func (g *Generator) SetLinuxResourcesCPUShares(shares uint64) {
g.initSpecLinuxResourcesCPU()
Expand Down Expand Up @@ -855,6 +857,7 @@ func (g *Generator) AddCgroupsMount(mountCgroupOption string) error {
switch mountCgroupOption {
case "ro":
case "rw":
break
case "no":
return nil
default:
Expand Down
14 changes: 10 additions & 4 deletions man/ocitools-generate.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ read the configuration from `config.json`.
Current working directory for the process

**--env**=[]
Set environment variables
This option allows you to specify arbitrary
environment variables that are available for the process that will be launched
inside of the container.
Set environment variables e.g. key=value.
This option allows you to specify arbitrary environment variables
that are available for the process that will be launched inside of
the container.

**--gid**=GID
Gid for the process inside of container
Expand All @@ -84,6 +84,9 @@ inside of the container.
The special *PATH* `host` removes any existing IPC namespace from the
configuration.

**--label**=[]
Add annotations to the configuration e.g. key=value.

**--mount**=*PATH*
Use a mount namespace where *PATH* is an existing mount namespace file
to join. The special *PATH* empty-string creates a new namespace.
Expand Down Expand Up @@ -117,6 +120,9 @@ inside of the container.
using tools like setuid apps. It is a good idea to run unprivileged
containers with this flag.

**--oom-score-adj**=adj
Specifies oom_score_adj for the container.

**--output**=PATH
Instead of writing the configuration JSON to stdout, write it to a
file at *PATH* (overwriting the existing content if a file already
Expand Down
4 changes: 2 additions & 2 deletions man/ocitools.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ ocitools is a collection of tools for working with the [OCI runtime specificatio
# COMMANDS
**validate**
Validating OCI bundle
See **ocitools-validate(1)** for full documentation on the **validate** command.
See **ocitools-validate**(1) for full documentation on the **validate** command.

**generate**
Generating OCI runtime spec configuration files
See **ocitools-generate(1)** for full documentation on the **generate** command.
See **ocitools-generate**(1) for full documentation on the **generate** command.

# SEE ALSO
**ocitools-validate**(1), **ocitools-generate**(1)
Expand Down