Commit Graph

294 Commits

Author SHA1 Message Date
Brian Goff dc702b6c6b Merge pull request #20727 from mrunalp/no_new_priv
Add support for NoNewPrivileges in docker
2016-03-08 14:26:15 -05:00
Mrunal Patel 74bb1ce9e9 Add support for NoNewPrivileges in docker
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>

Add tests for no-new-privileges

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>

Update documentation for no-new-privileges

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2016-03-07 09:47:02 -08:00
Arnaud Porterie ad2fa39459 Fix race in container creation
Only register a container once it's successfully started. This avoids a
race condition where the daemon is killed while in the process of
calling `libcontainer.Container.Start`, and ends up killing -1.

There is a time window where the container `initProcess` is not set, and
its PID unknown. This commit fixes the race Engine side.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
2016-03-03 20:25:03 -08:00
Alexander Morozov 0a352e1a90 Remove some unused structs and fields
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2016-03-01 09:59:29 -08:00
David Calavera df2b74188e Merge pull request #20699 from calavera/remove_static_error_declarations
Remove static errors from errors package.
2016-02-26 16:30:12 -08:00
Alexander Morozov 51302c29ed Merge pull request #20729 from estesp/pipework
Add synchronization and closure to IO pipes in userns path
2016-02-26 13:33:02 -08:00
David Calavera a793564b25 Remove static errors from errors package.
Moving all strings to the errors package wasn't a good idea after all.

Our custom implementation of Go errors predates everything that's nice
and good about working with errors in Go. Take as an example what we
have to do to get an error message:

```go
func GetErrorMessage(err error) string {
	switch err.(type) {
	case errcode.Error:
		e, _ := err.(errcode.Error)
		return e.Message

	case errcode.ErrorCode:
		ec, _ := err.(errcode.ErrorCode)
		return ec.Message()

	default:
		return err.Error()
	}
}
```

This goes against every good practice for Go development. The language already provides a simple, intuitive and standard way to get error messages, that is calling the `Error()` method from an error. Reinventing the error interface is a mistake.

Our custom implementation also makes very hard to reason about errors, another nice thing about Go. I found several (>10) error declarations that we don't use anywhere. This is a clear sign about how little we know about the errors we return. I also found several error usages where the number of arguments was different than the parameters declared in the error, another clear example of how difficult is to reason about errors.

Moreover, our custom implementation didn't really make easier for people to return custom HTTP status code depending on the errors. Again, it's hard to reason about when to set custom codes and how. Take an example what we have to do to extract the message and status code from an error before returning a response from the API:

```go
	switch err.(type) {
	case errcode.ErrorCode:
		daError, _ := err.(errcode.ErrorCode)
		statusCode = daError.Descriptor().HTTPStatusCode
		errMsg = daError.Message()

	case errcode.Error:
		// For reference, if you're looking for a particular error
		// then you can do something like :
		//   import ( derr "github.com/docker/docker/errors" )
		//   if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... }

		daError, _ := err.(errcode.Error)
		statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode
		errMsg = daError.Message

	default:
		// This part of will be removed once we've
		// converted everything over to use the errcode package

		// FIXME: this is brittle and should not be necessary.
		// If we need to differentiate between different possible error types,
		// we should create appropriate error types with clearly defined meaning
		errStr := strings.ToLower(err.Error())
		for keyword, status := range map[string]int{
			"not found":             http.StatusNotFound,
			"no such":               http.StatusNotFound,
			"bad parameter":         http.StatusBadRequest,
			"conflict":              http.StatusConflict,
			"impossible":            http.StatusNotAcceptable,
			"wrong login/password":  http.StatusUnauthorized,
			"hasn't been activated": http.StatusForbidden,
		} {
			if strings.Contains(errStr, keyword) {
				statusCode = status
				break
			}
		}
	}
```

You can notice two things in that code:

1. We have to explain how errors work, because our implementation goes against how easy to use Go errors are.
2. At no moment we arrived to remove that `switch` statement that was the original reason to use our custom implementation.

This change removes all our status errors from the errors package and puts them back in their specific contexts.
IT puts the messages back with their contexts. That way, we know right away when errors used and how to generate their messages.
It uses custom interfaces to reason about errors. Errors that need to response with a custom status code MUST implementent this simple interface:

```go
type errorWithStatus interface {
	HTTPErrorStatusCode() int
}
```

This interface is very straightforward to implement. It also preserves Go errors real behavior, getting the message is as simple as using the `Error()` method.

I included helper functions to generate errors that use custom status code in `errors/errors.go`.

By doing this, we remove the hard dependency we have eeverywhere to our custom errors package. Yes, you can use it as a helper to generate error, but it's still very easy to generate errors without it.

Please, read this fantastic blog post about errors in Go: http://dave.cheney.net/2014/12/24/inspecting-errors

Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-02-26 15:49:09 -05:00
Phil Estes 995386735c Add synchronization and closure to IO pipes in userns path
The execdriver pipes setup uses OS pipes with fds so that they can be
chown'ed to the remapped root user for proper access. Recent flakiness
in certain short-lived tests (usually via the "exec" path) reveals that
the copy routines are not completing before exit/tear-down.

This fix adds synchronization and proper closure such that these
routines exit successfully.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
2016-02-26 13:47:34 -05:00
Jessica Frazelle ad600239bc
generate seccomp profile convert type
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-02-19 13:32:54 -08:00
Dan Walsh adb2e3fedc /dev/mqueue should never be mounted readonly
If user specifies --read-only flag it should not effect /dev/mqueue.
This is causing SELinux issues in docker-1.10.  --read-only blows up
on SELinux enabled machines.  Mounting /dev/mqueue read/only would also
blow up any tool that was going to use /dev/mqueue.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2016-02-15 14:56:07 -05:00
Dan Walsh ba38d58659 Make mqueue container specific
mqueue can not be mounted on the host os and then shared into the container.
There is only one mqueue per mount namespace, so current code ends up leaking
the /dev/mqueue from the host into ALL containers.  Since SELinux changes the
label of the mqueue, only the last container is able to use the mqueue, all
other containers will get a permission denied.  If you don't have SELinux protections
sharing of the /dev/mqueue allows one container to interact in potentially hostile
ways with other containers.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2016-02-05 16:50:35 +01:00
Fangyuan Gao 5d07d83ee0 remove the unused Info interface in daemon/execdriver/driver.go and related code
Signed-off-by: Fangyuan Gao <21551127@zju.edu.cn>
2016-02-02 09:04:52 +08:00
Joey Geiger 318b4f0b5f Fix typos in create.go
There were a few spelling issues that I noticed when reading about shared mounts.

Signed-off-by: jgeiger <joey.geiger@irco.com>
2016-01-28 14:08:11 -07:00
Arnaud Porterie 3a70ab3a2c Merge pull request #19688 from crosbymichael/tmpfs-tar
Remove tar copy-up for tmpfs mounts
2016-01-26 17:03:07 -08:00
Michael Crosby ae8ec4860e Move tar copy-up for tmpfs mounts
We cannot rely on the tar command for this type of operation because tar
versions, flags, and functionality can very from distro to distro.
Since this is in the container execution path it is not safe to have
this as a dependency from dockers POV where the user cannot change the
fact that docker is adding these pre and post mount commands.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2016-01-26 14:00:39 -08:00
Jessica Frazelle bed0bb7d01
move default seccomp profile into package
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-21 16:55:29 -08:00
Jessica Frazelle 35e50119fc
move default apparmor policy into package
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-21 16:55:27 -08:00
Phil Estes 3233f45609 Merge pull request #19263 from jfrazelle/update-aa-parser
refactor aaparser pkg, add unit tests
2016-01-21 19:40:53 -05:00
Jessica Frazelle 308eff99e8
add send, recv, and x32 so we can install i386 pkgs on amd64
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-18 19:24:01 -08:00
Jessica Frazelle 446f498eba
refactor aaparser pkg, add unit tests
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-13 08:43:12 -08:00
Jessica Frazelle 062d0b3921
read seccomp profile locally then pass to daemon
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-12 13:12:29 -08:00
Jess Frazelle a96a0b3781 Merge pull request #19217 from justincormack/arm_syscalls
Add arm specific syscalls to default seccomp profile
2016-01-11 15:26:09 -08:00
Jess Frazelle 9c9a1d1b4b Merge pull request #19069 from jfrazelle/apparmor-regex-proc
fix proc regex
2016-01-11 13:50:25 -08:00
Sebastiaan van Stijn 967acd56c1 Merge pull request #18512 from euank/18510-fixOomKilled
Set OOMKilled state on any OOM event
2016-01-11 00:09:26 +01:00
Justin Cormack 37d35f3c28 Add arm specific syscalls to default seccomp profile
Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-10 19:55:24 +00:00
Justin Cormack 13a9d4e899 Add i386 specific modify_ldt syscall to default seccomp filter
This syscall is used by Go on i386 binaries, although not by libc.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-10 12:00:11 +00:00
Alexander Morozov c1cd45d547 Choose default-cgroup parent by cgroup driver
It's "/docker" for cgroupfs and "system.slice" for systemd.

Fix #19140

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2016-01-07 08:56:26 -08:00
David Calavera 4ee3048fa8 Merge pull request #19110 from brahmaroutu/update_openc
update runc to the latest code base to fix gccgo builds
2016-01-06 15:09:11 -08:00
Jessica Frazelle 2b4f64e590
fix proc regex
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-06 10:08:35 -08:00
Srini Brahmaroutu 9982631707 update runc to the latest code base to fix gccgo build
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
2016-01-06 00:02:56 +00:00
Justin Cormack 822c4f79ab
Allow the waitpid syscall
This version is sometimes used eg by glibc on x86

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-05 09:29:16 -08:00
Justin Cormack ca3ae72e43
Support compatible architectures with default seccomp rules
In the default seccomp rule, allow use of 32 bit syscalls on
64 bit architectures, so you can run x86 Linux images on x86_64
without disabling seccomp or using a custom rule.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-05 09:28:42 -08:00
Justin Cormack d8e06d54cf
Allow sigreturn syscall
This is used on some 32 bit architectures, eg x86

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-04 16:11:59 -08:00
Justin Cormack 923609179b
Add _llseek syscall
This is the newer verion of lseek on many 32 bit platforms

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-04 11:55:28 -08:00
Justin Cormack d6a9c5abed
Do not allow obsolete syscalls
sysfs and ustat syscalls are marked obsolete.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-04 11:55:28 -08:00
Justin Cormack c1b57fc1c9
Do not allow name_to_handle_at, as we have already blocked open_by_handle_at
Being able to obtain a file handle is no use as we cannot perform
any operation in it, and it may leak kernel state.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2016-01-04 11:55:27 -08:00
Jessica Frazelle a1747b3cc8
add 32bit syscalls to whitelist
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-04 11:55:26 -08:00
Jessica Frazelle 17735c3c98
change seccomp blacklist to whitelist
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2016-01-04 11:55:21 -08:00
Lukas Waslowski 9a03967f0a Fix declarations of of execdriver/native.NewDriver to have the same signature.
This change is done so that driver_unsupported.go and driver_unsupported_nocgo.go
declare the same signature for NewDriver as driver.go.

Fixes #19032

Signed-off-by: Lukas Waslowski <cr7pt0gr4ph7@gmail.com>
2016-01-02 19:55:37 +01:00
Jess Frazelle abc695d9d5 Merge pull request #18974 from jfrazelle/remove-seccomp-from-seccomp-profile
remove seccomp from seccomp profile
2015-12-29 13:15:14 -08:00
Arnaud Porterie a81e438544 Merge pull request #18969 from justincormack/vm86
Block vm86 syscalls in default seccomp profile
2015-12-29 11:57:35 -08:00
Arnaud Porterie 2307f47fdd Merge pull request #18972 from justincormack/bpf
Block bpf syscall from default seccomp profile
2015-12-29 11:57:07 -08:00
Arnaud Porterie e01cab1cc5 Merge pull request #18971 from justincormack/ptrace
Block additional ptrace related syscalls in default seccomp profile
2015-12-29 11:56:51 -08:00
Jessica Frazelle b610fc226a
remove seccomp from seccomp profile
This can be allowed because it should only restrict more per the seccomp docs, and multiple apps use it today.

Signed-off-by: Jessica Frazelle <acidburn@docker.com>
2015-12-29 11:21:33 -08:00
Arnaud Porterie 94e0760868 Merge pull request #18947 from jfrazelle/fix-seccomp-unsupported
fix default profile where unsupported
2015-12-29 10:21:07 -08:00
Arnaud Porterie afdc4747dc Merge pull request #18953 from justincormack/robust_list
Allow use of robust list syscalls in default seccomp policy
2015-12-29 10:19:41 -08:00
Arnaud Porterie a32b06b067 Merge pull request #18956 from justincormack/umount
Block original umount syscall in default seccomp filter
2015-12-29 10:19:04 -08:00
Justin Cormack a0a8ca0ae0 Block additional ptrace related syscalls in default seccomp profile
Block kcmp, procees_vm_readv, process_vm_writev.
All these require CAP_PTRACE, and are only used for ptrace related
actions, so are not useful as we block ptrace.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
2015-12-29 18:17:28 +00:00
Arnaud Porterie ad8bce2ce4 Merge pull request #18959 from justincormack/finit_module
Deny finit_module in default seccomp profile
2015-12-29 10:12:50 -08:00
Arnaud Porterie 8ac3d083a8 Merge pull request #18961 from justincormack/clock_adjtime
Block clock_adjtime in default seccomp config
2015-12-29 10:08:45 -08:00