2014-04-30 19:09:25 -07:00
|
|
|
// +build linux
|
|
|
|
|
2014-04-10 23:03:52 +00:00
|
|
|
package restrict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
2014-04-23 18:12:07 -07:00
|
|
|
|
|
|
|
"github.com/dotcloud/docker/pkg/system"
|
2014-04-10 23:03:52 +00:00
|
|
|
)
|
|
|
|
|
2014-04-30 18:00:42 -07:00
|
|
|
// This has to be called while the container still has CAP_SYS_ADMIN (to be able to perform mounts).
|
|
|
|
// However, afterwards, CAP_SYS_ADMIN should be dropped (otherwise the user will be able to revert those changes).
|
2014-05-02 11:14:24 -07:00
|
|
|
func Restrict(mounts ...string) error {
|
2014-05-01 10:08:18 -07:00
|
|
|
// remount proc and sys as readonly
|
2014-05-02 11:14:24 -07:00
|
|
|
for _, dest := range mounts {
|
2014-05-01 10:08:18 -07:00
|
|
|
if err := system.Mount("", dest, "", syscall.MS_REMOUNT|syscall.MS_RDONLY, ""); err != nil {
|
|
|
|
return fmt.Errorf("unable to remount %s readonly: %s", dest, err)
|
2014-04-10 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-01 13:55:23 -07:00
|
|
|
if err := system.Mount("/dev/null", "/proc/kcore", "", syscall.MS_BIND, ""); err != nil {
|
2014-05-01 10:08:18 -07:00
|
|
|
return fmt.Errorf("unable to bind-mount /dev/null over /proc/kcore")
|
|
|
|
}
|
2014-05-01 19:09:12 -07:00
|
|
|
return nil
|
2014-04-10 23:03:52 +00:00
|
|
|
}
|